Comparison of a counter in racket-scheme and sbcl-lisp
Comparison of a counter in racket-scheme and sbcl-lisp
A counter in racket-scheme:
#lang typed/racket
(define my-counter!
(let ([t 0])
(lambda ()
(set! t (+ 1 t))
t);lambda
);let
);define
(print (my-counter!))
(print (my-counter!))
A counter in sbcl-lisp:
load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3)))
(let ((c 0))
(defun my-counter! ()
(lambda ()
(setf c (+ 1 c))
c); lambda
) ;defun
) ;let
(defun main ()
(print (funcall (my-counter!)))
(print (funcall (my-counter!)))
)
(sb-ext:save-lisp-and-die "test.exe" :toplevel #'main :executable t)
Could someone elaborate why i need "funcall" in lisp and not in scheme ? And why the different placing of let ?
You're viewing a single thread.
All Comments
8 comments
In Common Lisp, as opposed to Scheme, it is not possible that the car of the compound form to be evaluated is an arbitrary form. If it is not a symbol, it must be a lambda expression, which looks like (lambda lambda-list form*).
1 0 Reply
8 comments
Scroll to top