lasp 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +7 -32
- data/{EXAMPLES.md → docs/examples.md} +4 -3
- data/docs/language.md +136 -0
- data/{DOCUMENTATION.md → docs/reference.md} +3 -14
- data/lib/lasp/interpreter.rb +5 -1
- data/lib/lasp/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f37487e5e7f6bd7fb1ef31fef1dfa3bcfb4c9f55
|
4
|
+
data.tar.gz: b0bbd30928d655e45bcc809af6a34bfb389e0fcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d05c4d229e16ece6639a639b1555a5f76159b2ca29fe11890b181dcf4332f08164e26b0e1ac6f1da01af61a63e3c568efdd48b4eb11a996200d7679b53a7dd1
|
7
|
+
data.tar.gz: 60734cb7b52b5c3a1ef00e3a80dbb201c31c496b8580e1675131154580a6e0d1cf9edf160feaa5c15e933e8fb1eb279c3e209d5880cd11db8dad032baa7d1811
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,14 +4,14 @@ A Lisp implementation in Ruby.
|
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
7
|
-
- Comprehensive [documentation](
|
7
|
+
- Comprehensive [documentation](#documentation)
|
8
8
|
- Interactive REPL with auto-closing of missing trailing parentheses
|
9
9
|
- Closures
|
10
10
|
- let-bindings
|
11
11
|
- Fully functional macro system
|
12
12
|
- Interoperability with Ruby
|
13
13
|
- Very concise [core library](lib/lasp/corelib.rb) written in Ruby
|
14
|
-
- [Standard library](lib/lasp/stdlib.
|
14
|
+
- [Standard library](lib/lasp/stdlib.lasp) written in Läsp itself
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
@@ -40,38 +40,13 @@ lasp
|
|
40
40
|
lasp path/to/program.lasp
|
41
41
|
```
|
42
42
|
|
43
|
-
##
|
43
|
+
## Documentation
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
- [Language](docs/language.md) - explains the core types and syntax of the language.
|
46
|
+
- [Reference](docs/reference.md) - a list of every available function with description and usage examples.
|
47
|
+
- [Examples](docs/examples.md) - various small examples of using the language.
|
48
|
+
- [Zuul](https://github.com/alcesleo/zuul) - a small text-based game written in Läsp.
|
47
49
|
|
48
|
-
### Examples
|
49
|
-
|
50
|
-
More advanced examples can be found in [EXAMPLES.md](EXAMPLES.md), you can also
|
51
|
-
look at the [standard library](lib/lasp/stdlib.lasp) which is implemented in
|
52
|
-
Läsp itself.
|
53
|
-
|
54
|
-
```lisp
|
55
|
-
(+ 1 2 3) ;; => 6
|
56
|
-
|
57
|
-
(def x 5)
|
58
|
-
x ;; => 6
|
59
|
-
|
60
|
-
(sum (list 5 10 15)) ;; => 30
|
61
|
-
|
62
|
-
(def inc (fn (x) (+ x 1)))
|
63
|
-
(inc 5) ;; => 6
|
64
|
-
```
|
65
|
-
|
66
|
-
|
67
|
-
### Comments
|
68
|
-
|
69
|
-
Comments start with a `;` and end at the end of a line
|
70
|
-
|
71
|
-
```lisp
|
72
|
-
; This is a comment
|
73
|
-
(+ 1 2) ; This is also a comment
|
74
|
-
```
|
75
50
|
|
76
51
|
## Developing
|
77
52
|
|
@@ -248,10 +248,11 @@ x ;; => (1 2 3)
|
|
248
248
|
## Interoperability
|
249
249
|
|
250
250
|
```clojure
|
251
|
-
;
|
252
|
-
|
251
|
+
; Prepend a dot to the method name and pass the object as the first argument to
|
252
|
+
; call a Ruby method.
|
253
|
+
(.to_i "01011101" 2) ;; => 93
|
253
254
|
|
254
|
-
(def parse_binary (fn (bin) (. bin
|
255
|
+
(def parse_binary (fn (bin) (.to_i bin 2)))
|
255
256
|
(parse_binary "01011101") ;; => 93
|
256
257
|
```
|
257
258
|
|
data/docs/language.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# Language
|
2
|
+
|
3
|
+
This page describes the syntax and core types of the language.
|
4
|
+
|
5
|
+
## Comments
|
6
|
+
|
7
|
+
Comments start with a `;` and end at the end of a line
|
8
|
+
|
9
|
+
```lisp
|
10
|
+
; This is a comment
|
11
|
+
(+ 1 2) ; This is also a comment
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
## Data types
|
16
|
+
|
17
|
+
The core types are backed by their corresponding Ruby classes. This can be seen
|
18
|
+
by doing `(.class 5)`.
|
19
|
+
|
20
|
+
### integer
|
21
|
+
|
22
|
+
A whole number.
|
23
|
+
|
24
|
+
```clojure
|
25
|
+
1
|
26
|
+
-42
|
27
|
+
0
|
28
|
+
```
|
29
|
+
|
30
|
+
### decimal
|
31
|
+
|
32
|
+
A decimal number.
|
33
|
+
|
34
|
+
```clojure
|
35
|
+
3.56
|
36
|
+
-0.5
|
37
|
+
```
|
38
|
+
|
39
|
+
### boolean
|
40
|
+
|
41
|
+
The value `true` or `false`.
|
42
|
+
|
43
|
+
```clojure
|
44
|
+
true
|
45
|
+
false
|
46
|
+
```
|
47
|
+
|
48
|
+
### nil
|
49
|
+
|
50
|
+
The "null" or "no value" type.
|
51
|
+
|
52
|
+
```clojure
|
53
|
+
nil
|
54
|
+
```
|
55
|
+
|
56
|
+
### text
|
57
|
+
|
58
|
+
Text of any length. There is a shorthand syntax that can be used when the
|
59
|
+
string does not contain any whitespace - this makes the syntax in `dict`s
|
60
|
+
nicer, for example.
|
61
|
+
|
62
|
+
It supports these escape characters:
|
63
|
+
|
64
|
+
- `\n` - a newline
|
65
|
+
- `\t` - a tab
|
66
|
+
- `\\` - a literal `\`
|
67
|
+
- `\"` - a literal `"`
|
68
|
+
|
69
|
+
```clojure
|
70
|
+
"some text" ; => "some text"
|
71
|
+
|
72
|
+
; Shorthand version
|
73
|
+
:text ; => "text"
|
74
|
+
|
75
|
+
; Using escape characters
|
76
|
+
;
|
77
|
+
; Note that they will still look escaped when returned in the REPL,
|
78
|
+
; however, if you print them you will get the literal text.
|
79
|
+
"text with \" and \\ in it" ; => "text with \" and \\ in it"
|
80
|
+
|
81
|
+
(println "text with \" and \\ in it")
|
82
|
+
; text with " and \ in it
|
83
|
+
```
|
84
|
+
|
85
|
+
### list
|
86
|
+
|
87
|
+
A heterogeneous (allows mixed types) list of values, can be created with the
|
88
|
+
[list](reference.md#list) function. This type is also used to call a
|
89
|
+
function. There is no difference between a list of data and a "list of code",
|
90
|
+
a.k.a. **form**.
|
91
|
+
|
92
|
+
```clojure
|
93
|
+
(list 1 2 :three) ; => (1 2 "three")
|
94
|
+
|
95
|
+
; The first item in the list will be called with the rest of the list as arguments:
|
96
|
+
(println "Hello, " "world!")
|
97
|
+
```
|
98
|
+
|
99
|
+
### dict
|
100
|
+
|
101
|
+
A dictionary (a.k.a. hash-map) of keys that map to values, can be created with
|
102
|
+
the [dict](reference.md#dict) function.
|
103
|
+
|
104
|
+
```clojure
|
105
|
+
; Here we use the shorthand text syntax as keys
|
106
|
+
(dict :one 1 :two 2) ; => {"one" 1, "two" 2}
|
107
|
+
```
|
108
|
+
|
109
|
+
### symbol
|
110
|
+
|
111
|
+
Used to name other things (see [def](reference.md#def)), but can be obtained in itself by
|
112
|
+
quoting (see [quote](reference.md#quote)).
|
113
|
+
|
114
|
+
Symbols should be lowercase, with words separated by dashes.
|
115
|
+
|
116
|
+
```clojure
|
117
|
+
; A symbol will resolve to what it has been defined as
|
118
|
+
symbol
|
119
|
+
|
120
|
+
; To obtain a symbol by itself, you have to quote it
|
121
|
+
'symbol
|
122
|
+
|
123
|
+
'a-long-symbol-name
|
124
|
+
```
|
125
|
+
|
126
|
+
## Ruby interoperability
|
127
|
+
|
128
|
+
You can access Ruby classes and modules, to access nested ones use `/`. To call
|
129
|
+
Ruby methods, simply prepend a dot to the method name, and pass the object as
|
130
|
+
the first parameter.
|
131
|
+
|
132
|
+
```clojure
|
133
|
+
(.ceil Math/PI) ; => 4
|
134
|
+
|
135
|
+
(.to_i "010101" 2) ; => 21
|
136
|
+
```
|
@@ -1,18 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
## Data types
|
4
|
-
|
5
|
-
| Data type | Example literals | Description |
|
6
|
-
| :--- | :--- | :--- |
|
7
|
-
| integer | `1`, `-42`, `0` | A whole number of any size |
|
8
|
-
| decimal | `3.56`, `-0.5` | A decimal number of any size |
|
9
|
-
| boolean | `true`, `false` | The value `true` or `false` |
|
10
|
-
| nil | `nil` | The "null" or "no value" type |
|
11
|
-
| text | `"some text"`, `:text` | Text of any length. When containing no whitespace, it can be written with a leading colon (handy in dicts) |
|
12
|
-
| list | `(list 1 2 3.5)` | A heterogeneous (allows mixed types) list of values, can be created with the [list](#list) function |
|
13
|
-
| dict | `(dict :one 1 :two 2)` | A dictionary (a.k.a. hash-map) of keys that map to values, can be created with the [dict](#dict) function |
|
14
|
-
| symbol | `symbol`, `'symbol` | Used to name other things (see [def](#def)), but can be obtained in itself by quoting (see [quote](#quote)) |
|
1
|
+
# Reference
|
15
2
|
|
3
|
+
This is a reference of all the functions you can call by default in any Läsp
|
4
|
+
program.
|
16
5
|
|
17
6
|
## Special forms
|
18
7
|
|
data/lib/lasp/interpreter.rb
CHANGED
@@ -35,7 +35,11 @@ module Lasp
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def resolve_symbol(symbol, env)
|
38
|
-
|
38
|
+
if symbol.to_s.match(/^[A-Z]/)
|
39
|
+
Object.const_get(symbol.to_s.gsub("/", "::"))
|
40
|
+
else
|
41
|
+
env.fetch(symbol)
|
42
|
+
end
|
39
43
|
rescue KeyError
|
40
44
|
raise NameError, "#{symbol} is not present in this context"
|
41
45
|
end
|
data/lib/lasp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lasp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Börjesson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -63,13 +63,14 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".travis.yml"
|
65
65
|
- CHANGELOG.md
|
66
|
-
- DOCUMENTATION.md
|
67
|
-
- EXAMPLES.md
|
68
66
|
- Gemfile
|
69
67
|
- LICENSE.txt
|
70
68
|
- README.md
|
71
69
|
- Rakefile
|
72
70
|
- bin/lasp
|
71
|
+
- docs/examples.md
|
72
|
+
- docs/language.md
|
73
|
+
- docs/reference.md
|
73
74
|
- lasp.gemspec
|
74
75
|
- lib/lasp.rb
|
75
76
|
- lib/lasp/corelib.rb
|