4 ms·
Racket also optionally supports a square bracket syntax for cons clauses. For example, in traditional Scheme one would write: ; this is in R5RS Scheme (de
by linguae 5y ago
Racket also optionally supports a square bracket syntax for cons clauses.
For example, in traditional Scheme one would write:
; this is in R5RS Scheme
(define (length elems)
(cond ((null? elems) 0)
(else (+ 1 (length (cdr elems))))))
But in Racket one would write:
; this is in Racket
(define (length elems)
(cond [(empty? elems) 0]
[else (+ 1 (length (rest elems)))]))
It is also used in let/let*/letrec bindings in Racket; see https://docs.racket-lang.org/guide/syntax-overview.html#%28part._.Conditionals_with_if__and__or__and_cond%29 https://docs.racket-lang.org/guide/syntax-overview.html#%28p....
I don't know the origins of when brackets started appearing in Lisps. I don't remember seeing brackets in the LISP 1.5 Programmers Manual when using S-expressions (though brackets are a core part of M-expression syntax, which LISP 1.5 still supported), and I haven't encountered brackets in Common Lisp.
- rawoke083600 5y agoInteresting ! Thank you for the examples. Yes Racket is also on my someday-soon-list !
- tralarpa 5y ago> It is also used in let/let*/letrec bindings in Racket I suppose this is just a personal choice of the author of the manual, right? Please correct me if I am wrong but I thought Racket doesn't care whether you use brackets, parentheses, or even curly brackets.