this post was submitted on 10 Oct 2023
0 points (50.0% liked)

Lisp

53 readers
3 users here now

founded 1 year ago
MODERATORS
 

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 are viewing a single comment's thread
view the rest of the comments
[โ€“] soegaard@alien.top 1 points 1 year ago (1 children)

Are you on old reddit by chance?

For the youngsters: The tripple ` notation doesn't work on old reddit. Indent each line of code with four spaces.

https://old.reddit.com/r/scheme/comments/16y3avr/comparison_of_a_counter_in_racketscheme_and/