ruspea_lang 0.1.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +183 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/ruspea +8 -0
- data/lib/example.rb +10 -0
- data/lib/example.rsp +23 -0
- data/lib/language/standard.rsp +77 -0
- data/lib/ruspea.rb +9 -0
- data/lib/ruspea/code.rb +19 -0
- data/lib/ruspea/error/arity.rb +7 -0
- data/lib/ruspea/error/resolution.rb +7 -0
- data/lib/ruspea/error/standard.rb +3 -0
- data/lib/ruspea/error/syntax.rb +4 -0
- data/lib/ruspea/interpreter/evaler.rb +67 -0
- data/lib/ruspea/interpreter/form.rb +27 -0
- data/lib/ruspea/interpreter/reader.rb +127 -0
- data/lib/ruspea/language/core.rb +185 -0
- data/lib/ruspea/language/ruby.rb +36 -0
- data/lib/ruspea/printer.rb +54 -0
- data/lib/ruspea/repl/loop.rb +85 -0
- data/lib/ruspea/repl/repl.rsp +2 -0
- data/lib/ruspea/runtime/env.rb +119 -0
- data/lib/ruspea/runtime/fn.rb +23 -0
- data/lib/ruspea/runtime/list.rb +67 -0
- data/lib/ruspea/runtime/lm.rb +74 -0
- data/lib/ruspea/runtime/nill.rb +54 -0
- data/lib/ruspea/runtime/sym.rb +28 -0
- data/lib/ruspea/version.rb +3 -0
- data/lib/ruspea_lang.rb +4 -0
- data/ruspea.gemspec +31 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d980cd9fd209da6b5677dfd64cc160162d7b8b884237ba73802434c3dcef85eb
|
4
|
+
data.tar.gz: 8079ac9c2e75dc14a1f4d619909e0c570c09fdd23a7e2f732d453c9110ff15bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ba192a000bc070ab3d33eb960606626d15782a9637b349c483951084b5cb4f0c901b24e0793a18628f249696b2e281f734649bc9c173b3c9e11af3d97d6a3ea
|
7
|
+
data.tar.gz: 949259c3771dc15795d85c243c2773ceebb6b00baf12879ab7aaba371f206124d7c6ed5b2d01b64aadfcc2f45389d96149ed6a8c4f09cf1fc1d7b066ace2a628
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruspea_lang (0.1.1)
|
5
|
+
zeitwerk
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
byebug (11.0.1)
|
11
|
+
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
method_source (0.9.2)
|
14
|
+
pry (0.12.2)
|
15
|
+
coderay (~> 1.1.0)
|
16
|
+
method_source (~> 0.9.0)
|
17
|
+
pry-byebug (3.7.0)
|
18
|
+
byebug (~> 11.0)
|
19
|
+
pry (~> 0.10)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.8.0)
|
22
|
+
rspec-core (~> 3.8.0)
|
23
|
+
rspec-expectations (~> 3.8.0)
|
24
|
+
rspec-mocks (~> 3.8.0)
|
25
|
+
rspec-core (3.8.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-expectations (3.8.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-mocks (3.8.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-support (3.8.0)
|
34
|
+
zeitwerk (2.1.9)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 2.0)
|
41
|
+
pry-byebug
|
42
|
+
rake (~> 10.0)
|
43
|
+
rspec (~> 3.0)
|
44
|
+
ruspea_lang!
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ricardo Valeriano
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# Ruspea
|
2
|
+
|
3
|
+
A Lisp dialect written in Ruby (and on itself)
|
4
|
+
meant to be used as a standard Ruby gem.
|
5
|
+
|
6
|
+
So if anyone asks:
|
7
|
+
|
8
|
+
> What is this Ruspea thing on the Gemfile?
|
9
|
+
|
10
|
+
You can go:
|
11
|
+
|
12
|
+
> Nah. Just a gem.
|
13
|
+
|
14
|
+
Then you can sneak in code like this in your project
|
15
|
+
|
16
|
+
```lisp
|
17
|
+
(def %fib
|
18
|
+
(fn [n]
|
19
|
+
(cond
|
20
|
+
((= n 0) n)
|
21
|
+
((= n 1) n)
|
22
|
+
(true
|
23
|
+
(+
|
24
|
+
(%fib (- n 1))
|
25
|
+
(%fib (- n 2)))))))
|
26
|
+
```
|
27
|
+
|
28
|
+
And execute it from Ruby like:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Ruspea::Code.new.load("my/awesome/ruspea/script.rsp")
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also bypass the file loading:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require "ruspea-lang"
|
38
|
+
|
39
|
+
code = <<~c
|
40
|
+
(def plus1
|
41
|
+
(fn [num] (+ num 1)))
|
42
|
+
(plus1 10)
|
43
|
+
c
|
44
|
+
|
45
|
+
eleven = Ruspea::Code.new.run(code).last
|
46
|
+
puts eleven # => 11
|
47
|
+
```
|
48
|
+
|
49
|
+
## Is this a functional language? Is it interpreted?
|
50
|
+
|
51
|
+
Yes.
|
52
|
+
|
53
|
+
## Does it have a REPL?
|
54
|
+
|
55
|
+
YES! After install it as a gem (`gem install ruspea_lang`),
|
56
|
+
just go ahead and:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
➜ ruspea
|
60
|
+
loading repl: repl.rsp
|
61
|
+
repl loaded.
|
62
|
+
|
63
|
+
#user=> (def lol 1)
|
64
|
+
1
|
65
|
+
#user=> lol
|
66
|
+
1
|
67
|
+
#user=> (puts "hello world")
|
68
|
+
hello world
|
69
|
+
nil
|
70
|
+
#user=> ^CSee you soon.
|
71
|
+
```
|
72
|
+
|
73
|
+
## Humm... but what about the Ruby stuff? The gems?! HUH!?
|
74
|
+
|
75
|
+
Ruspea has Ruby interoperabillity built-in
|
76
|
+
so you can "just use" Ruby:
|
77
|
+
|
78
|
+
```lisp
|
79
|
+
(def puts
|
80
|
+
(fn [str]
|
81
|
+
(.
|
82
|
+
(:: Kernel) puts str)))
|
83
|
+
```
|
84
|
+
|
85
|
+
In fact, the very minimal standard library is
|
86
|
+
built on top of this interop capability.
|
87
|
+
It is also the best source to look for usage/syntax/etc right now:
|
88
|
+
[`lib/language/standard.rsp`](https://github.com/mistersourcerer/ruspea/blob/master/lib/language/standard.rsp)
|
89
|
+
|
90
|
+
### OH! I see! This was inspired by Clojure?
|
91
|
+
|
92
|
+
100%!
|
93
|
+
|
94
|
+
### OH! I see! Is this as good as Clojure!?
|
95
|
+
|
96
|
+

|
97
|
+
|
98
|
+
## Why would I use that, though? All those parenthesis...
|
99
|
+
|
100
|
+
This is the actual question, isn't it?
|
101
|
+
Sadly this is way out of the scope of this README.
|
102
|
+
|
103
|
+
You will need to convince yourself here. 😬
|
104
|
+
|
105
|
+
## Is this ready for production usage?
|
106
|
+
|
107
|
+
Nope.
|
108
|
+
And it will probably never be.
|
109
|
+
|
110
|
+
This was just an exercise:
|
111
|
+
|
112
|
+
- Ruby is really fun.
|
113
|
+
- Lisp too.
|
114
|
+
- I am really (I mean REALLY) enjoying Clojure.
|
115
|
+
- And I really wanted to learn how to implemente a programming language.
|
116
|
+
- Lists are a great way to organize thoughts.
|
117
|
+
|
118
|
+
If you put all this together you have this project.
|
119
|
+
|
120
|
+
## Shortcomings
|
121
|
+
|
122
|
+
Actually, I would prefer to avoid the term ~~shortcomings~~.
|
123
|
+
|
124
|
+
The current social norm forces impossible standards
|
125
|
+
on everyone and everything!
|
126
|
+
|
127
|
+
I want to list the things I know are not perfect
|
128
|
+
about this pretty little thing called Ruspea
|
129
|
+
and I don't want to hurt it's feelings.
|
130
|
+
|
131
|
+
Let's call those rough edges... *features*.
|
132
|
+
Those are enhancements that are not here... just yet 😬.
|
133
|
+
|
134
|
+

|
135
|
+
|
136
|
+
### Features
|
137
|
+
|
138
|
+
- No performance! Seriously. There is no optmization whatsoever to see here.
|
139
|
+
- No TCO. Goes hand to hand with the previous one.
|
140
|
+
- No standard library.
|
141
|
+
- No multi-arity functions.
|
142
|
+
They are in the Runtime though. Just to lazy to build the syntax reader for each right now.
|
143
|
+
- No examples. Besides the "standard library" ones ([`lib/language`](https://github.com/mistersourcerer/ruspea/blob/master/lib/language/standard.rsp))
|
144
|
+
|
145
|
+
## Installation
|
146
|
+
|
147
|
+
Add this line to your application's Gemfile:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
gem "ruspea_lang"
|
151
|
+
```
|
152
|
+
|
153
|
+
And then execute:
|
154
|
+
|
155
|
+
$ bundle
|
156
|
+
|
157
|
+
Or install it yourself as:
|
158
|
+
|
159
|
+
$ gem install ruspea_lang
|
160
|
+
|
161
|
+
|
162
|
+
### Why not just ruspea? Do we really need a `_lang` suffix?!
|
163
|
+
|
164
|
+
Yes, we do:
|
165
|
+
|
166
|
+
```
|
167
|
+
Pushing gem to https://rubygems.org...
|
168
|
+
There was a problem saving your gem: Name 'ruspea' is too close to typo-protected gem: rspec
|
169
|
+
```
|
170
|
+
|
171
|
+
## Development
|
172
|
+
|
173
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
174
|
+
|
175
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
176
|
+
|
177
|
+
## Contributing
|
178
|
+
|
179
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mistersourcerer/ruspea.
|
180
|
+
|
181
|
+
## License
|
182
|
+
|
183
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruspea"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/ruspea
ADDED
data/lib/example.rb
ADDED
data/lib/example.rsp
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
(def %zerify
|
2
|
+
(fn [n]
|
3
|
+
(cond
|
4
|
+
((= n 0)
|
5
|
+
(puts "-- end --"))
|
6
|
+
(true
|
7
|
+
(puts n)
|
8
|
+
(puts "--")
|
9
|
+
(cond
|
10
|
+
((> n 10) (puts "not yet..."))
|
11
|
+
(true (puts "almost there"))
|
12
|
+
)
|
13
|
+
(%zerify (- n 1))))))
|
14
|
+
|
15
|
+
(def %fib
|
16
|
+
(fn [n]
|
17
|
+
(cond
|
18
|
+
((= n 0) n)
|
19
|
+
((= n 1) n)
|
20
|
+
(true
|
21
|
+
(+
|
22
|
+
(%fib (- n 1))
|
23
|
+
(%fib (- n 2)))))))
|
@@ -0,0 +1,77 @@
|
|
1
|
+
(def puts
|
2
|
+
(fn [str]
|
3
|
+
(.
|
4
|
+
(:: Kernel) puts str)))
|
5
|
+
|
6
|
+
(def cons
|
7
|
+
(fn [el list]
|
8
|
+
(. list cons el)))
|
9
|
+
|
10
|
+
(def head
|
11
|
+
(fn [list]
|
12
|
+
(. list head)))
|
13
|
+
|
14
|
+
(def tail
|
15
|
+
(fn [list]
|
16
|
+
(. list tail)))
|
17
|
+
|
18
|
+
(def empty?
|
19
|
+
(fn [list]
|
20
|
+
(. list empty?)))
|
21
|
+
|
22
|
+
(def take
|
23
|
+
(fn [num list]
|
24
|
+
(. list take num)))
|
25
|
+
|
26
|
+
(def =
|
27
|
+
(fn [lhs rhs]
|
28
|
+
(cond
|
29
|
+
((. lhs == rhs) true)
|
30
|
+
(true false))))
|
31
|
+
|
32
|
+
(def !=
|
33
|
+
(fn [lhs rhs]
|
34
|
+
(cond
|
35
|
+
((. lhs != rhs) true)
|
36
|
+
(true false))))
|
37
|
+
|
38
|
+
(def >
|
39
|
+
(fn [lhs rhs]
|
40
|
+
(cond
|
41
|
+
((. lhs > rhs) true)
|
42
|
+
(true false))))
|
43
|
+
|
44
|
+
(def <
|
45
|
+
(fn [lhs rhs]
|
46
|
+
(cond
|
47
|
+
((. lhs > rhs) true)
|
48
|
+
(true false))))
|
49
|
+
|
50
|
+
(def +
|
51
|
+
(fn [lhs rhs]
|
52
|
+
(. lhs + rhs)))
|
53
|
+
|
54
|
+
(def -
|
55
|
+
(fn [lhs rhs]
|
56
|
+
(. lhs - rhs)))
|
57
|
+
|
58
|
+
(def /
|
59
|
+
(fn [lhs rhs]
|
60
|
+
(. lhs / rhs)))
|
61
|
+
|
62
|
+
(def *
|
63
|
+
(fn [lhs rhs]
|
64
|
+
(. lhs * rhs)))
|
65
|
+
|
66
|
+
(def read
|
67
|
+
(fn [code]
|
68
|
+
(def reader (. (:: Ruspea::Interpreter::Reader) new))
|
69
|
+
(def code_and_forms (. reader call code))
|
70
|
+
(. code_and_forms "[]" 1)))
|
71
|
+
|
72
|
+
(def load
|
73
|
+
(fn [path]
|
74
|
+
(puts (. "reading from " << path))
|
75
|
+
(eval
|
76
|
+
(read (. (:: File) read path))
|
77
|
+
(%ctx %ctx))))
|