S-expression: atom or parenthesized list. Whitespace is collapsed.
Program result = read → expand → evaluate → print.
REPL
Atoms (plus the usual string & math functions)
42+3i 1/3 0.333
#b101010 #x2a #o52
"hello world"
#\h
#true
#t
#false ; yes, we have no falsiness
#f
'sym
(void)
Datums: quote ' quasiquote unquote unquote-splicing `(short ,hand ,@notation) '(dotted . pair)
(list 1 2 3)
'[4 5 6]
`{2 3 ,(+ 4 5)}
`{,(list 7 8 9)}
`{,@(list a b c)}
'(d . (e . (f)))
(cons 'x (cons 'y (cons 'z null)))
(lambda (x) (abs x))
(λ (x) (abs x))
((λ (x) (abs x)) -42)
(abs -42)
(apply (λ (x) (abs x)) (list -42))
(apply abs (list -42))
(map abs '(-1 2 3 -4))
(filter abs '(-1 2 3 -4))
(filter even? (map abs '(-1 2 3 -4)))
(6 . * . 7)
Variable = identifier + binding
Binding forms: define define-values let let* set!
(define val 42)
(define (f x) (+ x x))
(define g (λ (x) (+ x x)))
(let ([f (λ (x) (* x x))]
[res (f val)])
res)
(let* ([f (λ (x) (* x x))]
[res (f val)])
res)
(if (even? 42) #true #false)
(when (even? 42) #true)
(unless (even? 42) 'destroy-galaxy)
(cond
[(even? 42) #true]
[else #false])
(let ([val 42])
(case val
[(42) #true]
[else #false]))
(match 42
[(? even?) #true]
[_ #false])
(for/list ([i (in-range 1 5)]
[j (in-naturals 6)])
(list i j))
(for/fold ([sum 0])
([i (in-range 1 5)]
[j (in-naturals 6)])
(+ sum i j))
(for/sum ([i (in-range 1 5)]
[j (in-naturals 6)])
(+ i j))
(apply +
(apply append
(for/list ([i (in-range 1 5)]
[j (in-naturals 6)])
(list i j))))
Import & export: require provide rename-out
(module inner br
(provide foo (rename-out [barbara bar]))
(define foo 'inner-foo)
(define barbara 'inner-bar))
(require 'inner)
(define foo 'outer-foo)
foo
bar
Syntax objects: syntax quasisyntax unsyntax unsyntax-splicing #`(short #,hand #,@notation) syntax/loc
Syntax patterns: ...
(define-macro (dbl ARG)
#'(list ARG ARG))
(define-macro-cases foo
[(_ 42) #'"kaboom!"]
[(_ ARG) #'(list ARG ARG)])
(define-macro (rev ARG0 "foo" ARG ...)
#'(append (reverse (list 'ARG ...)) (list 'ARG0)))
(define-macro (tell ARG ...)
#'(for ([name (in-list (list 'ARG ...))])
(displayln (format "~a = ~a" name ARG)) ...))
Interposition points: #%app #%datum #%top-interaction #%module-begin
Comments: ;line #|block|# #;expr
In #lang br: #R debugging
If you already know how to write functions, make your own implementations of map and filter.
If you already know how to write macros, make your own implementations of apply, and, and or.