News for hackers. Stuff that matters.
Re:Lisp Macros, Delayed Evaluation and the Evolution of Smal... by i_feel_great on Wednesday March 20, 2019 @12:20AM (#19438956)
Smalltalk blocks are anonymous functions sure, but the evaluation is delayed - you have to pass the message #value (and its variants) to it. This not the case in Scheme and maybe Lisps, where evaluation is eager.

Passing Smalltalk blocks and Scheme/Lisp lambdas into functions have different behaviours.

Re:Lisp Macros, Delayed Evaluation and the Evolution of Smal... by lispm on Wednesday March 20, 2019 @12:29AM (#19439000)
That doesn't matter. One can write IF as a function taking functions as THEN and ELSE forms:

    CL-USER 9 > (defun my-if (test then else)
                  (if test (funcall then) (funcall else)))
    MY-IF

    CL-USER 10 > (let ((a 10))
                  (my-if (> a 5)
                         (lambda ()
                           (print 'hello))
                         (lambda ()
                           (print 'world)))
                  'done)

    HELLO 
    DONE
The lambdas you see above serve the same purpose as blocks in Smalltalk.
Re:Lisp Macros, Delayed Evaluation and the Evolution of Smal... by skybrian on Wednesday March 20, 2019 @01:05AM (#19439168)
It works, but the syntax isn't nice enough to use as-is, so in practice you need a macro.

The innovation here is using better syntax for anonymous functions to make such things practical in languages without macros.

Re:Lisp Macros, Delayed Evaluation and the Evolution of Smal... by lispm on Wednesday March 20, 2019 @01:22AM (#19439251)
If you think brackets are the core innovation of Smalltalk to make lambdas practical, then Lisp has no problem providing it, too:

    CL-USER 19 > (defun bracket-reader (stream char)
                   (declare (ignore char))
                   `(lambda () ,@(read-delimited-list #\] stream t)))
    BRACKET-READER

    CL-USER 20 > (set-macro-character #\[ #'bracket-reader)
    T

    CL-USER 21 > (let ((a 10))
                  (my-if (> a 5)
                        [(print 'hello)]
                        [(print 'world)])
                  'done)

    HELLO 
    DONE
With a bit more effort, we could also parse a parameter list.

But Lisp does not go the route of making IF a function, because it typically provides three different types of language expressions and IF then is a special operator:

1) function calls

2) macro forms

3) a small set of special operators, which are implemented as built-in functionality. One of them is a core conditional operator. More complex conditional operators then are implemented as macros, which expand eventually into the core conditional operator. The interpreter and compiler will have to specially recognize and implement these special operators.

See IF: http://clhs.lisp.se/Body/s_if.htm

The usual Lisp view is that

  [(print 'hello)]
is no useful improvement over

  (lambda () (print 'hello))
Some disagree, but most of the time the pattern

  (<operator> <expr0> ... <exprn>)
is preferred in Lisp over

  <fancy-character> <expr0> ... <exprn> <another-fancy-character>
Re:Lisp Macros, Delayed Evaluation and the Evolution of Smal... by skybrian on Wednesday March 20, 2019 @02:17AM (#19439508)
Okay, but if you have macros, you might as well use them. The idea is more about exploring what can be done when designing a less powerful language, without macros.
Re:Lisp Macros, Delayed Evaluation and the Evolution of Smal... by lispm on Wednesday March 20, 2019 @02:43AM (#19439617)
> The idea is more about exploring what can be done when designing a less powerful language, without macros.

Lot's of things. But the language won't be able to easily compute code at compile time, which a main purpose of macros. Lisp has a simple data format for source code and thus code transformations are relatively simple to do and even integrated into the language.