nydp 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -0
  3. data/lib/lisp/core-015-documentation.nydp +12 -7
  4. data/lib/lisp/core-017-builtin-dox.nydp +13 -12
  5. data/lib/lisp/core-030-syntax.nydp +24 -16
  6. data/lib/lisp/core-037-list-utils.nydp +0 -11
  7. data/lib/lisp/core-040-utils.nydp +11 -0
  8. data/lib/lisp/core-041-string-utils.nydp +1 -1
  9. data/lib/lisp/core-043-list-utils.nydp +6 -6
  10. data/lib/lisp/core-080-pretty-print.nydp +5 -0
  11. data/lib/lisp/core-090-hook.nydp +19 -7
  12. data/lib/lisp/core-120-settings.nydp +2 -2
  13. data/lib/lisp/core-130-validations.nydp +51 -0
  14. data/lib/lisp/core-900-benchmarking.nydp +59 -1
  15. data/lib/lisp/tests/multi-assign-examples.nydp +6 -0
  16. data/lib/lisp/tests/settings-examples.nydp +16 -0
  17. data/lib/lisp/tests/string-tests.nydp +4 -1
  18. data/lib/lisp/tests/to-integer-examples.nydp +16 -0
  19. data/lib/lisp/tests/validation-examples.nydp +15 -0
  20. data/lib/nydp.rb +4 -0
  21. data/lib/nydp/builtin/date.rb +6 -1
  22. data/lib/nydp/builtin/inspect.rb +1 -1
  23. data/lib/nydp/builtin/plus.rb +10 -2
  24. data/lib/nydp/builtin/random_string.rb +2 -2
  25. data/lib/nydp/builtin/ruby_wrap.rb +8 -5
  26. data/lib/nydp/builtin/string_match.rb +2 -2
  27. data/lib/nydp/builtin/string_pad_left.rb +1 -1
  28. data/lib/nydp/builtin/string_pad_right.rb +1 -1
  29. data/lib/nydp/builtin/string_replace.rb +1 -1
  30. data/lib/nydp/builtin/string_split.rb +1 -2
  31. data/lib/nydp/builtin/to_integer.rb +23 -0
  32. data/lib/nydp/builtin/to_string.rb +2 -9
  33. data/lib/nydp/core.rb +4 -2
  34. data/lib/nydp/core_ext.rb +13 -1
  35. data/lib/nydp/date.rb +1 -0
  36. data/lib/nydp/helper.rb +29 -7
  37. data/lib/nydp/pair.rb +8 -3
  38. data/lib/nydp/parser.rb +4 -5
  39. data/lib/nydp/truth.rb +2 -2
  40. data/lib/nydp/version.rb +1 -1
  41. data/lib/nydp/vm.rb +7 -0
  42. data/spec/embedded_spec.rb +12 -12
  43. data/spec/foreign_hash_spec.rb +2 -2
  44. data/spec/hash_non_hash_behaviour_spec.rb +7 -7
  45. data/spec/hash_spec.rb +2 -2
  46. data/spec/nydp_spec.rb +14 -2
  47. data/spec/parser_spec.rb +16 -16
  48. data/spec/rand_spec.rb +3 -3
  49. data/spec/spec_helper.rb +10 -1
  50. metadata +7 -2
@@ -1,3 +1,3 @@
1
1
  module Nydp
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -116,6 +116,13 @@ module Nydp
116
116
  end
117
117
  msg << "\n"
118
118
  msg << "\n"
119
+ msg << "\nargs stack"
120
+ msg << "\n================="
121
+ args.each_with_index do |args, ix|
122
+ msg << "\args##{ix} :\n#{args}"
123
+ end
124
+ msg << "\n"
125
+ msg << "\n"
119
126
  msg
120
127
  end
121
128
  end
@@ -27,29 +27,29 @@ describe Nydp::Parser do
27
27
  it "should parse empty string" do
28
28
  expected = pair_list([sym('string-pieces'), Nydp::StringFragmentCloseToken.new('','')])
29
29
  actual = parse_string ""
30
- expect(actual).to eq Nydp::StringAtom.new ''
30
+ expect(actual).to eq ''
31
31
  end
32
32
 
33
33
  it "should parse external text" do
34
34
  actual = parse_string "a fluffy bunny!"
35
- expect(actual) .to eq Nydp::StringAtom.new "a fluffy bunny!"
35
+ expect(actual) .to eq "a fluffy bunny!"
36
36
  expect(actual.inspect).to eq '"a fluffy bunny!"'
37
37
  end
38
38
 
39
39
  it "should parse a string delimited by eof" do
40
40
  expected = pair_list([sym('string-pieces'), Nydp::StringFragmentCloseToken.new('a fluffy bunny!','a fluffy bunny!')])
41
41
  actual = parse_string "a fluffy bunny!"
42
- expect(actual) .to eq Nydp::StringAtom.new "a fluffy bunny!"
42
+ expect(actual) .to eq "a fluffy bunny!"
43
43
  expect(actual.inspect).to eq '"a fluffy bunny!"'
44
44
  end
45
45
 
46
46
  it "should parse a string with embedded code, delimited by eof" do
47
47
  x1 = sym('string-pieces')
48
48
  x2 = Nydp::StringFragmentToken.new('a fluffy bunny! ','a fluffy bunny! ~')
49
- x2 = Nydp::StringAtom.new(x2.string)
49
+ x2 = x2.string
50
50
  x3 = sym('expr')
51
51
  x4 = Nydp::StringFragmentCloseToken.new(' a purple cow!',' a purple cow!')
52
- x4 = Nydp::StringAtom.new(x4.string)
52
+ x4 = x4.string
53
53
 
54
54
  expected = pair_list([x1,x2,x3,x4])
55
55
  actual = parse_string "a fluffy bunny! ~expr a purple cow!"
@@ -59,15 +59,15 @@ describe Nydp::Parser do
59
59
  it "should parse a string with embedded code containing a nested string, delimited by eof" do
60
60
  n1 = sym(:foo)
61
61
  n2 = sym(:bar)
62
- n3 = Nydp::StringAtom.new 'an embedded bunny :)'
62
+ n3 = 'an embedded bunny :)'
63
63
  n4 = sym(:zop)
64
64
 
65
65
  x1 = sym('string-pieces')
66
66
  x2 = Nydp::StringFragmentToken.new('a fluffy bunny! ','a fluffy bunny! ~')
67
- x2 = Nydp::StringAtom.new(x2.string)
67
+ x2 = x2.string
68
68
  x3 = pair_list [n1, n2, n3, n4]
69
69
  x4 = Nydp::StringFragmentCloseToken.new(' a purple cow!',' a purple cow!')
70
- x4 = Nydp::StringAtom.new(x4.string)
70
+ x4 = x4.string
71
71
 
72
72
  expected = pair_list([x1,x2,x3,x4])
73
73
  actual = parse_string 'a fluffy bunny! ~(foo bar "an embedded bunny :)" zop) a purple cow!'
@@ -80,10 +80,10 @@ describe Nydp::Parser do
80
80
 
81
81
  s1 = sym('string-pieces')
82
82
  s2 = Nydp::StringFragmentToken.new('a rather ','a rather ~')
83
- s2 = Nydp::StringAtom.new(s2.string)
83
+ s2 = s2.string
84
84
  s3 = pair_list [e1, e2]
85
85
  s4 = Nydp::StringFragmentCloseToken.new(' bunny :)',' bunny :)"')
86
- s4 = Nydp::StringAtom.new(s4.string)
86
+ s4 = s4.string
87
87
 
88
88
  n1 = sym(:foo)
89
89
  n2 = sym(:bar)
@@ -92,10 +92,10 @@ describe Nydp::Parser do
92
92
 
93
93
  x1 = sym('string-pieces')
94
94
  x2 = Nydp::StringFragmentToken.new('a fluffy bunny! ','a fluffy bunny! ~')
95
- x2 = Nydp::StringAtom.new(x2.string)
95
+ x2 = x2.string
96
96
  x3 = pair_list [n1, n2, n3, n4]
97
97
  x4 = Nydp::StringFragmentCloseToken.new(' a purple cow!',' a purple cow!')
98
- x4 = Nydp::StringAtom.new(x4.string)
98
+ x4 = x4.string
99
99
 
100
100
  expected = pair_list([x1,x2,x3,x4])
101
101
  actual = parse_string "a fluffy bunny! ~(foo bar \"a rather ~(describe bunny) bunny :)\" zop) a purple cow!"
@@ -9,7 +9,7 @@ describe Nydp::Hash do
9
9
  describe "hash set" do
10
10
  it "returns a new Nydp hash" do
11
11
  k = Nydp::Symbol.mk "keysym", ns
12
- v = Nydp::StringAtom.new "foobar"
12
+ v = "foobar"
13
13
  args = pair_list [ahash, k, v]
14
14
  Nydp::Builtin::HashSet.instance.invoke vm, args
15
15
 
@@ -29,7 +29,7 @@ describe Nydp::Hash do
29
29
 
30
30
  Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
31
31
 
32
- expect(vm.args.pop).to eq Nydp::StringAtom.new("avalue")
32
+ expect(vm.args.pop).to eq "avalue"
33
33
  end
34
34
 
35
35
  it "converts ruby nil to nydp value" do
@@ -20,15 +20,15 @@ describe Nydp::Hash do
20
20
  args = [ ahash, k ]
21
21
 
22
22
  Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
23
- expect(vm.args.pop).to eq Nydp::StringAtom.new("hello there")
23
+ expect(vm.args.pop).to eq "hello there"
24
24
  end
25
25
 
26
26
  it "converts string keys to method names" do
27
- k = Nydp::StringAtom.new "b"
27
+ k = "b"
28
28
  args = [ ahash, k ]
29
29
 
30
30
  Nydp::Builtin::HashGet.instance.invoke vm, pair_list(args)
31
- expect(vm.args.pop).to eq Nydp::StringAtom.new("hello there")
31
+ expect(vm.args.pop).to eq "hello there"
32
32
  end
33
33
 
34
34
  it "returns nil for unavailable methods" do
@@ -42,7 +42,7 @@ describe Nydp::Hash do
42
42
  end
43
43
 
44
44
  describe "unfriendly non-hash" do
45
- let(:ahash) { Nydp::StringAtom.new "this here ain't no hash, hombre" }
45
+ let(:ahash) { "this here ain't no hash, hombre" }
46
46
 
47
47
  def cleanup_err_msg txt
48
48
  txt.gsub(/at \/.*:in `builtin_invoke'/, '<error info>')
@@ -51,7 +51,7 @@ describe Nydp::Hash do
51
51
  describe "hash set" do
52
52
  it "does nothing, returns its value" do
53
53
  k = Nydp::Symbol.mk "keysym", ns
54
- v = Nydp::StringAtom.new "foobar"
54
+ v = "foobar"
55
55
  args = pair_list [ahash, k, v]
56
56
 
57
57
  begin
@@ -66,7 +66,7 @@ with args
66
66
  keysym
67
67
  \"foobar\""
68
68
 
69
- expect(cleanup_err_msg error.cause.message).to eq "_nydp_get : not settable: keysym on Nydp::StringAtom"
69
+ expect(cleanup_err_msg error.cause.message).to eq "_nydp_get : not settable: keysym on String"
70
70
  end
71
71
  end
72
72
 
@@ -86,7 +86,7 @@ with args
86
86
  \"this here ain't no hash, hombre\"
87
87
  keysym"
88
88
 
89
- expect(cleanup_err_msg error.cause.message).to eq "_nydp_get : not gettable: keysym on Nydp::StringAtom"
89
+ expect(cleanup_err_msg error.cause.message).to eq "_nydp_get : not gettable: keysym on String"
90
90
  end
91
91
  end
92
92
  end
@@ -16,7 +16,7 @@ describe Nydp::Hash do
16
16
 
17
17
  it "converts ruby string key to nydp string key" do
18
18
  hash = Nydp::Hash.new
19
- hash[Nydp::StringAtom.new "boo"] = 42
19
+ hash["boo"] = 42
20
20
 
21
21
  rhash = hash.to_ruby
22
22
  expect(rhash["boo"]).to eq 42
@@ -123,7 +123,7 @@ describe Nydp::Hash do
123
123
  describe "hash set" do
124
124
  it "does nothing, returns its value" do
125
125
  k = Nydp::Symbol.mk "keysym", ns
126
- v = Nydp::StringAtom.new "foobar"
126
+ v = "foobar"
127
127
  args = pair_list [ahash, k, v]
128
128
  Nydp::Builtin::HashSet.instance.invoke vm, args
129
129
 
@@ -22,7 +22,7 @@ describe Nydp do
22
22
  end
23
23
 
24
24
  it "should add strings" do
25
- expect(run '(+ "hello" " " "world")').to eq Nydp::StringAtom.new("hello world")
25
+ expect(run '(+ "hello" " " "world")').to eq "hello world"
26
26
  end
27
27
 
28
28
  it "should add Pairs" do
@@ -46,7 +46,7 @@ describe Nydp do
46
46
  end
47
47
 
48
48
  it "should convert items to strings" do
49
- expect(run "(to-string 3.1415)").to eq Nydp::StringAtom.new("3.1415")
49
+ expect(run "(to-string 3.1415)").to eq "3.1415"
50
50
  end
51
51
 
52
52
  it "should compare integers" do
@@ -112,4 +112,16 @@ describe Nydp do
112
112
  expect(run code).to eq 17
113
113
  end
114
114
  end
115
+
116
+ describe "proc from ruby object" do
117
+ it "invokes a proc like a builtin function" do
118
+ Nydp::Symbol.mk(:tt, ns).assign(TestThing.new(42, 720, 9699690))
119
+
120
+ one_thing = run "((hash-get tt 'one_thing) 24)"
121
+ expect(one_thing).to eq(42 + 24)
122
+
123
+ two_things = run "((hash-get tt 'two_things) 60 2)"
124
+ expect(two_things).to eq(60 + (2 * 720))
125
+ end
126
+ end
115
127
  end
@@ -75,7 +75,7 @@ describe Nydp::Parser do
75
75
  s2 = Nydp::StringFragmentCloseToken.new "hello there", '"hello there"'
76
76
 
77
77
  x1 = 1
78
- x2 = Nydp::StringAtom.new "hello there"
78
+ x2 = "hello there"
79
79
  x3 = 3
80
80
 
81
81
  expected = pair_list [x1, x2, x3]
@@ -85,7 +85,7 @@ describe Nydp::Parser do
85
85
 
86
86
  it "should parse a string" do
87
87
  x1 = sym 'join'
88
- x2 = Nydp::StringAtom.new " - "
88
+ x2 = " - "
89
89
  x3 = 1
90
90
  x4 = 2
91
91
  x5 = 3
@@ -99,7 +99,7 @@ describe Nydp::Parser do
99
99
  s2 = Nydp::StringFragmentCloseToken.new "hello (1 2 3) there", '"hello (1 2 3) there"'
100
100
 
101
101
  x1 = 1
102
- x2 = Nydp::StringAtom.new "hello (1 2 3) there"
102
+ x2 = "hello (1 2 3) there"
103
103
  x3 = 3
104
104
 
105
105
  expected = pair_list [x1, x2, x3]
@@ -111,7 +111,7 @@ describe Nydp::Parser do
111
111
  s2 = Nydp::StringFragmentCloseToken.new "hello there \"jimmy\"", '"hello there \"jimmy\""'
112
112
 
113
113
  x1 = 1
114
- x2 = Nydp::StringAtom.new "hello there \"jimmy\""
114
+ x2 = "hello there \"jimmy\""
115
115
  x3 = 3
116
116
 
117
117
  expected = pair_list [x1, x2, x3]
@@ -120,7 +120,7 @@ describe Nydp::Parser do
120
120
  end
121
121
 
122
122
  it "should handle escaped tabs and newlines inside a string" do
123
- expected = Nydp::StringAtom.new "hello\tworld\nnice day"
123
+ expected = "hello\tworld\nnice day"
124
124
  parsed = parse "\"hello\\tworld\\nnice day\""
125
125
  expect(parsed).to eq expected
126
126
  end
@@ -215,7 +215,7 @@ describe Nydp::Parser do
215
215
  end
216
216
 
217
217
  it "retains otherwise unidentified list prefixes" do
218
- expect(parse "%wong(bar)").to eq pair_list([prefix_list, Nydp::StringAtom.new("%wong"), pair_list([bar])])
218
+ expect(parse "%wong(bar)").to eq pair_list([prefix_list, "%wong", pair_list([bar])])
219
219
  end
220
220
 
221
221
  it "should do some complicated unquote stuff with lists" do
@@ -257,24 +257,24 @@ describe Nydp::Parser do
257
257
  end
258
258
 
259
259
  it "parses a simple string" do
260
- expect(parse '"foo"').to eq Nydp::StringAtom.new("foo")
260
+ expect(parse '"foo"').to eq "foo"
261
261
  end
262
262
 
263
263
  it "parses a string with a simple interpolation" do
264
- str = Nydp::StringAtom.new("foo ")
265
- empty = Nydp::StringAtom.new("")
264
+ str = "foo "
265
+ empty = ""
266
266
  expect(parse '"foo ~foo"').to eq pair_list([string_pieces, str, foo, empty])
267
267
  end
268
268
 
269
269
  it "parses a string with a more complex interpolation" do
270
- strf = Nydp::StringAtom.new("foo ")
271
- strb = Nydp::StringAtom.new(" bar")
270
+ strf = "foo "
271
+ strb = " bar"
272
272
  expect(parse '"foo ~(foo bar) bar"').to eq pair_list([string_pieces, strf, pair_list([foo, bar]), strb])
273
273
  end
274
274
 
275
275
  it "parses a string with an interpolation containing a nested interpolation" do
276
- strf = Nydp::StringAtom.new("foo ")
277
- strb = Nydp::StringAtom.new(" bar")
276
+ strf = "foo "
277
+ strb = " bar"
278
278
 
279
279
  nested = pair_list [string_pieces, strf, foo, strb]
280
280
  expr = pair_list [foo, nested, bar]
@@ -283,7 +283,7 @@ describe Nydp::Parser do
283
283
  end
284
284
 
285
285
  it "parses a string with only an interpolation" do
286
- empty = Nydp::StringAtom.new("")
286
+ empty = ""
287
287
  expect(parse '"~foo"').to eq pair_list([string_pieces, empty, foo, empty])
288
288
  end
289
289
 
@@ -292,7 +292,7 @@ describe Nydp::Parser do
292
292
  ; here's a comment
293
293
  (zab))
294
294
  "
295
- c1 = pair_list([comment, Nydp::StringAtom.new("here's a comment")])
295
+ c1 = pair_list([comment, "here's a comment"])
296
296
  fbar = pair_list([bar])
297
297
  fzab = pair_list([Nydp::Symbol.mk(:zab, ns)])
298
298
  fdef = Nydp::Symbol.mk(:def, ns)
@@ -322,7 +322,7 @@ NYDP
322
322
  expect(args[1]).to eq sym("args")
323
323
  expect(args[2]).to be_nil
324
324
  expect(parsed[2].cdr.cdr).to eq sym("body")
325
- expect(parsed[3].to_a).to eq [sym("comment"), Nydp::StringAtom.new("define a new function in the global namespace")]
325
+ expect(parsed[3].to_a).to eq [sym("comment"), "define a new function in the global namespace"]
326
326
  expect(parsed[4].to_a).to eq [sym("chapter"), sym("nydp-core")]
327
327
  end
328
328
  end
@@ -15,7 +15,7 @@ describe Nydp::Builtin::Rand do
15
15
  numbers = (0..100).map { |i| get_rand }
16
16
  expect(numbers.all? { |n| n >= 0 && n < 1 })
17
17
  avg = numbers.reduce &:+
18
- expect(avg).to be_between 40, 60
18
+ expect(avg).to be_between 40, 60 # with high probability
19
19
  distinct = Set.new numbers
20
20
  expect(distinct.count).to be > 90
21
21
  end
@@ -26,7 +26,7 @@ describe Nydp::Builtin::Rand do
26
26
  numbers = (0..200).map { |i| get_rand 10 }
27
27
  expect(numbers.all? { |n| n >= 0 && n < 10 })
28
28
  avg = numbers.reduce &:+
29
- expect(avg).to be_between 800, 1200
29
+ expect(avg).to be_between 800, 1200 # with high probability
30
30
  distinct = Set.new numbers
31
31
  expect(distinct.count).to eq 10
32
32
  end
@@ -37,7 +37,7 @@ describe Nydp::Builtin::Rand do
37
37
  numbers = (0..200).map { |i| get_rand 10, 20 }
38
38
  expect(numbers.all? { |n| n >= 10 && n < 20 })
39
39
  avg = numbers.reduce &:+
40
- expect(avg).to be_between 2800, 3200
40
+ expect(avg).to be_between 2800, 3200 # with high probability
41
41
  distinct = Set.new numbers
42
42
  expect(distinct.count).to eq 10
43
43
  end
@@ -37,8 +37,17 @@ class TestThing
37
37
  "(TestThing #{a.inspect} #{b.inspect})"
38
38
  end
39
39
 
40
+ def one_thing x
41
+ x + a
42
+ end
43
+
44
+ def two_things x, y
45
+ x + (y * b)
46
+ end
47
+
40
48
  def _nydp_get name
41
49
  name = name.to_s.to_sym
42
- send(name) if name == :a || name == :b
50
+ return send(name) if name == :a || name == :b
51
+ return method(name) if name == :one_thing || name == :two_things
43
52
  end
44
53
  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.4.5
4
+ version: 0.4.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: 2019-12-06 00:00:00.000000000 Z
11
+ date: 2020-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,7 @@ files:
80
80
  - lib/lisp/core-100-utils.nydp
81
81
  - lib/lisp/core-110-hash-utils.nydp
82
82
  - lib/lisp/core-120-settings.nydp
83
+ - lib/lisp/core-130-validations.nydp
83
84
  - lib/lisp/core-900-benchmarking.nydp
84
85
  - lib/lisp/tests/accum-examples.nydp
85
86
  - lib/lisp/tests/add-hook-examples.nydp
@@ -132,6 +133,7 @@ files:
132
133
  - lib/lisp/tests/mapreduce-examples.nydp
133
134
  - lib/lisp/tests/mapsum-examples.nydp
134
135
  - lib/lisp/tests/module-examples.nydp
136
+ - lib/lisp/tests/multi-assign-examples.nydp
135
137
  - lib/lisp/tests/none-examples.nydp
136
138
  - lib/lisp/tests/orequal-examples.nydp
137
139
  - lib/lisp/tests/parser-tests.nydp
@@ -154,9 +156,11 @@ files:
154
156
  - lib/lisp/tests/string-tests.nydp
155
157
  - lib/lisp/tests/syntax-tests.nydp
156
158
  - lib/lisp/tests/time-examples.nydp
159
+ - lib/lisp/tests/to-integer-examples.nydp
157
160
  - lib/lisp/tests/tuples-examples.nydp
158
161
  - lib/lisp/tests/type-of-examples.nydp
159
162
  - lib/lisp/tests/unparse-tests.nydp
163
+ - lib/lisp/tests/validation-examples.nydp
160
164
  - lib/lisp/tests/zap-examples.nydp
161
165
  - lib/lisp/tests/zip-examples.nydp
162
166
  - lib/nydp.rb
@@ -206,6 +210,7 @@ files:
206
210
  - lib/nydp/builtin/thread_locals.rb
207
211
  - lib/nydp/builtin/time.rb
208
212
  - lib/nydp/builtin/times.rb
213
+ - lib/nydp/builtin/to_integer.rb
209
214
  - lib/nydp/builtin/to_string.rb
210
215
  - lib/nydp/builtin/type_of.rb
211
216
  - lib/nydp/builtin/vm_info.rb