-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
bel.scroll
83 lines (78 loc) · 2.12 KB
/
bel.scroll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import ../code/conceptPage.scroll
id bel
name Bel
appeared 2019
creators Paul Graham
tags pl
website http://paulgraham.com/bel.html
relatedConcepts arc
documentation https://sep.yimg.com/ty/cdn/paulgraham/bellanguage.txt?t=1595850613&
country United States
example
; 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)))))
lineCommentToken ;
printToken prn
hasLineComments true
; A comment
hasComments true
; A comment
hasPrintDebugging true
hasPairs true
(foo . bar)
hasSymbols true
foo
hasCharacters true
\p
; Characters that aren't letters may have longer names. For example the bell character, after which Bel is named, is
\bel
hasLists true
; here is a list of a, b, and c:
(a . (b . (c . nil)))
; can be written as
(a b c)
hasCaseInsensitiveIdentifiers false
hasStreams true
hasExpressions true
(+ 1 2)
hasFunctions true
(fn (x) (+ x 1))
hasBooleans true
; 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.
hasStrings true
(\h \e \l \l \o)
; can also be represented as
"hello"
hasSemanticIndentation false
hasMacros true
; 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))