3 ms·
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 brack
by lispm 8y ago
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 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>
- skybrian 8y agoOkay, 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.
- lispm 8y ago> 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.