lasp 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe53c128ac7fb00e1dcf9e1e89db3596e9557690
4
- data.tar.gz: c7a42762434a1192b531bc980fc65ba5b84d06f9
3
+ metadata.gz: 834e32aec6fd535ecec0d68c7297cb3184ced218
4
+ data.tar.gz: ccc67e45c0aeb24b368a51a6bcea67d09af86db9
5
5
  SHA512:
6
- metadata.gz: 18a21269e6682b786c215d16b286ea6ff4533de458dea3099536e9f1b8f709c8cf568f0725a527c398469ccd941213f1c4a8c86f8b6c23f954a8f88c1e64cc44
7
- data.tar.gz: 315b73b00df83f029848a3b36dd8b7e3a7fb03bf22109cd4298adff8b6b57eb6bee8afa9c81ba665735d6e5a6962a05f36943feb6481e42419cbdaf86f4f5f20
6
+ metadata.gz: ca7f8e586069ed34fa69c03c9c3b16a789b25b695e342d7e2124e5c1b6a9c7b5a23d12cfa4fa329b8668bcb24597ff1e4c8626a39888622369db3e20addab53e
7
+ data.tar.gz: 32229cfbb3e1c039249adcedacd75a8e50b3ad3ef0c71f3b0e522d8d5816a5d48429ddd9fa540157d7923b77a195bd46fe921d8b2d8f8086110896e2d1286675
@@ -1,5 +1,21 @@
1
1
  # Läsp changelog
2
2
 
3
+ ## v0.4.0
4
+
5
+ Implicit do-blocks around files. You can now do this...:
6
+
7
+ ```lisp
8
+ (def x 5)
9
+
10
+ (def y 10)
11
+ ```
12
+
13
+ ...in a Läsp file without having to wrap the entire contents of the file in
14
+ `(do ...)`. Previously it just stopped reading after the first form and
15
+ anything after would seemingly inexplicably not be run.
16
+
17
+ **This is only enabled in files, not every form of evaluation.**
18
+
3
19
  ## v0.3.2
4
20
 
5
21
  Fix bug in `do` - it accidentally returned part of the AST, now it correctly
data/README.md CHANGED
@@ -57,6 +57,7 @@ Supports these datatypes (implemented as their Ruby counterparts)
57
57
  - nil
58
58
  - string
59
59
  - list
60
+ - hash-map
60
61
 
61
62
  ### Comments
62
63
 
@@ -7,7 +7,7 @@ module Lasp
7
7
  module_function
8
8
 
9
9
  def execute_file(path)
10
- execute(File.read(path))
10
+ execute("(do #{File.read(path)})")
11
11
  end
12
12
 
13
13
  def execute(program, env = global_env)
@@ -1,122 +1,120 @@
1
- (do
2
- ; Aliases
3
- (def first head)
4
- (def rest tail)
5
-
6
- ; Increment a number by one
7
- (def inc (fn (x) (+ x 1)))
8
-
9
- ; Decrement a number by one
10
- (def dec (fn (x) (- x 1)))
11
-
12
- ; If a list is empty
13
- (def empty?
14
- (fn (coll)
15
- (= (head coll) nil)))
16
-
17
- ; Modulus
18
- (def mod
19
- (fn (x y) (- x (* (/ x y) y))))
20
-
21
- ; Returns a function that does the opposite of the given function
22
- (def complement
23
- (fn (f) (fn (x) (not (f x)))))
24
-
25
- ; If a number is even
26
- (def even?
27
- (fn (x) (= (mod x 2) 0)))
28
-
29
- ; If a number is odd
30
- (def odd? (complement even?))
31
-
32
- ; Length of a list
33
- (def len
34
- (fn (coll)
35
- (if (empty? coll)
36
- 0
37
- (inc (len (tail coll))))))
38
-
39
- ; Gets an item in a list by index
40
- (def nth
41
- (fn (index coll)
42
- (if (= 0 index)
43
- (head coll)
44
- (nth (dec index) (tail coll)))))
45
-
46
- ; Last item in list
47
- (def last
48
- (fn (coll)
49
- (nth (dec (len coll)) coll)))
50
-
51
- ; Reverses a list
52
- (def reverse
53
- (fn (coll)
54
- (reduce (fn (acc item) (cons item acc)) (list) coll)))
55
-
56
- ; Apply f to all items in list
57
- (def map
58
- (fn (f coll)
59
- (if (= nil (head coll))
60
- coll
61
- (cons
62
- (f (head coll))
63
- (map f (tail coll))))))
64
-
65
- ; Go through a list passing an accumulator and each item of the list through f
66
- ; f(acc item)
67
- (def reduce
68
- (fn (f acc coll)
69
- (if (empty? coll)
70
- acc
71
- (reduce f (f acc (head coll)) (tail coll)))))
72
-
73
- ; Filter a list of items based on a function
74
- (def filter
75
- (fn (f coll)
76
- (reduce
77
- (fn (acc item) (if (f item) (cons item acc) acc))
78
- (list)
79
- (reverse coll))))
80
-
81
- ; Sum of all items in a list
82
- (def sum
83
- (fn (coll)
84
- (reduce + 0 coll)))
85
-
86
- ; Take x items from list
87
- (def take
88
- (fn (num coll)
89
- (if (= num 0)
90
- (list)
91
- (cons (head coll) (take (dec num) (tail coll))))))
92
-
93
- ; Drop x items from list
94
- (def drop
95
- (fn (num coll)
96
- (if (= num 0)
97
- coll
98
- (drop (dec num) (tail coll)))))
99
-
100
- ; Exclusive range
101
- (def range
102
- (fn (from to)
103
- (if (= from to)
104
- (list)
105
- (cons from (range (inc from) to)))))
106
-
107
- ; Highest value in list
108
- (def max
109
- (fn (coll)
110
- (reduce
111
- (fn (acc item) (if (< acc item) item acc))
112
- (head coll)
113
- (tail coll))))
114
-
115
- ; Lowest value in list
116
- (def min
117
- (fn (coll)
118
- (reduce
119
- (fn (acc item) (if (> acc item) item acc))
120
- (head coll)
121
- (tail coll))))
122
- )
1
+ ; Aliases
2
+ (def first head)
3
+ (def rest tail)
4
+
5
+ ; Increment a number by one
6
+ (def inc (fn (x) (+ x 1)))
7
+
8
+ ; Decrement a number by one
9
+ (def dec (fn (x) (- x 1)))
10
+
11
+ ; If a list is empty
12
+ (def empty?
13
+ (fn (coll)
14
+ (= (head coll) nil)))
15
+
16
+ ; Modulus
17
+ (def mod
18
+ (fn (x y) (- x (* (/ x y) y))))
19
+
20
+ ; Returns a function that does the opposite of the given function
21
+ (def complement
22
+ (fn (f) (fn (x) (not (f x)))))
23
+
24
+ ; If a number is even
25
+ (def even?
26
+ (fn (x) (= (mod x 2) 0)))
27
+
28
+ ; If a number is odd
29
+ (def odd? (complement even?))
30
+
31
+ ; Length of a list
32
+ (def len
33
+ (fn (coll)
34
+ (if (empty? coll)
35
+ 0
36
+ (inc (len (tail coll))))))
37
+
38
+ ; Gets an item in a list by index
39
+ (def nth
40
+ (fn (index coll)
41
+ (if (= 0 index)
42
+ (head coll)
43
+ (nth (dec index) (tail coll)))))
44
+
45
+ ; Last item in list
46
+ (def last
47
+ (fn (coll)
48
+ (nth (dec (len coll)) coll)))
49
+
50
+ ; Reverses a list
51
+ (def reverse
52
+ (fn (coll)
53
+ (reduce (fn (acc item) (cons item acc)) (list) coll)))
54
+
55
+ ; Apply f to all items in list
56
+ (def map
57
+ (fn (f coll)
58
+ (if (= nil (head coll))
59
+ coll
60
+ (cons
61
+ (f (head coll))
62
+ (map f (tail coll))))))
63
+
64
+ ; Go through a list passing an accumulator and each item of the list through f
65
+ ; f(acc item)
66
+ (def reduce
67
+ (fn (f acc coll)
68
+ (if (empty? coll)
69
+ acc
70
+ (reduce f (f acc (head coll)) (tail coll)))))
71
+
72
+ ; Filter a list of items based on a function
73
+ (def filter
74
+ (fn (f coll)
75
+ (reduce
76
+ (fn (acc item) (if (f item) (cons item acc) acc))
77
+ (list)
78
+ (reverse coll))))
79
+
80
+ ; Sum of all items in a list
81
+ (def sum
82
+ (fn (coll)
83
+ (reduce + 0 coll)))
84
+
85
+ ; Take x items from list
86
+ (def take
87
+ (fn (num coll)
88
+ (if (= num 0)
89
+ (list)
90
+ (cons (head coll) (take (dec num) (tail coll))))))
91
+
92
+ ; Drop x items from list
93
+ (def drop
94
+ (fn (num coll)
95
+ (if (= num 0)
96
+ coll
97
+ (drop (dec num) (tail coll)))))
98
+
99
+ ; Exclusive range
100
+ (def range
101
+ (fn (from to)
102
+ (if (= from to)
103
+ (list)
104
+ (cons from (range (inc from) to)))))
105
+
106
+ ; Highest value in list
107
+ (def max
108
+ (fn (coll)
109
+ (reduce
110
+ (fn (acc item) (if (< acc item) item acc))
111
+ (head coll)
112
+ (tail coll))))
113
+
114
+ ; Lowest value in list
115
+ (def min
116
+ (fn (coll)
117
+ (reduce
118
+ (fn (acc item) (if (> acc item) item acc))
119
+ (head coll)
120
+ (tail coll))))
@@ -1,3 +1,3 @@
1
1
  module Lasp
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lasp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Börjesson