An unreachable malformed if statement is a syntax error in a Schema, but not in Common Lisp

I am trying to better understand how S-expressions are evaluated in different foxes, and would like them to handle interesting poorly formed expressions. I understand that Common Lisp and Scheme are completely different languages, but is there any difference in their semantics that explains the difference in behavior. For example, Lisp -1s and Lisp -2s have observed differences in their behavior, as well as hygienic and unhygienic macro systems.

I have a program that contains an unreachable poorly formed if statement in Scheme and Common Lisp.

;; foo.scm
(if #t 1 (if))

(display "12")

And the general version of Lisp

;; foo.lisp
(if t 1 (if))

(display "12")

chickenand guilegenerate a syntax error.

Chick:

% chicken foo.scm

Syntax error: (foo.scm:1) in `if' - pair expected

    (if)

    Expansion history:

    <syntax>      (##core#begin (if #t 1 (if)))
    <syntax>      (if #t 1 (if))
    <syntax>      (##core#if #t 1 (if))
    <syntax>      (if)  <--

Insidiousness:

% guile foo.scm
...
.../foo.scm:1:9: source expression failed to match any pattern in form (if)

sbcland clispboth type 12 and give no warning.

SBCL:

% sbcl --load foo.lisp
This is SBCL 1.3.11, an implementation of ANSI Common Lisp.
...
12
0]^D

CLISP

% clisp foo.lisp

"12"
+4
2

Common Lisp:

Common Lisp , Lisp . Common Lisp : . , .

  • : Lisp. , JVM. , / . , .

  • : Lisp C, . , ( , . ), .

  • Toplevel: , .

GNU CLISP ,

GNU CLISP:

LOAD :

[1]> (load "test.lisp")
;; Loading file test.lisp ...
;; Loaded file test.lisp
T

, . else , .

CLISP :

[2]> (compile-file "test.lisp")
;; Compiling file /tmp/test.lisp ...
** - Continuable Error
in #:|1 1 (IF T 1 ...)-1| in line 1 : Form too short, too few arguments: (IF)
If you continue (by typing 'continue'): Ignore the error and proceed
The following restarts are also available:
ABORT          :R1      Abort main loop

, CLISP .

SBCL ,

SBCL , . . .

IF SBCL, :

CL-USER> (if t 1 (if))
1

, , :

CL-USER> (defun foo () (if t 1 (if)))
; in: DEFUN FOO
;     (IF)
; 
; caught ERROR:
;   error while parsing arguments to special operator IF:
;     too few elements in
;       ()
;     to satisfy lambda list
;       (SB-C::TEST SB-C::THEN &OPTIONAL SB-C::ELSE):
;     between 2 and 3 expected, but got 0
; 
; compilation unit finished
;   caught 1 ERROR condition
WARNING: redefining COMMON-LISP-USER::FOO in DEFUN
FOO

SBCL, :

CL-USER> (setf *evaluator-mode* :interpret)
:INTERPRET
CL-USER> (defun foo () (if t 1 (if)))
WARNING: redefining COMMON-LISP-USER::FOO in DEFUN
FOO

, .

Lisp / .

+8

, CL . , R5RS , .

R5RS , if , , , :

, " ", , . , , . , "".

, R5RS, "banana" , Guile Chickens (if #t 1 (if)).

R6RS, , , , . , if 3 , , , .

+3

Source: https://habr.com/ru/post/1659788/


All Articles