nydp 0.1.3 → 0.1.4
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/tests/builtin-tests.nydp +2 -0
- data/lib/lisp/tests/range-examples.nydp +8 -0
- data/lib/lisp/tests/tuples-examples.nydp +16 -0
- data/lib/nydp/builtin/plus.rb +8 -12
- data/lib/nydp/builtin/today.rb +11 -0
- data/lib/nydp/core.rb +2 -0
- data/lib/nydp/date.rb +4 -0
- data/lib/nydp/version.rb +1 -1
- data/spec/date_spec.rb +68 -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: a7f1dacf6f22c7cd5db09de064fe3cdd11a76654
|
4
|
+
data.tar.gz: 530d35d6fc54b082edb788eec8ccb15078c09582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84db7216bd92545097e6b0dc3f827620c45b80261d3bbdfb18e7f0dfb70dca2b5d3078dfd07be3a0ef5fa107ad2363f9cc66e94a21b1a4b8b09a40c0cb87451a
|
7
|
+
data.tar.gz: 07c739e5165a3c857a43d8c2e04088562897dcede3283a9ae572620a09f24b6cf8836efcb84f8fcd0985a424c24db675c77acff178ed03a43692bd857877d82b
|
@@ -200,3 +200,19 @@
|
|
200
200
|
; for the old function
|
201
201
|
(fn args2
|
202
202
|
(apply func (joinlists args1 args2))))
|
203
|
+
|
204
|
+
(def tuples (n things)
|
205
|
+
;; split things into a list of lists each n long
|
206
|
+
(rfnwith _ (list things)
|
207
|
+
(if (no list)
|
208
|
+
nil
|
209
|
+
(cons (firstn n list) (_ (nthcdr n list))))))
|
210
|
+
|
211
|
+
(def range (start stop)
|
212
|
+
; return a list containing the range
|
213
|
+
; of elements starting with 'start, up
|
214
|
+
; to but not including 'stop
|
215
|
+
(if (< start stop)
|
216
|
+
(cons start
|
217
|
+
(range (+ start 1)
|
218
|
+
stop))))
|
@@ -11,6 +11,8 @@
|
|
11
11
|
("<" (inspect < ) "builtin/<" )
|
12
12
|
("eval" (inspect eval ) "builtin/eval" )
|
13
13
|
("hash" (inspect hash ) "builtin/hash" )
|
14
|
+
("date" (inspect date ) "builtin/date" )
|
15
|
+
("today" (inspect today ) "builtin/today" )
|
14
16
|
("error" (inspect error ) "builtin/error" )
|
15
17
|
("apply" (inspect apply ) "builtin/apply" )
|
16
18
|
("error" (inspect error ) "builtin/error" )
|
@@ -0,0 +1,16 @@
|
|
1
|
+
(examples-for tuples
|
2
|
+
("returns nil for nil"
|
3
|
+
(tuples 3 nil)
|
4
|
+
nil)
|
5
|
+
|
6
|
+
("returns single list for fewer than n items"
|
7
|
+
(tuples 4 '(a b) )
|
8
|
+
((a b nil nil)))
|
9
|
+
|
10
|
+
("returns exactly one list for exactly n items"
|
11
|
+
(tuples 5 '(a b c d e) )
|
12
|
+
((a b c d e)))
|
13
|
+
|
14
|
+
("returns the given list split into sublist each having n items"
|
15
|
+
(tuples 3 '(a b c d e f g) )
|
16
|
+
((a b c) (d e f) (g nil nil))))
|
data/lib/nydp/builtin/plus.rb
CHANGED
@@ -2,7 +2,14 @@ class Nydp::Builtin::Plus
|
|
2
2
|
include Nydp::Builtin::Base
|
3
3
|
|
4
4
|
def builtin_invoke vm, args
|
5
|
-
vm.push_arg
|
5
|
+
vm.push_arg case args.car
|
6
|
+
when Fixnum, Nydp::Date
|
7
|
+
sum(args.cdr, args.car)
|
8
|
+
when Nydp::Pair
|
9
|
+
sum(args, Nydp.NIL)
|
10
|
+
when String, Nydp::StringAtom
|
11
|
+
sum(args, Nydp::StringAtom.new(""))
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
15
|
def sum args, accum
|
@@ -13,16 +20,5 @@ class Nydp::Builtin::Plus
|
|
13
20
|
end
|
14
21
|
end
|
15
22
|
|
16
|
-
def origin obj
|
17
|
-
case obj
|
18
|
-
when Fixnum
|
19
|
-
0
|
20
|
-
when Nydp::Pair
|
21
|
-
Nydp.NIL
|
22
|
-
when String, Nydp::StringAtom
|
23
|
-
Nydp::StringAtom.new ""
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
23
|
def name ; "+" ; end
|
28
24
|
end
|
data/lib/nydp/builtin/today.rb
CHANGED
@@ -5,3 +5,14 @@ class Nydp::Builtin::Today
|
|
5
5
|
vm.push_arg(Nydp::Date.new Date.today)
|
6
6
|
end
|
7
7
|
end
|
8
|
+
|
9
|
+
class Nydp::Builtin::Date
|
10
|
+
include Nydp::Helper, Nydp::Builtin::Base
|
11
|
+
|
12
|
+
def builtin_invoke vm, args
|
13
|
+
y = args.car
|
14
|
+
m = args.cdr.car
|
15
|
+
d = args.cdr.cdr.car
|
16
|
+
vm.push_arg(Nydp::Date.new Date.new(y,m,d))
|
17
|
+
end
|
18
|
+
end
|
data/lib/nydp/core.rb
CHANGED
@@ -34,6 +34,7 @@ module Nydp
|
|
34
34
|
Symbol.mk(:false, ns).assign(false)
|
35
35
|
Symbol.mk(:hash, ns).assign(Nydp::Builtin::Hash.new)
|
36
36
|
Symbol.mk(:apply, ns).assign(Nydp::Builtin::Apply.new)
|
37
|
+
Symbol.mk(:date, ns).assign(Nydp::Builtin::Date.new)
|
37
38
|
Symbol.mk(:error, ns).assign(Nydp::Builtin::Error.new)
|
38
39
|
Symbol.mk(:parse, ns).assign(Nydp::Builtin::Parse.new(ns))
|
39
40
|
Symbol.mk(:p, ns).assign(Nydp::Builtin::Puts.new)
|
@@ -55,6 +56,7 @@ module Nydp
|
|
55
56
|
Symbol.mk("string-replace" , ns).assign(Nydp::Builtin::StringReplace.new)
|
56
57
|
Symbol.mk("string-match" , ns).assign(Nydp::Builtin::StringMatch.new(ns))
|
57
58
|
Symbol.mk("string-split" , ns).assign(Nydp::Builtin::StringSplit.new )
|
59
|
+
Symbol.mk("today" , ns).assign(Nydp::Builtin::Today.new)
|
58
60
|
Symbol.mk("thread-locals" , ns).assign(Nydp::Builtin::ThreadLocals.new)
|
59
61
|
Symbol.mk("type-of", ns).assign(Nydp::Builtin::TypeOf.new(ns))
|
60
62
|
Symbol.mk(:"eq?", ns).assign(Nydp::Builtin::IsEqual.new)
|
data/lib/nydp/date.rb
CHANGED
@@ -20,6 +20,10 @@ module Nydp
|
|
20
20
|
def to_ruby ; ruby_date ; end
|
21
21
|
def inspect ; ruby_date.inspect ; end
|
22
22
|
def nydp_type ; :date ; end
|
23
|
+
def - other ; r2n(ruby_date - other.ruby_date, nil) ; end
|
24
|
+
def + int ; r2n(ruby_date + int , nil) ; end
|
25
|
+
def > other ; ruby_date > other.ruby_date ; end
|
26
|
+
def < other ; ruby_date < other.ruby_date ; end
|
23
27
|
|
24
28
|
@@keys = Set.new %i{
|
25
29
|
year month week_day day
|
data/lib/nydp/version.rb
CHANGED
data/spec/date_spec.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Nydp::Date do
|
4
4
|
|
5
|
-
let(:ns) { { }
|
5
|
+
let(:ns) { { } }
|
6
|
+
let(:vm) { Nydp::VM.new }
|
6
7
|
|
7
8
|
it "converts ruby Date to Nydp::Date" do
|
8
9
|
rd = Date.parse "2015-06-08"
|
@@ -14,6 +15,14 @@ describe Nydp::Date do
|
|
14
15
|
expect(nd.to_ruby).to eq Date.parse("2015-06-08")
|
15
16
|
end
|
16
17
|
|
18
|
+
it "creates a new date" do
|
19
|
+
df = Nydp::Builtin::Date.new
|
20
|
+
df.invoke vm, pair_list([2015, 11, 18])
|
21
|
+
nd = vm.pop_arg
|
22
|
+
expect(nd).to be_a Nydp::Date
|
23
|
+
expect(nd.ruby_date).to eq Date.parse("2015-11-18")
|
24
|
+
end
|
25
|
+
|
17
26
|
it "returns date components" do
|
18
27
|
rd = Date.parse "2015-06-08"
|
19
28
|
nd = Nydp.r2n rd, ns
|
@@ -23,6 +32,64 @@ describe Nydp::Date do
|
|
23
32
|
expect(nd[:day]). to eq 8
|
24
33
|
end
|
25
34
|
|
35
|
+
describe "date maths" do
|
36
|
+
let(:d0) { Nydp.r2n Date.today, ns }
|
37
|
+
let(:d1) { Nydp.r2n (Date.today + 6), ns }
|
38
|
+
|
39
|
+
it "works with builtin minus" do
|
40
|
+
minus = Nydp::Builtin::Minus.new
|
41
|
+
|
42
|
+
minus.invoke vm, pair_list([d1, d0])
|
43
|
+
diff = vm.pop_arg
|
44
|
+
|
45
|
+
expect(d0).to be_a Nydp::Date
|
46
|
+
expect(diff).to eq 6
|
47
|
+
end
|
48
|
+
|
49
|
+
it "works with builtin greater-than when true" do
|
50
|
+
f = Nydp::Builtin::GreaterThan.new
|
51
|
+
|
52
|
+
f.invoke vm, pair_list([d1, d0])
|
53
|
+
|
54
|
+
expect(vm.pop_arg).to eq Nydp.T
|
55
|
+
end
|
56
|
+
|
57
|
+
it "works with builtin greater-than when false" do
|
58
|
+
f = Nydp::Builtin::GreaterThan.new
|
59
|
+
|
60
|
+
f.invoke vm, pair_list([d0, d1])
|
61
|
+
|
62
|
+
expect(vm.pop_arg).to eq Nydp.NIL
|
63
|
+
end
|
64
|
+
|
65
|
+
it "works with builtin less-than when true" do
|
66
|
+
f = Nydp::Builtin::LessThan.new
|
67
|
+
|
68
|
+
f.invoke vm, pair_list([d0, d1])
|
69
|
+
|
70
|
+
expect(vm.pop_arg).to eq Nydp.T
|
71
|
+
end
|
72
|
+
|
73
|
+
it "works with builtin less-than when false" do
|
74
|
+
f = Nydp::Builtin::LessThan.new
|
75
|
+
|
76
|
+
f.invoke vm, pair_list([d1, d0])
|
77
|
+
|
78
|
+
expect(vm.pop_arg).to eq Nydp.NIL
|
79
|
+
end
|
80
|
+
|
81
|
+
it "works with builtin plus" do
|
82
|
+
plus = Nydp::Builtin::Plus.new
|
83
|
+
|
84
|
+
plus.invoke vm, pair_list([d0, 5])
|
85
|
+
sum = vm.pop_arg
|
86
|
+
|
87
|
+
expect(d0) .to be_a Nydp::Date
|
88
|
+
expect(sum).to be_a Nydp::Date
|
89
|
+
expect(sum.ruby_date).to eq(Date.today + 5)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
26
93
|
it "returns relative dates by year" do
|
27
94
|
rd = Date.parse "2015-06-08"
|
28
95
|
nd = Nydp.r2n rd, ns
|
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.4
|
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
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,9 +117,11 @@ files:
|
|
117
117
|
- lib/lisp/tests/parser-tests.nydp
|
118
118
|
- lib/lisp/tests/pretty-print-tests.nydp
|
119
119
|
- lib/lisp/tests/quasiquote-examples.nydp
|
120
|
+
- lib/lisp/tests/range-examples.nydp
|
120
121
|
- lib/lisp/tests/rfnwith-tests.nydp
|
121
122
|
- lib/lisp/tests/string-tests.nydp
|
122
123
|
- lib/lisp/tests/syntax-tests.nydp
|
124
|
+
- lib/lisp/tests/tuples-examples.nydp
|
123
125
|
- lib/lisp/tests/type-of-examples.nydp
|
124
126
|
- lib/lisp/tests/unparse-tests.nydp
|
125
127
|
- lib/nydp.rb
|