I want to implement lazy thread in SICP 3.5.1 section
First, I defined these two functions
(defmacro delay (form) `(lambda () ,form)) (defun force (form) (when form (funcall form)))
When we called:
(force (delay '(+ 1 2))) ;;=> (+ 1 2) (force (delay (+ 1 2))) ;;=> 3
It happened. Then I continue to define the "cons-cons", but this time it appears in two ways:
(defmacro stream-cons (ab) `(cons ,a ,(delay b))) (defmacro stream-cons (ab) `(cons ,a (delay ,b)))
I do not think they are different, but I am wrong! The first edition, which is the wrong edition when called:
(force (cdr (stream-cons 'a (progn (print "hello") 2)))) ;;=> (PROGN (PRINT "hello") 2) (macroexpand '(stream-cons 'a (progn (print "hello") 2))) ;;=> (CONS 'A
and the second edition, which is correct when called:
(force (cdr (stream-cons 'a (progn (print "hello") 2)))) ;; ;; "hello" ;; => 2 (macroexpand '(stream-cons 'a (progn (print "hello") 2))) ;;=> (CONS 'A (DELAY (PROGN (PRINT "hello") 2)))
Now I am very confused. Who can kindly help me clarify the different of the two? Thank you very much!
My environment: Windows 32bits, SBCL 1.1.4