nydp 0.1.6 → 0.1.7
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 +27 -14
- data/lib/lisp/core-100-utils.nydp +4 -0
- data/lib/lisp/tests/date-examples.nydp +18 -16
- data/lib/lisp/tests/detect-examples.nydp +26 -3
- data/lib/lisp/tests/hash-examples.nydp +38 -0
- data/lib/lisp/tests/include-examples.nydp +20 -0
- data/lib/nydp/builtin/hash.rb +4 -3
- data/lib/nydp/date.rb +4 -3
- data/lib/nydp/truth.rb +1 -1
- data/lib/nydp/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c06a0264cdd46d00dc6380d8e864fa5471742b9c
|
4
|
+
data.tar.gz: e154d0f6bf4bfdc48eb86daa8b28d41568683e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 695695ea3b5c9d70a13eec9d907d81b0b7e8f1fefe7d5a7f6d5e1e4b81c6e68b05ba938e7a1c5a6ed15ddb05b837a069e44b4f5c19fdbbad05541d3404f11856
|
7
|
+
data.tar.gz: b01929361f8ee8f8c19e00d6fcac70164b6e584b2f4ea890ae5b643ca03a3fda6a972ecb50cecdb34964ad5995ddb854e80c6c396e876b3027b0511bf52e065b
|
@@ -38,18 +38,6 @@
|
|
38
38
|
(def string-pieces pieces
|
39
39
|
(joinstr "" pieces))
|
40
40
|
|
41
|
-
(def detect (f things)
|
42
|
-
; if 'things is a list, return the first item in the list for which 'f returns non-nil
|
43
|
-
; otherwise, return 'things if (f things) is non-nil
|
44
|
-
; otherwise, nil
|
45
|
-
(if (pair? things)
|
46
|
-
(let it (car things)
|
47
|
-
(or
|
48
|
-
(and (f it) it)
|
49
|
-
(detect f (cdr things))))
|
50
|
-
(f things)
|
51
|
-
things))
|
52
|
-
|
53
41
|
(def collect (f things)
|
54
42
|
; if 'things is a list, return all the items in the list for which 'f returns non-nil
|
55
43
|
; otherwise, return 'things if (f things) is non-nil
|
@@ -200,8 +188,33 @@
|
|
200
188
|
; the given args1 already applied
|
201
189
|
; arguments to the new function are whatever arguments remain
|
202
190
|
; for the old function
|
203
|
-
(fn
|
204
|
-
(apply func
|
191
|
+
(fn args
|
192
|
+
(apply func
|
193
|
+
(joinlists args1
|
194
|
+
args))))
|
195
|
+
|
196
|
+
(def detect (f things)
|
197
|
+
; if 'f is a function,
|
198
|
+
; if 'things is a list, return the first item in the list for which 'f returns non-nil
|
199
|
+
; otherwise, return 'things if (f things) is non-nil
|
200
|
+
; otherwise, nil
|
201
|
+
; if 'f is not a function, self-invoke with a function checking for equality with f
|
202
|
+
;
|
203
|
+
; WARNING: if the detected thing is nil, returns t instead. A return value of nil
|
204
|
+
; means the thing was not found ; non-nil means the thing was found, including when
|
205
|
+
; the found thing is itself nil.
|
206
|
+
(if (isa 'fn f)
|
207
|
+
(rfnwith d (items things)
|
208
|
+
(if (pair? items)
|
209
|
+
(let it (car items)
|
210
|
+
(or
|
211
|
+
(and (f it)
|
212
|
+
(or it t))
|
213
|
+
(d:cdr items)))
|
214
|
+
(f items)
|
215
|
+
items))
|
216
|
+
(detect (curry eq? f)
|
217
|
+
things)))
|
205
218
|
|
206
219
|
(def tuples (n things)
|
207
220
|
;; split things into a list of lists each n long
|
@@ -1,20 +1,22 @@
|
|
1
1
|
(examples-for date
|
2
|
-
("creates a single date"
|
3
|
-
("navigates to next day"
|
4
|
-
("navigates to previous day"
|
5
|
-
("navigates to previous year"
|
6
|
-
("navigates to next year"
|
7
|
-
("navigates to previous month"
|
8
|
-
("navigates to next month"
|
9
|
-
("jumps a year to previous month"
|
10
|
-
("navigates to previous week"
|
11
|
-
("navigates to next week"
|
12
|
-
("navigates to year start"
|
13
|
-
("navigates to year end"
|
14
|
-
("navigates to month start"
|
15
|
-
("navigates to month end"
|
16
|
-
("navigates to week start"
|
17
|
-
("navigates to week
|
2
|
+
("creates a single date" (to-string (date 1965 6 8)) "1965-06-08" )
|
3
|
+
("navigates to next day" (let d (date 2004 3 11) (to-string d.tomorrow)) "2004-03-12" )
|
4
|
+
("navigates to previous day" (let d (date 2006 6 22) (to-string d.yesterday)) "2006-06-21" )
|
5
|
+
("navigates to previous year" (let d (date 1971 12 18) (to-string d.last-year)) "1970-12-18" )
|
6
|
+
("navigates to next year" (let d (date 1974 1 11) (to-string d.next-year)) "1975-01-11" )
|
7
|
+
("navigates to previous month" (let d (date 1971 12 18) (to-string d.last-month)) "1971-11-18" )
|
8
|
+
("navigates to next month" (let d (date 1974 1 11) (to-string d.next-month)) "1974-02-11" )
|
9
|
+
("jumps a year to previous month" (let d (date 1974 1 11) (to-string d.last-month)) "1973-12-11" )
|
10
|
+
("navigates to previous week" (let d (date 2008 2 16) (to-string d.last-week)) "2008-02-09" )
|
11
|
+
("navigates to next week" (let d (date 1972 11 13) (to-string d.next-week)) "1972-11-20" )
|
12
|
+
("navigates to year start" (let d (date 1972 11 13) (to-string d.beginning-of-year)) "1972-01-01" )
|
13
|
+
("navigates to year end" (let d (date 1972 11 13) (to-string d.end-of-year)) "1972-12-31" )
|
14
|
+
("navigates to month start" (let d (date 1971 11 18) (to-string d.beginning-of-month)) "1971-11-01" )
|
15
|
+
("navigates to month end" (let d (date 1971 11 18) (to-string d.end-of-month)) "1971-11-30" )
|
16
|
+
("navigates to week start" (let d (date 2015 11 6) (to-string d.beginning-of-week)) "2015-11-02" )
|
17
|
+
("navigates to week start from sun" (let d (date 2015 11 1) (to-string d.beginning-of-week)) "2015-10-26" )
|
18
|
+
("navigates to week end from sun" (let d (date 2015 11 1) (to-string d.end-of-week)) "2015-11-01" )
|
19
|
+
("navigates to week end" (let d (date 2015 11 6) (to-string d.end-of-week)) "2015-11-08" )
|
18
20
|
|
19
21
|
("can act as hash key"
|
20
22
|
(with (h {} d (date 2015 11 8))
|
@@ -9,10 +9,13 @@
|
|
9
9
|
(list "foo" "bar" "xx" "pp"))
|
10
10
|
nil)
|
11
11
|
|
12
|
-
|
13
|
-
("returns nil if nil is the matching item"
|
12
|
+
("returns t if nil is the matching item (warning: anomalous behaviour)"
|
14
13
|
(detect no (list "foo" "bar" nil "pp"))
|
15
|
-
|
14
|
+
t)
|
15
|
+
|
16
|
+
("finds first non-nil item using x1"
|
17
|
+
(detect x1 (list nil nil "foo" "bar" nil "pp"))
|
18
|
+
"foo")
|
16
19
|
|
17
20
|
("returns item if it's an atom and matches"
|
18
21
|
(detect (fn (x) (eq? (len x) 2)) "zz")
|
@@ -21,4 +24,24 @@
|
|
21
24
|
("returns nil if it's an atom and doesn't match"
|
22
25
|
(detect (fn (x) (eq? (len x) 20))
|
23
26
|
"zz")
|
27
|
+
nil)
|
28
|
+
|
29
|
+
("nil for nil"
|
30
|
+
(detect nil nil)
|
31
|
+
nil)
|
32
|
+
|
33
|
+
("true for nil in list containing nil"
|
34
|
+
(detect nil '(1 2 nil 3 4))
|
35
|
+
t)
|
36
|
+
|
37
|
+
("nil for nil in list not containing nil"
|
38
|
+
(detect nil '(1 2 3 4 5))
|
39
|
+
nil)
|
40
|
+
|
41
|
+
("true for 42 in list containing 42"
|
42
|
+
(detect 42 '(1 2 nil 3 42 4))
|
43
|
+
42)
|
44
|
+
|
45
|
+
("nil for 42 in list not containing 42"
|
46
|
+
(detect 42 '(1 2 nil 3 (a b c) 4))
|
24
47
|
nil))
|
@@ -9,6 +9,44 @@
|
|
9
9
|
(cons (hash-keys h) (mapx (hash-keys h) k h.,k)))
|
10
10
|
((a "b" 3 b) 99 2 "foo" 98)))
|
11
11
|
|
12
|
+
(examples-for hash-keys
|
13
|
+
("returns nil for a number" (hash-keys 1) nil)
|
14
|
+
("returns nil for nil" (hash-keys nil) nil)
|
15
|
+
("returns nil for a string" (hash-keys "hello") nil)
|
16
|
+
("returns nil for a symbol" (hash-keys 'lipstick) nil)
|
17
|
+
|
18
|
+
("returns date operations"
|
19
|
+
(hash-keys (date 2015 11 18))
|
20
|
+
(beginning_of_month
|
21
|
+
beginning_of_week
|
22
|
+
beginning_of_year
|
23
|
+
day
|
24
|
+
end_of_month
|
25
|
+
end_of_week
|
26
|
+
end_of_year
|
27
|
+
friday?
|
28
|
+
last_month
|
29
|
+
last_week
|
30
|
+
last_year
|
31
|
+
monday?
|
32
|
+
month
|
33
|
+
next_month
|
34
|
+
next_week
|
35
|
+
next_year
|
36
|
+
saturday?
|
37
|
+
sunday?
|
38
|
+
thursday?
|
39
|
+
tomorrow
|
40
|
+
tuesday?
|
41
|
+
wednesday?
|
42
|
+
week_day
|
43
|
+
year
|
44
|
+
yesterday))
|
45
|
+
|
46
|
+
("returns keys of a given hash"
|
47
|
+
(hash-keys {a 1 b 2 c { x 99 y 98 z 97 }})
|
48
|
+
(a b c)))
|
49
|
+
|
12
50
|
(examples-for hash-key?
|
13
51
|
("detects key presence"
|
14
52
|
(hash-key? { foo 1 bar 2 } 'foo)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
(examples-for include?
|
2
|
+
("nil for nil"
|
3
|
+
(include? nil nil)
|
4
|
+
nil)
|
5
|
+
|
6
|
+
("true for nil in list containing nil"
|
7
|
+
(include? nil '(1 2 nil 3 4))
|
8
|
+
t)
|
9
|
+
|
10
|
+
("nil for nil in list not containing nil"
|
11
|
+
(include? nil '(1 2 3 4 5))
|
12
|
+
nil)
|
13
|
+
|
14
|
+
("true for 42 in list containing 42"
|
15
|
+
(include? 42 '(1 2 nil 3 42 4))
|
16
|
+
42)
|
17
|
+
|
18
|
+
("nil for 42 in list not containing 42"
|
19
|
+
(include? 42 '(1 2 nil 3 (a b c) 4))
|
20
|
+
nil))
|
data/lib/nydp/builtin/hash.rb
CHANGED
@@ -65,11 +65,12 @@ class Nydp::Builtin::HashKeys
|
|
65
65
|
def initialize ns ; @ns = ns; end
|
66
66
|
def builtin_invoke vm, args
|
67
67
|
hash = args.car
|
68
|
-
|
69
|
-
when Nydp::Hash
|
68
|
+
if hash.is_a? Nydp::Hash
|
70
69
|
vm.push_arg Nydp::Pair.from_list hash.keys
|
70
|
+
elsif hash.respond_to?(:keys)
|
71
|
+
vm.push_arg r2n(hash.keys.to_a.sort, ns)
|
71
72
|
else
|
72
|
-
vm.push_arg
|
73
|
+
vm.push_arg Nydp.NIL
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
data/lib/nydp/date.rb
CHANGED
@@ -58,8 +58,8 @@ module Nydp
|
|
58
58
|
|
59
59
|
def last_week y, m, d, w ; ruby_date - 7 ; end
|
60
60
|
def next_week y, m, d, w ; ruby_date + 7 ; end
|
61
|
-
def beginning_of_week y, m, d, w ; ruby_date
|
62
|
-
def end_of_week y, m, d, w ; ruby_date + 7 - w
|
61
|
+
def beginning_of_week y, m, d, w ; ruby_date - ((w - 1) % 7) ; end
|
62
|
+
def end_of_week y, m, d, w ; ruby_date + ((7 - w) % 7) ; end
|
63
63
|
|
64
64
|
def yesterday y, m, d, w ; ruby_date - 1 ; end
|
65
65
|
def tomorrow y, m, d, w ; ruby_date + 1 ; end
|
@@ -68,7 +68,8 @@ module Nydp
|
|
68
68
|
class_eval "def #{n} * ; ruby_date.#{n} ; end"
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
71
|
+
def keys ; @@keys ; end
|
72
|
+
def dispatch key, y, m, d, w ; self.send(key, y, m, d, w) if keys.include?(key) ; end
|
72
73
|
|
73
74
|
def [] key
|
74
75
|
key = key.to_s.gsub(/-/, '_').to_sym
|
data/lib/nydp/truth.rb
CHANGED
@@ -11,7 +11,7 @@ module Nydp
|
|
11
11
|
def car ; self ; end
|
12
12
|
def cdr ; self ; end
|
13
13
|
def size ; 0 ; end
|
14
|
-
def is? other ;
|
14
|
+
def is? other ; other.class == self.class ; end
|
15
15
|
def isnt? other ; !is?(other) ; end
|
16
16
|
def to_s ; "" ; end
|
17
17
|
def + other ; other ; end
|
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.7
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/lisp/core-070-prefix-list.nydp
|
97
97
|
- lib/lisp/core-080-pretty-print.nydp
|
98
98
|
- lib/lisp/core-090-hook.nydp
|
99
|
+
- lib/lisp/core-100-utils.nydp
|
99
100
|
- lib/lisp/tests/add-hook-examples.nydp
|
100
101
|
- lib/lisp/tests/best-examples.nydp
|
101
102
|
- lib/lisp/tests/boot-tests.nydp
|
@@ -115,6 +116,7 @@ files:
|
|
115
116
|
- lib/lisp/tests/explain-mac-examples.nydp
|
116
117
|
- lib/lisp/tests/foundation-test.nydp
|
117
118
|
- lib/lisp/tests/hash-examples.nydp
|
119
|
+
- lib/lisp/tests/include-examples.nydp
|
118
120
|
- lib/lisp/tests/invocation-tests.nydp
|
119
121
|
- lib/lisp/tests/isa-examples.nydp
|
120
122
|
- lib/lisp/tests/len-examples.nydp
|