|#594on PLDB||4Years Old||0Books|
; Bel in Bel. 9 October 2019, 9:14 GMT (def no (x) (id x nil)) (def atom (x) (no (id (type x) 'pair))) (def all (f xs) (if (no xs) t (f (car xs)) (all f (cdr xs)) nil)) (def some (f xs) (if (no xs) nil (f (car xs)) xs (some f (cdr xs)))) (def reduce (f xs) (if (no (cdr xs)) (car xs) (f (car xs) (reduce f (cdr xs))))) (def cons args (reduce join args)) (def append args (if (no (cdr args)) (car args) (no (car args)) (apply append (cdr args)) (cons (car (car args)) (apply append (cdr (car args)) (cdr args)))))
; A macro is essentially a function that generates code. I would have ; liked the first example of a macro to be something simpler, but fn ; is the one we need first. So I'll introduce macros using a simpler ; macro that isn't part of Bel, then explain fn. ; Here is a very simple macro: (mac nilwith (x) (list 'cons nil x))
(\h \e \l \l \o) ; can also be represented as "hello"
; The symbol nil represents falsity as well as the empty list. ; The symbol t is the default representation for truth, but any object other than nil also counts as true.
(fn (x) (+ x 1))
(+ 1 2)
; here is a list of a, b, and c: (a . (b . (c . nil))) ; can be written as (a b c)
\p ; Characters that aren't letters may have longer names. For example the bell character, after which Bel is named, is \bel
(foo . bar)
; A comment
; A comment
|Case Insensitive Identifiers||X|