nydp 0.1.7.1 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db35faecd269e526a42734f65107c5e01225e1d7
4
- data.tar.gz: bf41a00b1da780edade899c64c60448af7e3bfed
3
+ metadata.gz: 464c1f232ccc2d83cad5b5141745c64b46f44456
4
+ data.tar.gz: 6197cc9ee681187c2bd2ace20395f1c2a414df1f
5
5
  SHA512:
6
- metadata.gz: 8854d5d5072ddef9cc13b9990352ba1e14651304fc4e81042181504b0e9f352cc5aee08f91c655decea3c0019317325bb8c3b9ab1118f02712eeb7ff54b5dd74
7
- data.tar.gz: 9e47f43feec791386e44b183dd16bdf254238bd507977b42e39771d3a0f55aea30dd42fc6db48544e65010d430c376e09e0607a680132756d572e842092d1de3
6
+ metadata.gz: 9b1e87a79e8531565cedd6f9eaebd3bf1af59782ea383e3426ee054ae9c2c819881dde4123620f683690cbbbef164b1477df93a323de8dac817d39355aaeccf7
7
+ data.tar.gz: 9d9a93990ebcd01d4305ef2458b02acfbf338263f3ee5ba4ab0f223f1115db845cc91220e410cf1bbb535a84c59f3eea66e8f8856e04d0919d9afb4ada53893a
@@ -2,17 +2,20 @@
2
2
  ;;
3
3
  ;; Acknowledgements to Paul Graham, Robert Morris, and their ancestor programmers.
4
4
  ;; nydp's main inspiration is arc, and many nydp features (including, but not limited
5
- ;; to, 'do, 'rfn, 'loop, 'for) were directly inspired by (aka stolen from) arc.arc
6
- ;;
5
+ ;; to, 'do, 'rfn, 'loop, 'for) were directly inspired by (aka stolen from) arc.arc. See
6
+ ;; README.md however for some significant differences
7
7
 
8
8
  (assign list (fn args args))
9
9
  (assign caar (fn (arg) (car (car arg))))
10
10
  (assign cadr (fn (arg) (car (cdr arg))))
11
11
  (assign cdar (fn (arg) (cdr (car arg))))
12
12
  (assign cddr (fn (arg) (cdr (cdr arg))))
13
- (assign cadar (fn (arg) (car (cdr (car arg)))))
14
- (assign caddr (fn (arg) (car (cdr (cdr arg)))))
15
- (assign cdddr (fn (arg) (cdr (cdr (cdr arg)))))
16
- (assign cadddr (fn (arg) (car (cdr (cdr (cdr arg))))))
13
+ (assign cadar (fn (arg) (car (cdar arg))))
14
+ (assign caddr (fn (arg) (car (cddr arg))))
15
+ (assign cdddr (fn (arg) (cdr (cddr arg))))
16
+ (assign cadddr (fn (arg) (car (cdddr arg))))
17
17
  (assign no (fn (arg) (cond arg nil t)))
18
18
  (assign just (fn (arg) arg))
19
+ (assign isa (fn (type obj) (eq? (type-of obj) type)))
20
+ (assign pair? (fn (arg) (isa 'pair arg)))
21
+ (assign hash? (fn (arg) (isa 'hash arg)))
@@ -168,8 +168,6 @@
168
168
  ,(build-hash-get-key:car rnames)
169
169
  ,value-expr)))
170
170
 
171
- (def isa (type obj) (eq? (type-of obj) type))
172
-
173
171
  (mac = (name value)
174
172
  (if (isa 'symbol name)
175
173
  `(assign ,name ,value)
@@ -78,10 +78,17 @@
78
78
  (and (isa 'pair things)
79
79
  (eq? (car things) obj)))
80
80
 
81
+ (def list-length (things)
82
+ (if (no things) 0
83
+ (atom? things) 1
84
+ (+ 1 (list-length:cdr things))))
85
+
81
86
  (def len (xs)
82
- (if (pair? xs) (+ 1 (len (cdr xs)))
87
+ (if (no xs) 0
88
+ (pair? xs) (list-length xs)
83
89
  (string? xs) (string-length xs)
84
- 0))
90
+ (hash? xs) (list-length:hash-keys xs)
91
+ nil))
85
92
 
86
93
  (assign dynamics (hash))
87
94
 
@@ -112,7 +119,18 @@
112
119
  `(ensuring (fn () ,protection)
113
120
  (fn () ,@body)))
114
121
 
122
+ (mac while (test . body)
123
+ ; tests 'test, as long as 'test is non-nil,
124
+ ; repeatedly executes 'body
125
+ (w/uniq (rfname pred)
126
+ `(rfnwith ,rfname (,pred ,test)
127
+ (when ,pred
128
+ ,@body
129
+ (,rfname ,test)))))
130
+
115
131
  (mac loop (start test update . body)
132
+ ; execute 'start. then for as long as 'test returns non-nil,
133
+ ; execute 'body and 'update
116
134
  (w/uniq (gfn gparm)
117
135
  `(do ,start
118
136
  ((rfn ,gfn (,gparm)
@@ -129,7 +147,21 @@
129
147
  (mac mapx (things x expr)
130
148
  `(map (fn (,x) ,expr) ,things))
131
149
 
132
- (def empty? (things) (eq? (len things) 0))
150
+ (def atom? (thing)
151
+ (and thing
152
+ (!pair? thing)
153
+ (!hash? thing)))
154
+
155
+ (def empty? (things)
156
+ ; t if it's nil or an empty list, string, or hash
157
+ ; nil otherwise
158
+ (let l (len things)
159
+ (and l (eq? l 0))))
160
+
161
+ (def present? (thing)
162
+ ; t if it's a symbol or number, or a non-empty string, list or hash
163
+ ; nil otherwise
164
+ (!empty? thing))
133
165
 
134
166
  (mac each (var things code)
135
167
  ; repeatedly assigns an element of 'things to 'var,
@@ -75,7 +75,7 @@
75
75
 
76
76
  (def pp/find-breaks/mac (form)
77
77
  (if (eq? (dox-what-is? (car form)) 'mac)
78
- (let arg-count (+ 1 (len (dox-arg-names (car form))))
78
+ (let arg-count (list-length:dox-arg-names:car form)
79
79
  (cons (firstn arg-count form)
80
80
  (map list (nthcdr arg-count form))))))
81
81
 
@@ -0,0 +1,31 @@
1
+ (examples-for empty?
2
+ ("nonzero" (empty? "foo-bar") nil)
3
+ ("zero" (empty? "") t)
4
+ ("blank" (empty? " ") nil)
5
+ ("nil is t" (empty? nil) t)
6
+ ("sym is nil" (empty? 'abc) nil)
7
+ ("number is nil" (empty? 234) nil)
8
+
9
+ ("nil for proper list" (empty? '(a b)) nil)
10
+ ("nil for improper list" (empty? '(a b c . d)) nil)
11
+ ("t for empty hash" (empty? { }) t)
12
+
13
+ ("nil for hash with keys"
14
+ (empty? { a 11 b 22 c 23 d nil e { nested t counted nil } })
15
+ nil))
16
+
17
+ (examples-for present?
18
+ ("nonzero" (present? "foo-bar") t)
19
+ ("zero" (present? "") nil)
20
+ ("blank" (present? " ") t)
21
+ ("nil is t" (present? nil) nil)
22
+ ("sym is t" (present? 'abc) t)
23
+ ("number is t" (present? 234) t)
24
+
25
+ ("t for proper list" (present? '(a b)) t)
26
+ ("t for improper list" (present? '(a b c . d)) t)
27
+ ("nil for empty hash" (present? { }) nil)
28
+
29
+ ("t for hash with keys"
30
+ (present? { a 11 b 22 c 23 d nil e { nested t counted nil } })
31
+ t))
@@ -1,3 +1,10 @@
1
+ (examples-for hash?
2
+ ("nil for a cons" (hash? '(1 a 2 b 3 c)) nil)
3
+ ("nil for a number" (hash? 1) nil)
4
+ ("nil for a string" (hash? "werwe") nil)
5
+ (" t for a hash" (hash? {a 1 b 2}) t )
6
+ ("nil for a symbol" (hash? 'foo) nil))
7
+
1
8
  (examples-for hash-merge
2
9
  ("merge with symbol keys"
3
10
  (let h (hash-merge { a 1 b 2 c 3 } { a 99 c 98 d 97 })
@@ -1,11 +1,15 @@
1
1
  (examples-for len
2
- ("nonzero" (len "foo-bar") 7)
3
- ("zero" (len "") 0)
2
+ ("nonzero" (len "foo-bar") 7)
3
+ ("zero" (len "") 0)
4
+ ("nil is zero" (len nil) 0)
5
+ ("sym is nil" (len 'abc) nil)
6
+ ("number is nil" (len 234) nil)
4
7
 
5
- ("ignores backslash-escaped interpolation symbol"
6
- (len "hello \~world")
7
- 12)
8
+ ("ignores backslash-escaped interpolation symbol" (len "hello \~world") 12)
9
+ ("returns length of proper list" (len '(a b)) 2)
10
+ ("counts last item of improper list" (len '(a b c . d)) 4)
11
+ ("counts keys of empty hash" (len { }) 0)
8
12
 
9
- ("len returns length of proper list"
10
- (len (cons "a" (cons "b" nil)))
11
- 2))
13
+ ("counts keys of hash"
14
+ (len { a 11 b 22 c 23 d nil e { nested t counted nil } })
15
+ 5))
@@ -1,3 +1,10 @@
1
+ (examples-for pair?
2
+ (" t for a cons" (pair? '(1 a 2 b 3 c)) t)
3
+ ("nil for a number" (pair? 1) nil)
4
+ ("nil for a string" (pair? "werwe") nil)
5
+ ("nil for a hash" (pair? {a 1 b 2}) nil)
6
+ ("nil for a symbol" (pair? 'foo) nil))
7
+
1
8
  (examples-for pairs
2
9
  ("'pair breaks a list into pairs"
3
10
  (pairs '(1 a 2 b 3 c))
@@ -1,7 +1,15 @@
1
1
  (examples-for string-split
2
2
  ("splits a string using given expression"
3
3
  (string-split "a and b and c and d" " and ")
4
- ("a" "b" "c" "d")))
4
+ ("a" "b" "c" "d"))
5
+
6
+ ("returns empty leading, internal, and trailing segments"
7
+ (string-split "and" "and")
8
+ ("" ""))
9
+
10
+ ("returns empty leading, internal, and trailing segments"
11
+ (string-split "andandand" "and")
12
+ ("" "" "" "")))
5
13
 
6
14
  (examples-for string-replace
7
15
  ("replaces parts of a string with the given replacement"
@@ -6,14 +6,4 @@ module Nydp::Builtin
6
6
  vm.push_arg Nydp::Pair.new(args.car, args.cdr.car)
7
7
  end
8
8
  end
9
-
10
- class IsPair
11
- include Nydp::Helper, Nydp::Builtin::Base
12
-
13
- def builtin_invoke vm, args
14
- arg = args.car
15
- result = pair?(arg) ? Nydp.T : Nydp.NIL
16
- vm.push_arg result
17
- end
18
- end
19
9
  end
@@ -4,7 +4,7 @@ class Nydp::Builtin::StringSplit
4
4
  def builtin_invoke vm, args
5
5
  target = args.car.to_s
6
6
  separator = args.cdr.car.to_s
7
- result = target.split separator
7
+ result = target.split separator, -1
8
8
  list = result.map { |s| Nydp::StringAtom.new s }
9
9
 
10
10
  vm.push_arg Nydp::Pair.from_list list
data/lib/nydp/core.rb CHANGED
@@ -60,7 +60,6 @@ module Nydp
60
60
  Symbol.mk("thread-locals" , ns).assign(Nydp::Builtin::ThreadLocals.new)
61
61
  Symbol.mk("type-of", ns).assign(Nydp::Builtin::TypeOf.new(ns))
62
62
  Symbol.mk(:"eq?", ns).assign(Nydp::Builtin::IsEqual.new)
63
- Symbol.mk(:"pair?", ns).assign(Nydp::Builtin::IsPair.new)
64
63
  Symbol.mk(:"cdr-set", ns).assign(Nydp::Builtin::CdrSet.new)
65
64
  Symbol.mk(:"hash-get", ns).assign(Nydp::Builtin::HashGet.new ns)
66
65
  Symbol.mk(:"hash-set", ns).assign(Nydp::Builtin::HashSet.new)
data/lib/nydp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nydp
2
- VERSION = "0.1.7.1"
2
+ VERSION = "0.1.8"
3
3
  end
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.7.1
4
+ version: 0.1.8
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-15 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,6 +112,7 @@ files:
112
112
  - lib/lisp/tests/dox-tests.nydp
113
113
  - lib/lisp/tests/dynamic-scope-test.nydp
114
114
  - lib/lisp/tests/each-tests.nydp
115
+ - lib/lisp/tests/empty-examples.nydp
115
116
  - lib/lisp/tests/error-tests.nydp
116
117
  - lib/lisp/tests/explain-mac-examples.nydp
117
118
  - lib/lisp/tests/foundation-test.nydp