nydp 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +44 -0
- data/lib/lisp/core-010-precompile.nydp +13 -16
- data/lib/lisp/core-012-utils.nydp +21 -6
- data/lib/lisp/core-015-documentation.nydp +58 -24
- data/lib/lisp/core-017-builtin-dox.nydp +49 -42
- data/lib/lisp/core-020-utils.nydp +5 -5
- data/lib/lisp/core-030-syntax.nydp +191 -96
- data/lib/lisp/core-035-flow-control.nydp +41 -14
- data/lib/lisp/core-037-list-utils.nydp +36 -14
- data/lib/lisp/core-039-module.nydp +24 -0
- data/lib/lisp/core-040-utils.nydp +51 -23
- data/lib/lisp/core-041-string-utils.nydp +37 -9
- data/lib/lisp/core-042-date-utils.nydp +21 -1
- data/lib/lisp/core-043-list-utils.nydp +99 -73
- data/lib/lisp/core-045-dox-utils.nydp +5 -0
- data/lib/lisp/core-070-prefix-list.nydp +1 -1
- data/lib/lisp/core-080-pretty-print.nydp +57 -17
- data/lib/lisp/core-090-hook.nydp +35 -1
- data/lib/lisp/core-100-utils.nydp +110 -15
- data/lib/lisp/core-110-hash-utils.nydp +61 -0
- data/lib/lisp/core-120-settings.nydp +46 -0
- data/lib/lisp/core-130-validations.nydp +51 -0
- data/lib/lisp/{core-060-benchmarking.nydp → core-900-benchmarking.nydp} +107 -19
- data/lib/lisp/tests/accum-examples.nydp +28 -1
- data/lib/lisp/tests/aif-examples.nydp +8 -3
- data/lib/lisp/tests/andify-examples.nydp +7 -0
- data/lib/lisp/tests/at-syntax-examples.nydp +17 -0
- data/lib/lisp/tests/best-examples.nydp +9 -0
- data/lib/lisp/tests/builtin-tests.nydp +19 -0
- data/lib/lisp/tests/case-examples.nydp +14 -0
- data/lib/lisp/tests/cdr-set-examples.nydp +6 -0
- data/lib/lisp/tests/date-examples.nydp +56 -1
- data/lib/lisp/tests/destructuring-examples.nydp +46 -14
- data/lib/lisp/tests/detect-examples.nydp +12 -0
- data/lib/lisp/tests/dp-examples.nydp +24 -0
- data/lib/lisp/tests/each-tests.nydp +5 -0
- data/lib/lisp/tests/empty-examples.nydp +1 -1
- data/lib/lisp/tests/error-tests.nydp +4 -4
- data/lib/lisp/tests/explain-mac-examples.nydp +1 -1
- data/lib/lisp/tests/filter-forms-examples.nydp +15 -0
- data/lib/lisp/tests/foundation-test.nydp +12 -0
- data/lib/lisp/tests/hash-examples.nydp +26 -2
- data/lib/lisp/tests/list-grep-examples.nydp +40 -0
- data/lib/lisp/tests/list-tests.nydp +58 -1
- data/lib/lisp/tests/map-hash-examples.nydp +11 -0
- data/lib/lisp/tests/module-examples.nydp +10 -0
- data/lib/lisp/tests/multi-assign-examples.nydp +6 -0
- data/lib/lisp/tests/parser-tests.nydp +25 -0
- data/lib/lisp/tests/pretty-print-tests.nydp +17 -14
- data/lib/lisp/tests/set-difference-examples.nydp +8 -0
- data/lib/lisp/tests/set-intersection-examples.nydp +16 -0
- data/lib/lisp/tests/set-union-examples.nydp +8 -0
- data/lib/lisp/tests/settings-examples.nydp +40 -0
- data/lib/lisp/tests/sort-examples.nydp +8 -0
- data/lib/lisp/tests/string-tests.nydp +65 -1
- data/lib/lisp/tests/syntax-tests.nydp +5 -1
- data/lib/lisp/tests/to-integer-examples.nydp +16 -0
- data/lib/lisp/tests/validation-examples.nydp +15 -0
- data/lib/lisp/tests/zap-examples.nydp +12 -0
- data/lib/nydp.rb +13 -7
- data/lib/nydp/assignment.rb +10 -3
- data/lib/nydp/builtin.rb +1 -1
- data/lib/nydp/builtin/abs.rb +8 -0
- data/lib/nydp/builtin/cdr_set.rb +1 -6
- data/lib/nydp/builtin/date.rb +15 -1
- data/lib/nydp/builtin/error.rb +1 -1
- data/lib/nydp/builtin/handle_error.rb +1 -1
- data/lib/nydp/builtin/hash.rb +27 -45
- data/lib/nydp/builtin/inspect.rb +1 -1
- data/lib/nydp/builtin/plus.rb +10 -2
- data/lib/nydp/builtin/random_string.rb +2 -2
- data/lib/nydp/builtin/{car.rb → regexp.rb} +2 -2
- data/lib/nydp/builtin/ruby_wrap.rb +72 -0
- data/lib/nydp/builtin/string_match.rb +2 -2
- data/lib/nydp/builtin/string_pad_left.rb +7 -0
- data/lib/nydp/builtin/string_pad_right.rb +7 -0
- data/lib/nydp/builtin/string_replace.rb +1 -1
- data/lib/nydp/builtin/string_split.rb +4 -3
- data/lib/nydp/builtin/to_integer.rb +23 -0
- data/lib/nydp/builtin/to_string.rb +2 -9
- data/lib/nydp/builtin/type_of.rb +9 -6
- data/lib/nydp/closure.rb +0 -3
- data/lib/nydp/cond.rb +23 -1
- data/lib/nydp/context_symbol.rb +14 -6
- data/lib/nydp/core.rb +36 -28
- data/lib/nydp/core_ext.rb +54 -0
- data/lib/nydp/date.rb +37 -31
- data/lib/nydp/function_invocation.rb +34 -26
- data/lib/nydp/hash.rb +5 -6
- data/lib/nydp/helper.rb +41 -25
- data/lib/nydp/interpreted_function.rb +68 -40
- data/lib/nydp/literal.rb +1 -1
- data/lib/nydp/pair.rb +22 -5
- data/lib/nydp/parser.rb +11 -7
- data/lib/nydp/string_atom.rb +16 -22
- data/lib/nydp/symbol.rb +40 -27
- data/lib/nydp/symbol_lookup.rb +7 -7
- data/lib/nydp/tokeniser.rb +2 -2
- data/lib/nydp/truth.rb +17 -10
- data/lib/nydp/version.rb +1 -1
- data/lib/nydp/vm.rb +7 -2
- data/nydp.gemspec +2 -4
- data/spec/date_spec.rb +115 -22
- data/spec/embedded_spec.rb +12 -12
- data/spec/foreign_hash_spec.rb +14 -2
- data/spec/hash_non_hash_behaviour_spec.rb +7 -7
- data/spec/hash_spec.rb +24 -2
- data/spec/nydp_spec.rb +14 -2
- data/spec/pair_spec.rb +3 -1
- data/spec/parser_spec.rb +31 -20
- data/spec/rand_spec.rb +3 -3
- data/spec/spec_helper.rb +13 -1
- data/spec/symbol_spec.rb +31 -0
- data/spec/time_spec.rb +1 -1
- metadata +31 -38
- data/lib/nydp/builtin/cdr.rb +0 -7
- data/lib/nydp/builtin/cons.rb +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '0389044de6d7b6230da9315bc8dde967e1ddf8ed77df2b8ef4106ce9bfc3e93a'
|
|
4
|
+
data.tar.gz: 133567982e2fbb734ea429e98197e4b7d5bc49c2130f64ec630c095adcd1f250
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2516bbc0473796915710786bb8b43ac339df657438e5a35d8f8d38cb5a7b46c1663b09a8cea266369b168530b63a1f249daf882d2712cd8558febb167bc648ef
|
|
7
|
+
data.tar.gz: 2548a1e1259f053ff25bc490d13f44579720be5f0ea7954915917092a04d0619f0b014221f55ed6b1f86f5046f5a6a7244348ff4805a2282ece150c3993be71f
|
data/README.md
CHANGED
|
@@ -55,6 +55,22 @@ answer = Nydp.apply_function ns, :question, :life, ["The Universe", and_also(eve
|
|
|
55
55
|
|
|
56
56
|
You can maintain multiple `ns` instances without mutual interference. In other words, assigning global variables while one `ns` is in scope will not affect the values of variables in any other `ns` (unless you've specifically arranged it to be so by duplicating namespaces or some such sorcery).
|
|
57
57
|
|
|
58
|
+
|
|
59
|
+
#### Facing the Truth
|
|
60
|
+
|
|
61
|
+
In conditional statements, nil is false, anything else is true
|
|
62
|
+
|
|
63
|
+
```lisp
|
|
64
|
+
(if) ;; same as (if nil)
|
|
65
|
+
(if a) ;; same as a
|
|
66
|
+
(if a b) ;; same as (if a b nil)
|
|
67
|
+
(if a b c) ;; if a is nil, return c, otherwise return b
|
|
68
|
+
(if a b c d) ;; same as (if a b (if c d))
|
|
69
|
+
(if a b c d e) ;; same as (if a b (if c d e))
|
|
70
|
+
|
|
71
|
+
;; and so on
|
|
72
|
+
```
|
|
73
|
+
|
|
58
74
|
## Different from Arc :
|
|
59
75
|
|
|
60
76
|
#### 1. Macro-expansion runs in lisp
|
|
@@ -151,8 +167,36 @@ nydp > (map &lastname german-composers) ; ampersand-syntax creates a function
|
|
|
151
167
|
|
|
152
168
|
As with all other syntax, you can of course override the `ampersand-syntax` macro to handle your special needs.
|
|
153
169
|
|
|
170
|
+
You can combine special syntaxes ("%td" comes from nydp-html gem)
|
|
171
|
+
|
|
172
|
+
```lisp
|
|
173
|
+
|
|
174
|
+
nydp > (map %td:&lastname german-composers)
|
|
175
|
+
|
|
176
|
+
"<td>Bach</td><td>Beethoven</td><td>Wagner</td><td>Mozart</td>"
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
So, @%td@ expands to @(percent-syntax || td)@, @&lastname@ to @(ampersand-syntax || lastname)@, and the whole @%td:&lastname@
|
|
181
|
+
to @(colon-syntax (percent-syntax || td) (ampersand-syntax || lastname))@. Luckily for you, there's a fine @colon-syntax@ macro
|
|
182
|
+
that knows how to build a function out of these bits and pieces.
|
|
183
|
+
|
|
184
|
+
|
|
154
185
|
Look for `SYMBOL_OPERATORS` in [parser.rb](lib/nydp/parser.rb) to see which syntax is recognised and in which order. The order of these definitions defines special-syntax-operator precedence.
|
|
155
186
|
|
|
187
|
+
Any character that is not special syntax will be recognised as part of a symbol. At time of writing, this includes the plus sign, hyphen, and slash.
|
|
188
|
+
|
|
189
|
+
```lisp
|
|
190
|
+
|
|
191
|
+
;; nonsense code illustrating the use of certain
|
|
192
|
+
;; characters as function and variable names
|
|
193
|
+
(def //-+ (x y z)
|
|
194
|
+
(let -*- (x y)
|
|
195
|
+
(if z (//-+ x y -*-) -*-)))
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
|
|
156
200
|
#### 3. Special list syntax
|
|
157
201
|
|
|
158
202
|
The parser detects alternative list delimiters
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
(assign mac-expand
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
(assign mac-expand
|
|
2
|
+
(fn (names macfn expr)
|
|
3
|
+
(cond macfn
|
|
4
|
+
(handle-error
|
|
5
|
+
(fn (errors)
|
|
6
|
+
(error "expanding" (inspect expr) "with" (inspect macfn)))
|
|
7
|
+
(fn ()
|
|
8
|
+
(pre-compile-with names (apply macfn (cdr expr)))))
|
|
9
|
+
expr)))
|
|
6
10
|
|
|
7
11
|
(assign macs (hash))
|
|
8
12
|
|
|
9
|
-
(assign pre-compile-expr
|
|
10
|
-
(fn (names expr)
|
|
11
|
-
(mac-expand names
|
|
12
|
-
(hash-get names (car expr))
|
|
13
|
-
expr)))
|
|
14
|
-
|
|
15
13
|
(assign pre-compile-each
|
|
16
14
|
(fn (names args)
|
|
17
15
|
(cond args
|
|
@@ -33,7 +31,10 @@
|
|
|
33
31
|
(cond (eq? (car arg) 'quote)
|
|
34
32
|
arg
|
|
35
33
|
(pre-compile-each names
|
|
36
|
-
(
|
|
34
|
+
(mac-expand names
|
|
35
|
+
(hash-get names
|
|
36
|
+
(car arg))
|
|
37
|
+
arg)))
|
|
37
38
|
arg)))
|
|
38
39
|
|
|
39
40
|
(assign pre-compile-debug
|
|
@@ -136,7 +137,3 @@
|
|
|
136
137
|
|
|
137
138
|
(hash-set macs 'quasiquote
|
|
138
139
|
(fn (arg) (qq-quasiquote arg 0)))
|
|
139
|
-
|
|
140
|
-
(hash-set macs 'do
|
|
141
|
-
(fn args
|
|
142
|
-
`((fn nil ,@args))))
|
|
@@ -8,16 +8,31 @@
|
|
|
8
8
|
(car args))
|
|
9
9
|
nil)))
|
|
10
10
|
|
|
11
|
-
(def map (f things)
|
|
12
|
-
; transforms the list 'things by applying 'f to each item
|
|
13
|
-
; returns the resulting list
|
|
11
|
+
(def map-helper-0 (f things lc)
|
|
14
12
|
(if (pair? things)
|
|
15
|
-
(
|
|
13
|
+
(map-helper-0 f (cdr things) (cdr-set lc (cons (f (car things)))))
|
|
16
14
|
things
|
|
17
|
-
(f things)))
|
|
15
|
+
(cdr-set lc (f things))))
|
|
16
|
+
|
|
17
|
+
(def map-helper-1 (f things acc)
|
|
18
|
+
(map-helper-0 f things acc)
|
|
19
|
+
(cdr acc))
|
|
20
|
+
|
|
21
|
+
;; transforms the list 'things by applying 'f to each item, returns the resulting list
|
|
22
|
+
;; conceptually, does the following:
|
|
23
|
+
;;
|
|
24
|
+
;; (if (pair? things)
|
|
25
|
+
;; (cons (f (car things)) (map f (cdr things)))
|
|
26
|
+
;; things
|
|
27
|
+
;; (f things))
|
|
28
|
+
;;
|
|
29
|
+
;; however the actual version is more complicated to allow for TCO ("modulo-cons" issue)
|
|
30
|
+
(def map (f things)
|
|
31
|
+
(map-helper-1 f things (cons)))
|
|
18
32
|
|
|
33
|
+
;; push 'v onto the value for 'k in 'h
|
|
34
|
+
;; the hash-values of h will all be lists, in reverse order of consing
|
|
19
35
|
(def hash-cons (h k v)
|
|
20
|
-
; push 'v onto the value for 'k in 'h
|
|
21
36
|
(hash-set h k (cons v (hash-get h k))))
|
|
22
37
|
|
|
23
38
|
(def rev (things last-cdr)
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
acc)))
|
|
20
20
|
form))
|
|
21
21
|
|
|
22
|
+
(hash-set macs 'do
|
|
23
|
+
(fn forms
|
|
24
|
+
(if (no (cdr forms))
|
|
25
|
+
(car forms)
|
|
26
|
+
`((fn nil ,@forms)))))
|
|
27
|
+
|
|
22
28
|
((fn (this-chapter-name chapters chapter-new chapter-build chapter-add-to-chapter)
|
|
23
29
|
(assign chapters (hash))
|
|
24
30
|
|
|
@@ -64,7 +70,7 @@
|
|
|
64
70
|
(assign this-script nil)
|
|
65
71
|
(assign this-plugin "Nydp Core")
|
|
66
72
|
|
|
67
|
-
((fn (dox examples chapters dox-new dox-build)
|
|
73
|
+
((fn (dox examples chapters types types-chapters dox-new dox-build)
|
|
68
74
|
(def dox-build (hsh name what texts args src chapters)
|
|
69
75
|
(hash-set hsh 'name name )
|
|
70
76
|
(hash-set hsh 'what what )
|
|
@@ -78,26 +84,38 @@
|
|
|
78
84
|
|
|
79
85
|
(def dox-new (item)
|
|
80
86
|
(hash-cons dox (hash-get item 'name) item)
|
|
81
|
-
(
|
|
87
|
+
(hash-cons types (hash-get item 'what) item)
|
|
88
|
+
(dox-add-to-chapters item (hash-get item 'what) (hash-get item 'chapters) (hash)))
|
|
82
89
|
|
|
83
90
|
(def dox-add-doc (name what texts args src chapters more)
|
|
84
91
|
(cond (no (privately))
|
|
85
92
|
(dox-new (dox-build (if more more (hash)) name what texts args src chapters))))
|
|
86
93
|
|
|
87
|
-
(def dox-add-to-chapters (item chapters)
|
|
94
|
+
(def dox-add-to-chapters (item type chapters already)
|
|
88
95
|
(cond chapters
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
(cond (no (hash-get already (car chapters)))
|
|
97
|
+
(do (hash-set already (car chapters) t)
|
|
98
|
+
(chapter-add-item item (car chapters))
|
|
99
|
+
(hash-cons types-chapters (inspect (cons type (car chapters))) item)
|
|
100
|
+
(dox-add-to-chapters item type (cdr chapters) already))
|
|
101
|
+
item)
|
|
91
102
|
item))
|
|
92
103
|
|
|
93
104
|
(def dox-add-examples (name example-exprs)
|
|
94
105
|
(hash-cons examples name example-exprs))
|
|
95
106
|
|
|
96
|
-
(def dox-lookup (
|
|
107
|
+
(def dox-lookup (name) (hash-get dox name))
|
|
97
108
|
|
|
98
109
|
(def dox? (sym) (hash-key? dox sym))
|
|
99
110
|
|
|
100
111
|
(def dox-names () (hash-keys dox))
|
|
112
|
+
(def dox-types () (hash-keys types))
|
|
113
|
+
(def dox-items-by-type (type) (hash-get types type))
|
|
114
|
+
|
|
115
|
+
(def get-types-chapters () types-chapters)
|
|
116
|
+
|
|
117
|
+
(def dox-items-by-type-and-chapter (dox-type chapter)
|
|
118
|
+
(hash-get types-chapters (inspect (cons dox-type chapter))))
|
|
101
119
|
|
|
102
120
|
(def dox-get-attr (name attr)
|
|
103
121
|
(cond (dox? name)
|
|
@@ -108,7 +126,7 @@
|
|
|
108
126
|
(def dox-examples (name) (hash-get examples name ))
|
|
109
127
|
(def dox-args (name) (dox-get-attr name 'args ))
|
|
110
128
|
(def dox-example-names () (hash-keys examples )))
|
|
111
|
-
(hash) (hash) (hash) nil)
|
|
129
|
+
(hash) (hash) (hash) (hash) (hash) nil)
|
|
112
130
|
|
|
113
131
|
(def plugin-start (name) (assign this-plugin name) (chapter-end))
|
|
114
132
|
(def plugin-end (name) (assign this-plugin nil ) (chapter-end))
|
|
@@ -125,9 +143,9 @@
|
|
|
125
143
|
(cond (eq? event 'script-end)
|
|
126
144
|
(script-end name))))))
|
|
127
145
|
|
|
146
|
+
;; if the car of 'form is a key of 'hsh, add the cdr of 'form to the value of the key in 'hsh
|
|
147
|
+
;; otherwise add the form to the list whose key is nil
|
|
128
148
|
(def filter-form (hsh form)
|
|
129
|
-
; if the car of 'form is a key of 'hsh, add the cdr of 'form to the value of the key in 'hsh
|
|
130
|
-
; otherwise add the form to the list whose key is nil
|
|
131
149
|
(cond (cond (pair? form)
|
|
132
150
|
(hash-key? hsh (car form)))
|
|
133
151
|
(hash-cons hsh (car form) (cdr form))
|
|
@@ -146,31 +164,43 @@
|
|
|
146
164
|
(def rev-values (hsh)
|
|
147
165
|
(rev-value-keys (hash-keys hsh) hsh (hash)))
|
|
148
166
|
|
|
167
|
+
;; group forms by their first element, if the first element
|
|
168
|
+
;; is already a key in hsh, collect all other elements under key nil
|
|
149
169
|
(def filter-forms (hsh forms)
|
|
150
|
-
; group forms by their first element, if the first element
|
|
151
|
-
; is already a key in hsh, collect all other elements under key nil
|
|
152
170
|
(cond forms
|
|
153
171
|
(filter-forms (filter-form hsh (car forms)) (cdr forms))
|
|
154
172
|
(rev-values hsh)))
|
|
155
173
|
|
|
156
|
-
(def
|
|
157
|
-
(
|
|
158
|
-
|
|
159
|
-
|
|
174
|
+
(def filter-remove (key forms keyforms otherforms)
|
|
175
|
+
(cond forms
|
|
176
|
+
(cond (cond (pair? forms) (cond (pair? (car forms)) (eq? key (caar forms))))
|
|
177
|
+
(filter-remove key (cdr forms) (cons (car forms) keyforms) otherforms)
|
|
178
|
+
(filter-remove key (cdr forms) keyforms (cons (car forms) otherforms)))
|
|
179
|
+
(list (rev keyforms) (rev otherforms))))
|
|
160
180
|
|
|
181
|
+
(assign DEF-FORMS '(comment chapter))
|
|
182
|
+
|
|
183
|
+
(def build-def-hash ()
|
|
184
|
+
((fn (h)
|
|
185
|
+
(map (fn (k) (hash-set h k nil)) DEF-FORMS)
|
|
186
|
+
h)
|
|
187
|
+
(hash)))
|
|
188
|
+
|
|
189
|
+
(def dox-build-def-name (name) name)
|
|
190
|
+
|
|
191
|
+
;; used internally by 'mac
|
|
161
192
|
(def define-mac-expr (name args body-forms)
|
|
162
|
-
; used internally by 'mac
|
|
163
193
|
`(do (hash-set macs ',name (fun ,args ,@(hash-get body-forms nil)))
|
|
164
|
-
(dox-add-doc ',name
|
|
194
|
+
(dox-add-doc ',(dox-build-def-name name)
|
|
165
195
|
'mac
|
|
166
|
-
',(map car (hash-get body-forms 'comment))
|
|
196
|
+
',(+ (fetch-and-clear-comments) (map car (hash-get body-forms 'comment)))
|
|
167
197
|
',args
|
|
168
198
|
'(mac ,name ,args ,@(hash-get body-forms nil))
|
|
169
199
|
',(map car (hash-get body-forms 'chapter)))))
|
|
170
200
|
|
|
171
201
|
(hash-set macs 'mac
|
|
172
202
|
(fn (name args . body)
|
|
173
|
-
(define-mac-expr name args (filter-forms (build-def-hash
|
|
203
|
+
(define-mac-expr name args (filter-forms (build-def-hash) body))))
|
|
174
204
|
|
|
175
205
|
(dox-add-doc 'mac
|
|
176
206
|
'mac
|
|
@@ -186,22 +216,26 @@
|
|
|
186
216
|
'`((fn nil ,@args))
|
|
187
217
|
'(nydp-core))
|
|
188
218
|
|
|
219
|
+
;; override later to use '= instead of 'assign, giving us hash-assignment and other goodies for free
|
|
189
220
|
(mac def-assign args `(assign ,@args))
|
|
190
221
|
|
|
222
|
+
;; used internally by 'def
|
|
191
223
|
(def define-def-expr (name args body-forms)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
224
|
+
`(do (def-assign ,name
|
|
225
|
+
((fn (self-name)
|
|
226
|
+
(fun ,args ,@(filter-comments (hash-get body-forms nil))))
|
|
227
|
+
',name))
|
|
228
|
+
(dox-add-doc ',(dox-build-def-name name)
|
|
195
229
|
'def
|
|
196
230
|
',(+ (fetch-and-clear-comments) (map car (hash-get body-forms 'comment)))
|
|
197
231
|
',args
|
|
198
232
|
'(def ,name ,args ,@(hash-get body-forms nil))
|
|
199
233
|
',(map car (hash-get body-forms 'chapter)))))
|
|
200
234
|
|
|
235
|
+
;; define a new function in the global namespace
|
|
201
236
|
(mac def (name args . body)
|
|
202
|
-
; define a new function in the global namespace
|
|
203
237
|
(chapter nydp-core)
|
|
204
|
-
(define-def-expr name args (filter-forms (build-def-hash
|
|
238
|
+
(define-def-expr name args (filter-forms (build-def-hash) body)))
|
|
205
239
|
|
|
206
240
|
(mac comment (txt)
|
|
207
241
|
(assign comments (cons txt comments))
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
(dox-add-doc 'cons 'def '("with args a and b, returns a new cons cell, (a . b)") '(a b) nil '(list-manipulation))
|
|
2
2
|
(dox-add-doc 'car 'def '("with args a, where a is a cons cell (x . y), return x." "Commonly used to get the first element of a list") '(a) nil '(list-manipulation))
|
|
3
3
|
(dox-add-doc 'cdr 'def '("with args a, where a is a cons cell (x . y), return y." "Commonly used to get contents of a list, excluding the first element") '(a) nil '(list-manipulation))
|
|
4
|
+
(dox-add-doc 'log 'def '("write arg to Nydp.logger ; be sure to assign Nydp.logger first!") '(arg) nil '(nydp-core))
|
|
4
5
|
(dox-add-doc '+ 'def '("with rest-args things, return the sum of the elements of things." "Will also increment dates and concatenate strings and lists") 'things nil '(math))
|
|
5
6
|
(dox-add-doc '- 'def '("return the result of subtracting all other args from the first arg." "(- a b c d) is equivalent to (- a (+ b c d))") 'things nil '(math))
|
|
6
7
|
(dox-add-doc '* 'def '("with rest-args things, return the product of the elements of things.") 'things nil '(math))
|
|
@@ -35,21 +36,22 @@
|
|
|
35
36
|
(dox-add-doc 'pair? 'def '("t if arg is a cons cell or (equivalently) the start of a list") '(arg) nil '(nydp-core))
|
|
36
37
|
(dox-add-doc 'hash? 'def '("t if arg is a hash") '(arg) nil '(nydp-core))
|
|
37
38
|
(dox-add-doc 'sym? 'def '("t if arg is a symbol, nil otherwise") '(arg) nil '(nydp-core))
|
|
38
|
-
(dox-add-doc 'ensuring 'def '("execute '
|
|
39
|
-
"'ensure-f will always be executed, even if there is an error in '
|
|
40
|
-
"returns the return value of '
|
|
39
|
+
(dox-add-doc 'ensuring 'def '("execute 'try-f, then 'ensure-f afterwards"
|
|
40
|
+
"'ensure-f will always be executed, even if there is an error in 'try-f"
|
|
41
|
+
"returns the return value of 'try-f. Similar to try/finally in java, or begin/ensure in ruby.") '(ensure-f try-f) nil '(flow-control))
|
|
41
42
|
(dox-add-doc 'inspect 'def '("return a string representing 'arg, potentially (but not always) in a way that can be parsed back in to get the original object") '(arg) nil '(nydp-core))
|
|
42
43
|
(dox-add-doc 'comment 'def '("does nothing at all." "Intercepted inside 'def and 'mac and used for documentation") '(arg) nil '(nydp-core))
|
|
43
44
|
(dox-add-doc 'parse-in-string 'def '("parse the given string assuming a string-open delimiter has already been encountered") '(str) nil '(nydp-core))
|
|
44
45
|
(dox-add-doc 'rand 'def '("return a random number ; with no args, between 0 and 1"
|
|
45
46
|
"with 1 arg, an integer less than arg"
|
|
46
|
-
"with two args, an integer >= arg 0 and < arg 1") 'args
|
|
47
|
-
(dox-add-doc 'random-string 'def '("return a random string of length 'len (default 10)") '(len)
|
|
48
|
-
(dox-add-doc '
|
|
49
|
-
(dox-add-doc 'string
|
|
50
|
-
(dox-add-doc 'string-
|
|
51
|
-
(dox-add-doc 'string-
|
|
52
|
-
(dox-add-doc 'string-
|
|
47
|
+
"with two args, an integer >= arg 0 and < arg 1") 'args nil '(math))
|
|
48
|
+
(dox-add-doc 'random-string 'def '("return a random string of length 'len (default 10)") '(len) nil '(string-manipulation))
|
|
49
|
+
(dox-add-doc 'regexp 'def '("return a regular expression compiled from the given string") '(str) nil '(string-manipulation))
|
|
50
|
+
(dox-add-doc 'to-string 'def '("return a human-readable string representation of 'arg") '(arg) nil '(string-manipulation))
|
|
51
|
+
(dox-add-doc 'string-length 'def '("return the length of 'arg") '(arg) nil '(string-manipulation))
|
|
52
|
+
(dox-add-doc 'string-replace 'def '("replace 'pattern with 'replacement in 'str") '(pattern replacement str) nil '(string-manipulation))
|
|
53
|
+
(dox-add-doc 'string-split 'def '("split 'str delimited by 'delim") '(str delim) nil '(string-manipulation))
|
|
54
|
+
(dox-add-doc 'string-match 'def '("if 'str matches 'pattern, return hash with keys 'match and 'captures ; otherwise nil") '(str pattern) nil '(string-manipulation))
|
|
53
55
|
(dox-add-doc 'time 'def '("with no args, return the current time."
|
|
54
56
|
"With one arg, if 'arg-0 is a number, return the current time plus 'arg-0 seconds."
|
|
55
57
|
"With one arg, if 'arg-0 is a date, return the time at the beginning of the given date."
|
|
@@ -57,37 +59,42 @@
|
|
|
57
59
|
"With two args, 'arg-0 must be a time."
|
|
58
60
|
"If 'arg-1 is a number, return 'arg-0 plus 'arg-1 seconds as a time object."
|
|
59
61
|
"If 'arg-1 is a time, return the number of seconds between the two (- 'arg-0 arg-1)."
|
|
60
|
-
"Otherwise, expect 3
|
|
62
|
+
"Otherwise, expect 3 or more args, to construct a time from"
|
|
61
63
|
"year, month, date, hours, minutes, seconds, milliseconds, reading arguments in that order,"
|
|
62
|
-
"where hours, minutes, seconds, and milliseconds are optional")
|
|
63
|
-
(dox-add-doc 'thread-locals
|
|
64
|
-
(dox-add-doc 'type-of
|
|
65
|
-
(dox-add-doc 'eq?
|
|
66
|
-
(dox-add-doc 'cdr-set
|
|
67
|
-
(dox-add-doc 'hash-get
|
|
68
|
-
(dox-add-doc 'hash-set
|
|
69
|
-
(dox-add-doc 'hash-keys
|
|
70
|
-
(dox-add-doc 'hash-key?
|
|
71
|
-
(dox-add-doc 'hash-merge
|
|
72
|
-
(dox-add-doc 'vm-info
|
|
73
|
-
(dox-add-doc 'pre-compile
|
|
74
|
-
(dox-add-doc 'script-run
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
"where hours, minutes, seconds, and milliseconds are optional") 'args nil '(date-time))
|
|
65
|
+
(dox-add-doc 'thread-locals 'def '("return a hash bound to the current thread") nil nil '(nydp-core))
|
|
66
|
+
(dox-add-doc 'type-of 'def '("return a symbol for the type of 'arg") '(arg) nil '(nydp-core))
|
|
67
|
+
(dox-add-doc 'eq? 'def '("return 't if 'arg-0 and 'arg-1 are equal, nil otherwise") '(arg-0 arg-1) nil '(nydp-core))
|
|
68
|
+
(dox-add-doc 'cdr-set 'def '("set the cdr of the given 'cell to 'arg, returns 'cell") '(cell arg) nil '(list-manipulation))
|
|
69
|
+
(dox-add-doc 'hash-get 'def '("return the value stored by 'key in 'hsh") '(hsh key) nil '(hash-manipulation))
|
|
70
|
+
(dox-add-doc 'hash-set 'def '("store 'val under 'key in 'hsh, return 'val") '(hsh key val) nil '(hash-manipulation))
|
|
71
|
+
(dox-add-doc 'hash-keys 'def '("return the list of keys in 'hsh") '(hsh) nil '(hash-manipulation))
|
|
72
|
+
(dox-add-doc 'hash-key? 'def '("return 't if 'key is a key of 'hsh") '(hsh key) nil '(hash-manipulation))
|
|
73
|
+
(dox-add-doc 'hash-merge 'def '("return a new hash containing keys and values from 'h0 and 'h1, where values of 'h1 override values of 'h0") '(h0 h1) nil '(hash-manipulation))
|
|
74
|
+
(dox-add-doc 'vm-info 'def '("return some information about the state of the current thread") nil nil '(nydp-core))
|
|
75
|
+
(dox-add-doc 'pre-compile 'def '("transform parsed forms before the compile and eval stages") '(arg) nil '(nydp-compilation))
|
|
76
|
+
(dox-add-doc 'script-run 'def '("announces the start of a plugin load or a script load."
|
|
77
|
+
"'event may be one of '(script-start script-end plugin-start plugin-end)"
|
|
78
|
+
"'name is the name of the script or plugin concerned") '(event name) nil '(nydp-core))
|
|
77
79
|
|
|
78
|
-
(dox-add-doc 'chapter-end
|
|
79
|
-
(dox-add-doc 'chapter-start
|
|
80
|
-
(dox-add-doc 'chapter-names
|
|
81
|
-
(dox-add-doc 'chapter-current
|
|
82
|
-
(dox-add-doc 'chapter-delete
|
|
83
|
-
(dox-add-doc 'chapter-find
|
|
84
|
-
(dox-add-doc 'set-intersection
|
|
85
|
-
(dox-add-doc '
|
|
86
|
-
(dox-add-doc '
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
(dox-add-doc 'chapter-end 'def '("Announce the end of a chapter. Called by 'plugin-start, 'plugin-end, 'script-start, 'script-end") nil nil '(nydp/documentation))
|
|
81
|
+
(dox-add-doc 'chapter-start 'def '("Announce the start of a chapter. Creates a new chapter if the named chapter does not already exist") '(chapter-name description) nil '(nydp/documentation))
|
|
82
|
+
(dox-add-doc 'chapter-names 'def '("Get the names of all the chapters nydp knows about") nil nil '(nydp/documentation))
|
|
83
|
+
(dox-add-doc 'chapter-current 'def '("Get the name of the chapter in progress right now - this is normally the last value sent to 'chapter-start") nil nil '(nydp/documentation))
|
|
84
|
+
(dox-add-doc 'chapter-delete 'def '("Remove the named chapter") '(name) nil '(nydp/documentation))
|
|
85
|
+
(dox-add-doc 'chapter-find 'def '("Get the named chapter") '(name) nil '(nydp/documentation))
|
|
86
|
+
(dox-add-doc 'set-intersection 'def '("return the intersection of the given lists") 'args nil '(list-manipulation))
|
|
87
|
+
(dox-add-doc '⋂ 'def '("return the intersection of the given lists") 'args nil '(list-manipulation))
|
|
88
|
+
(dox-add-doc 'set-union 'def '("return the union of the given lists") 'args nil '(list-manipulation))
|
|
89
|
+
(dox-add-doc '⋃ 'def '("return the union of the given lists") 'args nil '(list-manipulation))
|
|
90
|
+
(dox-add-doc 'dox-add-doc 'def '("Store the provided documentation item."
|
|
91
|
+
"'name is the name of the item"
|
|
92
|
+
"'what is the type of the item ('def or 'mac or 'thingy ... this is user-definable, not related to 'type-of)"
|
|
93
|
+
"'texts is a list of strings to store for this item"
|
|
94
|
+
"'args is the args if the item has the notion of args"
|
|
95
|
+
"'src the source code of the item if any"
|
|
96
|
+
"'chapters the chapters to which the item should be added, if any") '(name what texts args src chapters) nil '(nydp/documentation))
|
|
97
|
+
(dox-add-doc 'dox-add-examples 'def '("Add the given examples to the dox for the named item") '(name example-exprs) nil '(nydp/documentation))
|
|
98
|
+
(dox-add-doc 'dox-types 'def '("Get the list of types of documented items") nil nil '(nydp/documentation))
|
|
99
|
+
(dox-add-doc 'dox-lookup 'def '("Get the documentation for the given item") '(name) nil '(nydp/documentation))
|
|
100
|
+
(dox-add-doc 'dox-items-by-type 'def '("Get the list of dox items of a given type") '(type) nil '(nydp/documentation))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(assign script-name "core-
|
|
1
|
+
(assign script-name "core-020-utils.nydp")
|
|
2
2
|
|
|
3
3
|
(dox-add-doc 'if
|
|
4
4
|
'mac
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
'(hash-set h k (cons v (hash-get h k)))
|
|
44
44
|
'(hash-manipulation))
|
|
45
45
|
|
|
46
|
+
;; equivalent to (join-str "~prefix~joint~(car things)" joint (cdr things)) - except
|
|
47
|
+
;; 'string-pieces hasn't been defined yet, and if it were, it would be defined in terms of
|
|
48
|
+
;; 'join-str, so it would be circular.
|
|
49
|
+
;; see 'joinstr for a more powerful and easier-to-use implementation of the same idea
|
|
46
50
|
(def join-str (prefix joint things)
|
|
47
51
|
(chapter string-manipulation)
|
|
48
|
-
; equivalent to (join-str "~prefix~joint~(car things)" joint (cdr things)) - except
|
|
49
|
-
; 'string-pieces hasn't been defined yet, and if it were, it would be defined in terms of
|
|
50
|
-
; 'join-str, so it would be circular.
|
|
51
|
-
; see 'joinstr for a more powerful and easier-to-use implementation of the same idea
|
|
52
52
|
(if things
|
|
53
53
|
(join-str (+ (to-string prefix)
|
|
54
54
|
joint
|