nydp 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lisp/core-040-utils.nydp +16 -0
- data/lib/lisp/core-090-hook.nydp +18 -0
- data/lib/lisp/tests/add-hook-examples.nydp +20 -0
- data/lib/lisp/tests/best-examples.nydp +18 -0
- data/lib/lisp/tests/date-examples.nydp +6 -0
- data/lib/lisp/tests/hash-examples.nydp +9 -0
- data/lib/nydp/date.rb +2 -0
- data/lib/nydp/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2bdfc7b6cc359ea91871fc6ea2d46d454398e72
|
4
|
+
data.tar.gz: 8016a1174d6bbae50cded7bf9988ca50c5aefed9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f85114925c5bcdda72ae5f76db10229527a9e30ec8b96ce71b39dbf24138e1dc5f8544652556ae3c6ae6344c7fa54310e073c9f10a4c94c261521c43149b23d
|
7
|
+
data.tar.gz: b771be6e0e3be575c490179144b0db49983361a80687f374fa2e00805a263070789fdfdec829077d3c8831e634f7e7f1a050e7c9b0aab67db6d6c4579984ccf4
|
@@ -144,6 +144,8 @@
|
|
144
144
|
(def empty? (things) (eq? (len things) 0))
|
145
145
|
|
146
146
|
(mac each (var things code)
|
147
|
+
; repeatedly assigns an element of 'things to 'var,
|
148
|
+
; and executes 'code each time
|
147
149
|
(w/uniq (xs c)
|
148
150
|
`((rfn ,c (,xs)
|
149
151
|
(if (pair? ,xs)
|
@@ -216,3 +218,17 @@
|
|
216
218
|
(cons start
|
217
219
|
(range (+ start 1)
|
218
220
|
stop))))
|
221
|
+
|
222
|
+
(def best (f things)
|
223
|
+
(if (no things)
|
224
|
+
nil
|
225
|
+
(let winner (car things)
|
226
|
+
(each thing (cdr things)
|
227
|
+
(if (f thing winner)
|
228
|
+
(= winner thing)))
|
229
|
+
winner)))
|
230
|
+
|
231
|
+
(def min things (best < things))
|
232
|
+
(def max things (best > things))
|
233
|
+
|
234
|
+
(def hash-cons (h k v) (= h.,k (cons v h.,k)))
|
@@ -0,0 +1,18 @@
|
|
1
|
+
(let hooks {}
|
2
|
+
(def hook-names ()
|
3
|
+
(hash-keys hooks))
|
4
|
+
|
5
|
+
(def hooks-for (hook-name)
|
6
|
+
hooks.,hook-name)
|
7
|
+
|
8
|
+
(def add-hook (hook-name f)
|
9
|
+
(hash-cons hooks hook-name f))
|
10
|
+
|
11
|
+
(def remove-hook (hook-name f)
|
12
|
+
(= hooks.,hook-name
|
13
|
+
(select (curry !eq? f)
|
14
|
+
hooks.,hook-name)))
|
15
|
+
|
16
|
+
(def run-hooks (hook-name . args)
|
17
|
+
(each hook (hooks-for hook-name)
|
18
|
+
(apply hook args))))
|
@@ -0,0 +1,20 @@
|
|
1
|
+
(examples-for add-hook
|
2
|
+
("registers a function to be run in response to a particular event"
|
3
|
+
(with (x nil y nil z nil)
|
4
|
+
(add-hook 'pile-it-up
|
5
|
+
(fn (thing)
|
6
|
+
(= x (cons thing x))))
|
7
|
+
(add-hook 'why-not
|
8
|
+
(fn (thing)
|
9
|
+
(= y (cons thing y))))
|
10
|
+
(add-hook 'pile-it-up
|
11
|
+
(fn (thing)
|
12
|
+
(= z "~thing - ~z")))
|
13
|
+
(run-hooks 'pile-it-up 1)
|
14
|
+
(run-hooks 'pile-it-up 2)
|
15
|
+
(run-hooks 'why-not 'a)
|
16
|
+
(run-hooks 'pile-it-up 3)
|
17
|
+
(run-hooks 'why-not 'b)
|
18
|
+
(run-hooks 'why-not 'c)
|
19
|
+
(list x y z))
|
20
|
+
((3 2 1) (c b a) "3 - 2 - 1 - ")))
|
@@ -0,0 +1,18 @@
|
|
1
|
+
(examples-for best
|
2
|
+
("finds minimum of list"
|
3
|
+
(best < '(3 5 4 7 8 2))
|
4
|
+
2)
|
5
|
+
|
6
|
+
("finds maximum of list"
|
7
|
+
(best > '(3 5 4 7 8 2))
|
8
|
+
8))
|
9
|
+
|
10
|
+
(examples-for min
|
11
|
+
("finds minimum of list"
|
12
|
+
(min 3 5 4 7 8 2)
|
13
|
+
2))
|
14
|
+
|
15
|
+
(examples-for max
|
16
|
+
("finds minimum of list"
|
17
|
+
(max 3 5 4 7 8 2)
|
18
|
+
8))
|
@@ -16,6 +16,12 @@
|
|
16
16
|
("navigates to week start" (let d (date 2015 11 6) (to-string d.beginning-of-week)) "2015-11-02" )
|
17
17
|
("navigates to week end" (let d (date 2015 11 6) (to-string d.end-of-week)) "2015-11-08" )
|
18
18
|
|
19
|
+
("can act as hash key"
|
20
|
+
(with (h {} d (date 2015 11 8))
|
21
|
+
(hash-set h d "on this day")
|
22
|
+
(to-string (hash-get h (date 2015 11 8))))
|
23
|
+
"on this day")
|
24
|
+
|
19
25
|
("returns its year" (let d (date 1999 12 31) d.year) 1999)
|
20
26
|
("returns its month" (let d (date 1999 12 31) d.month) 12 )
|
21
27
|
("returns its day" (let d (date 1999 12 31) d.day) 31 )
|
@@ -18,6 +18,15 @@
|
|
18
18
|
(hash-key? { foo 1 bar 2 } 'zed)
|
19
19
|
nil))
|
20
20
|
|
21
|
+
(examples-for hash-cons
|
22
|
+
("is useful for storing a list in a hash"
|
23
|
+
(let h {}
|
24
|
+
(hash-cons h 'foo 1)
|
25
|
+
(hash-cons h 'foo 2)
|
26
|
+
(hash-cons h 'foo 3)
|
27
|
+
h.foo)
|
28
|
+
(3 2 1)))
|
29
|
+
|
21
30
|
(examples-for brace-list
|
22
31
|
("with no args builds an empty hash"
|
23
32
|
(let thing {}
|
data/lib/nydp/date.rb
CHANGED
@@ -29,6 +29,8 @@ module Nydp
|
|
29
29
|
def > other ; ruby_date > other.ruby_date ; end
|
30
30
|
def < other ; ruby_date < other.ruby_date ; end
|
31
31
|
def == other ; ruby_date == other.ruby_date ; end
|
32
|
+
def eql? d ; self == d ; end
|
33
|
+
def hash ; ruby_date.hash ; end
|
32
34
|
|
33
35
|
@@pass_through = %i{ monday? tuesday? wednesday? thursday? friday? saturday? sunday? }
|
34
36
|
@@keys = Set.new %i{
|
data/lib/nydp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nydp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,6 +95,9 @@ files:
|
|
95
95
|
- lib/lisp/core-060-benchmarking.nydp
|
96
96
|
- lib/lisp/core-070-prefix-list.nydp
|
97
97
|
- lib/lisp/core-080-pretty-print.nydp
|
98
|
+
- lib/lisp/core-090-hook.nydp
|
99
|
+
- lib/lisp/tests/add-hook-examples.nydp
|
100
|
+
- lib/lisp/tests/best-examples.nydp
|
98
101
|
- lib/lisp/tests/boot-tests.nydp
|
99
102
|
- lib/lisp/tests/builtin-tests.nydp
|
100
103
|
- lib/lisp/tests/car-examples.nydp
|