nydp 0.1.1 → 0.1.2

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: 031f54326dfa57ae2a067c931bd600bd9e2cc6c0
4
- data.tar.gz: aa49dab4d81173e02e968958028c1cad2948079c
3
+ metadata.gz: 63983bd000bf898d3987e7878f25a16e0be94924
4
+ data.tar.gz: ec47cf4bf570c09a63d17a53008fe92671460cbc
5
5
  SHA512:
6
- metadata.gz: e263b9ce4dff11cd6ac7e7d7ef5787ad553807eb1f2048bbd357973ddbbc910feaaf7c340c0bb8347f31d90e07c4e5b23af3992ed31cb8e61edef8e878c480b5
7
- data.tar.gz: 0966de059bcf3658fe137c9a436bf817d84b5bc4ad443b8afd14e22fbecc7e392c23732d6a5a5db8862345bd5ba70b7ae09e87e67e0a910484792e1882e27eda
6
+ metadata.gz: 02e72f25772989690a4ba44cee9e5f054528d0d2202779674fd232fab1806bf24d2840bd0e6e1ce289875b6aac739cfdd94e7e4da86513d1020cecce1cc7ac62
7
+ data.tar.gz: 680159117248665c00a5166bf6d9e1a58247170d28d532215529f35f7a562add5464db10ee1bcbc617a38ee7eb3402777c484f27b388834c9da0aef68189947c
@@ -1,15 +1,35 @@
1
+ (def orf args
2
+ (cond args
3
+ (cond (car args)
4
+ (car args)
5
+ (apply orf
6
+ (cdr args)))))
7
+
1
8
  (mac unless (arg . body)
2
9
  `(if (no ,arg) (do ,@body)))
3
10
 
4
- (def expand-colon-syntax (first rest)
5
- (if (no rest)
6
- `(apply ,first args)
7
- `(,first ,(expand-colon-syntax (car rest) (cdr rest)))))
11
+ (def expand-colon-syntax (names)
12
+ (if (no (cdr names))
13
+ `(apply ,(car names) args)
14
+ `(,(car names) ,(expand-colon-syntax (cdr names)))))
15
+
16
+ (def default-colon-syntax (names)
17
+ `(fn args ,(expand-colon-syntax names)))
18
+
19
+ (assign colon-syntax-overrides (hash))
20
+
21
+ (mac def-colon-syntax (name var . body)
22
+ `(hash-set colon-syntax-overrides
23
+ ',name
24
+ (fn (,var) ,@body)))
25
+
26
+ (def-colon-syntax || names
27
+ (error "Irregular ': syntax: got ~(inspect names) : not prefix-syntax : in ~(joinstr ":" names)"))
8
28
 
9
- (mac colon-syntax args
10
- (if (eq? (car args) '||)
11
- (error "Irregular ': syntax: got ~(inspect args) : not prefix-syntax : in ~(joinstr ":" (cons pfx rest))")
12
- `(fn args ,(expand-colon-syntax (car args) (cdr args)))))
29
+ (mac colon-syntax names
30
+ ((orf (hash-get colon-syntax-overrides (car names))
31
+ default-colon-syntax)
32
+ names))
13
33
 
14
34
  (mac bang-syntax (pfx . rest)
15
35
  (if (no (eq? pfx '||))
@@ -151,25 +151,26 @@
151
151
  (def dox-show-info (name what texts args src)
152
152
  ; show the given dox info
153
153
  ; 'info arg is a dox object from the dox system
154
- (p)
155
- (cond (eq? what 'mac) (p "Macro : ~name" ))
156
- (cond (eq? what 'def) (p "Function : ~name" ))
157
- (p "args : ~(inspect args)")
158
- (p (joinstr "\n" texts))
159
- (p "")
160
- (p "source")
161
- (p "======")
162
- (p (dox-show-src src))
163
- (p))
154
+ "~(if (eq? what 'mac) "Macro"
155
+ (eq? what 'def) "Function"
156
+ what) : ~name
157
+
158
+ args : ~(inspect args)
159
+
160
+ ~(joinstr "\n" texts)
161
+
162
+ source
163
+ ======
164
+ ~(dox-show-src src)
165
+ ")
164
166
 
165
167
  (mac dox (name)
166
168
  ; show dox for the given name
167
169
  `(let infos (dox-lookup ',name)
168
- (if (or (no infos)
169
- (eq? (len infos) 0))
170
- (p "No documentation for " ',name)
170
+ (if (no infos)
171
+ (p "No documentation for" ',name)
171
172
  (each info infos
172
- (apply dox-show-info info)))))
173
+ (p:apply dox-show-info info)))))
173
174
 
174
175
  (def proper? (list)
175
176
  ; t if this is a proper list (last cdr is nil)
@@ -190,3 +191,24 @@
190
191
  (if (> n 0)
191
192
  (nthcdr (- n 1) (cdr things))
192
193
  things))
194
+
195
+ (def joinlists (things . more-thingses)
196
+ ; return a new list which is the concatenation of all the given lists
197
+ ; 'things is a list
198
+ ; 'more-thingses is a list of lists
199
+ ; call like this: (joinlists '(a b c) '(x y z) '(1 2 3))
200
+ (if things
201
+ (cons (car things)
202
+ (apply joinlists
203
+ (cdr things)
204
+ more-thingses))
205
+ more-thingses
206
+ (apply joinlists more-thingses)))
207
+
208
+ (def curry (func . args1)
209
+ ; return a new function which is the original function with
210
+ ; the given args1 already applied
211
+ ; arguments to the new function are whatever arguments remain
212
+ ; for the old function
213
+ (fn args2
214
+ (apply func (joinlists args1 args2))))
@@ -21,7 +21,7 @@
21
21
  (if (eq? thing '||)
22
22
  ""
23
23
  (isa 'string thing)
24
- (pp/escape-string-literal thing)
24
+ "\"~(pp/escape-string-literal thing)\""
25
25
  (inspect thing)))
26
26
 
27
27
  (mac pp/def (name args . body)
@@ -47,6 +47,7 @@
47
47
  (pp/def unquote-splicing (form indent) ",@~(pp/main (cadr form) indent)")
48
48
  (pp/def comment (form indent) ";~(cadr form)\n")
49
49
  (pp/def prefix-list (form indent) "~(cadr form)~(pp (caddr form))")
50
+ (pp/def brace-list (form indent) "{~(pp/inline (cdr form) indent)}")
50
51
 
51
52
  (pp/syntax
52
53
  colon-syntax ":"
@@ -0,0 +1,24 @@
1
+ (def chicken-korma (a b c d e)
2
+ (list a b c d e))
3
+
4
+ (register-test
5
+ '(suite "Curry Tests"
6
+ ("zero-params"
7
+ (let ck0 (curry chicken-korma)
8
+ (ck0 1 2 3 4 5))
9
+ (1 2 3 4 5))
10
+
11
+ ("one param"
12
+ (let ck0 (curry chicken-korma 'x)
13
+ (ck0 1 2 3 4))
14
+ (x 1 2 3 4))
15
+
16
+ ("two params"
17
+ (let ck0 (curry chicken-korma 'x 'y)
18
+ (ck0 1 2 3))
19
+ (x y 1 2 3))
20
+
21
+ ("three params"
22
+ (let ck0 (curry chicken-korma 'x 'y 'z)
23
+ (ck0 1 2))
24
+ (x y z 1 2))))
@@ -40,6 +40,26 @@
40
40
  (that)))
41
41
  (("hello" "more details" "very rigourous") ((this) (that)))))
42
42
 
43
+ (suite "dox-show-info"
44
+ ("shows each item"
45
+ (dox-show-info "bingo"
46
+ 'def
47
+ '("there was a farmer had a dog" "and Bingo was his name-o")
48
+ '(count)
49
+ '(def bingo (count) (times count (bark))))
50
+ "Function : bingo
51
+
52
+ args : (count)
53
+
54
+ there was a farmer had a dog
55
+ and Bingo was his name-o
56
+
57
+ source
58
+ ======
59
+ (def bingo (count)
60
+ (times count (bark)))
61
+ "))
62
+
43
63
  (suite "mac"
44
64
  ("a documented macro"
45
65
  (dox-lookup 'this-is-a-well-documented-macro)
@@ -38,6 +38,18 @@
38
38
 
39
39
 
40
40
  (suite "type-of"
41
+ ("returns 'fn for builtin function"
42
+ (type-of car)
43
+ fn)
44
+
45
+ ("returns 'fn for nydp-defined function"
46
+ (type-of register-test)
47
+ fn)
48
+
49
+ ("returns 'fn for inline function"
50
+ (type-of (fn (x) (p x)))
51
+ fn)
52
+
41
53
  ("returns 'string"
42
54
  (type-of "foobar")
43
55
  string)
@@ -1,5 +1,14 @@
1
1
  (register-test
2
2
  '(suite "List Tests"
3
+ (suite "joinlists"
4
+ ("joins one list to another"
5
+ (joinlists '(a b c) '(x y z))
6
+ (a b c x y z))
7
+
8
+ ("joins three lists"
9
+ (joinlists '(a b c) '(x y z) '(1 2 3))
10
+ (a b c x y z 1 2 3)))
11
+
3
12
  (suite "firstn"
4
13
  ("returns no items for n = 0"
5
14
  (firstn 0 '(a b c d))
@@ -8,6 +8,10 @@
8
8
  (pp '(def pp (form) (pp/main form 0)))
9
9
  "(def pp (form)\n (pp/main form 0))")
10
10
 
11
+ ("something with a plain string literal"
12
+ (pp '(def yoohoo (it) (wrangle "foobar" it)))
13
+ "(def yoohoo (it)\n (wrangle \"foobar\" it))")
14
+
11
15
  ("combined with dox system"
12
16
  (pp:dox-src 'pp/find-breaks)
13
17
  "(def pp/find-breaks (form)
@@ -22,4 +26,6 @@
22
26
  (pp '(string-pieces "hello " (bang-syntax || (dot-syntax x y (ampersand-syntax foo bar))) " and welcome to " (prefix-list "%%" (a b c d)) " and friends!"))
23
27
  "\"hello ~~!x.y.foo&bar and welcome to ~~%%(a b c d) and friends!\"")
24
28
 
25
- ))
29
+ ("brace list"
30
+ (pp '(&x {a 1 b "two" c 'three d ,four e (sub invocation) f {sub brace list} }))
31
+ "(&x {a 1 b \"two\" c 'three d ,four e (sub invocation) f {sub brace list}})")))
@@ -1,5 +1,18 @@
1
1
  (register-test
2
2
  '(suite "syntax tests"
3
+ (suite "colon-syntax"
4
+ ("expands to sequential function application"
5
+ (pre-compile 'a:b)
6
+ (fn args (a (apply b args))))
7
+
8
+ ("example with car:cdr"
9
+ (car:cdr '(a b c))
10
+ b)
11
+
12
+ ("dislikes no-prefix"
13
+ (on-err err (pre-compile '(:foo 1 2 3)))
14
+ "(\"Irregular ': syntax: got (|| foo) : not prefix-syntax : in :foo\")"))
15
+
3
16
  (suite "lambda shortcut"
4
17
  ("one argument"
5
18
  (map λa(len a.name)
data/lib/nydp/builtin.rb CHANGED
@@ -40,8 +40,9 @@ module Nydp::Builtin
40
40
  cname
41
41
  end
42
42
 
43
- def inspect ; "builtin/#{name}" ; end
44
- def to_s ; name ; end
43
+ def inspect ; "builtin/#{name}" ; end
44
+ def to_s ; name ; end
45
+ def nydp_type ; "fn" ; end
45
46
  end
46
47
  end
47
48
 
data/lib/nydp/closure.rb CHANGED
@@ -22,6 +22,7 @@ module Nydp
22
22
  ifn.invoke vm, context, arg_values
23
23
  end
24
24
 
25
+ def nydp_type ; "fn" ; end
25
26
  def to_s
26
27
  "(closure #{context.inspect} : #{ifn.to_s})"
27
28
  end
@@ -82,7 +82,8 @@ module Nydp
82
82
  vm.push_arg Closure.new(self, vm.peek_context)
83
83
  end
84
84
 
85
- def inspect; to_s; end
85
+ def nydp_type ; "fn" ; end
86
+ def inspect ; to_s ; end
86
87
  def to_s
87
88
  "(fn #{arg_names.inspect} #{body.map { |b| b.inspect}.join(' ')})"
88
89
  end
data/lib/nydp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nydp
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/nydp.gemspec CHANGED
@@ -19,9 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
-
22
+ spec.add_development_dependency "rake", "~> 10.0"
24
23
  spec.add_development_dependency 'rspec', '~> 2.9'
25
24
  spec.add_development_dependency 'rspec_numbering_formatter'
26
-
27
25
  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.1
4
+ version: 0.1.2
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-10-18 00:00:00.000000000 Z
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +96,7 @@ files:
96
96
  - lib/lisp/core-080-pretty-print.nydp
97
97
  - lib/lisp/tests/boot-tests.nydp
98
98
  - lib/lisp/tests/builtin-tests.nydp
99
+ - lib/lisp/tests/curry-tests.nydp
99
100
  - lib/lisp/tests/dox-tests.nydp
100
101
  - lib/lisp/tests/dynamic-scope-test.nydp
101
102
  - lib/lisp/tests/each-tests.nydp