yarlisp 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/README.md +93 -0
- data/Rakefile +1 -0
- data/lib/yarlisp.rb +5 -0
- data/lib/yarlisp/version.rb +3 -0
- data/script/test +35 -0
- data/yarlisp.gemspec +24 -0
- metadata +66 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@yarlisp
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yarlisp (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rspec (2.7.0)
|
11
|
+
rspec-core (~> 2.7.0)
|
12
|
+
rspec-expectations (~> 2.7.0)
|
13
|
+
rspec-mocks (~> 2.7.0)
|
14
|
+
rspec-core (2.7.0)
|
15
|
+
rspec-expectations (2.7.0)
|
16
|
+
diff-lcs (~> 1.1.2)
|
17
|
+
rspec-mocks (2.7.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
rspec
|
24
|
+
yarlisp!
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# YARLISP #
|
2
|
+
|
3
|
+
## What is it and a brief history. ##
|
4
|
+
|
5
|
+
Yet Another Ruby Lisp.
|
6
|
+
|
7
|
+
(I assume that other people have implemented Lisp in ruby so...)
|
8
|
+
|
9
|
+
After reading [McCarthy's Paper][paper] for one of the
|
10
|
+
[Boston Software Crafstmanship Meetups][bossoftcraft] I decided to try to expand my limited
|
11
|
+
knowledge of Ruby by implmenting this Lisp.
|
12
|
+
|
13
|
+
That attempt failed - I even deleted the GitHub repository for it.
|
14
|
+
|
15
|
+
I hope that this attempt works better.
|
16
|
+
|
17
|
+
## The relevant parts of the paper: ##
|
18
|
+
|
19
|
+
Snippets from McCarthy's paper:
|
20
|
+
|
21
|
+
The Elementary S-functions and Predicates. We introduce the following
|
22
|
+
functions and predicates:
|
23
|
+
|
24
|
+
1. atom. `atom[x]` has the value of T or F according to whether x is an atomic symbol. Thus
|
25
|
+
|
26
|
+
atom [X] = T
|
27
|
+
atom [(X . A)] = F
|
28
|
+
|
29
|
+
2. eq. `eq [x;y]` is defined if and only if both x and y are atomic. `eq [x; y] = T` if x and y are the same symbol, and `eq [x; y] = F` otherwise. Thus
|
30
|
+
|
31
|
+
eq [X; X] = T
|
32
|
+
eq [X; A] = F
|
33
|
+
eq [X; (X . A)] is undefined
|
34
|
+
|
35
|
+
3. car. `car[x]` is defined if and only if x is not atomic.
|
36
|
+
|
37
|
+
car [(e1 . e2)] = e1
|
38
|
+
|
39
|
+
Thus `car [X]` is undefined.
|
40
|
+
|
41
|
+
car [(X . A)] = X
|
42
|
+
car [((X . A) . Y )] = (X . A)
|
43
|
+
|
44
|
+
4. cdr. `cdr [x]` is also defined when x is not atomic. We have `cdr [(e1 . e2)]= e2`. Thus cdr [X] is undefined.
|
45
|
+
|
46
|
+
cdr [(X . A)] = A
|
47
|
+
cdr [((X . A) . Y )] = Y
|
48
|
+
|
49
|
+
5. cons. `cons [x; y]` is defined for any x and y. We have `cons [e1; e2] = (e1 . e2`). Thus
|
50
|
+
|
51
|
+
cons [X; A] = (X A)
|
52
|
+
cons [(X . A); Y ] = ((X . A) Y )
|
53
|
+
|
54
|
+
car, cdr, and cons are easily seen to satisfy the relations
|
55
|
+
|
56
|
+
car [cons [x; y]] = x
|
57
|
+
cdr [cons [x; y]] = y
|
58
|
+
cons [car [x]; cdr [x]] = x, provided that x is not atomic.
|
59
|
+
|
60
|
+
The S-function apply is defined by
|
61
|
+
|
62
|
+
apply[f; args] = eval[cons[f; appq[args]];NIL],
|
63
|
+
|
64
|
+
where
|
65
|
+
|
66
|
+
appq[m] = [null[m] ! NIL; T ! cons[list[QUOTE; car[m]]; appq[cdr[m]]]]
|
67
|
+
|
68
|
+
and
|
69
|
+
|
70
|
+
eval[e; a] = [
|
71
|
+
atom [e] ! assoc [e; a];
|
72
|
+
atom [car [e]] ! [
|
73
|
+
eq [car [e]; QUOTE] ! cadr [e];
|
74
|
+
eq [car [e]; ATOM] ! atom [eval [cadr [e]; a]];
|
75
|
+
eq [car [e]; EQ] ! [eval [cadr [e]; a] = eval [caddr [e]; a]];
|
76
|
+
eq [car [e]; COND] ! evcon [cdr [e]; a];
|
77
|
+
eq [car [e]; CAR] ! car [eval [cadr [e]; a]];
|
78
|
+
eq [car [e]; CDR] ! cdr [eval [cadr [e]; a]];
|
79
|
+
eq [car [e]; CONS] ! cons [eval [cadr [e]; a]; eval [caddr [e]; a]];
|
80
|
+
T ! eval [cons [assoc [car [e]; a]; evlis [cdr [e]; a]]; a]];
|
81
|
+
eq [caar [e]; LABEL] ! eval [cons [caddar [e]; cdr [e]]; cons [list [cadar [e]; car [e]; a]];
|
82
|
+
eq [caar [e]; LAMBDA] ! eval [caddar [e]; append [pair [cadar [e]; evlis [cdr [e]; a]; a]]]
|
83
|
+
|
84
|
+
and
|
85
|
+
|
86
|
+
evcon[c; a] = [eval[caar[c]; a] ! eval[cadar[c]; a]; T ! evcon[cdr[c]; a]]
|
87
|
+
|
88
|
+
and
|
89
|
+
|
90
|
+
evlis[m; a] = [null[m] ! NIL; T ! cons[eval[car[m]; a]; evlis[cdr[m]; a]]]
|
91
|
+
|
92
|
+
[paper]: <http://www-formal.stanford.edu/jmc/recursive.pdf>
|
93
|
+
[bossoftcraft]: <http://groups.google.com/group/boston-software-craftsmanship?pli=1>
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/yarlisp.rb
ADDED
data/script/test
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# From Destroy All Software screencast #10, at:
|
4
|
+
# http://destroyallsoftware.com/screencasts/catalog/fast-tests-with-and-without-rails
|
5
|
+
#
|
6
|
+
# Put this in the script/ directory of your Rails app, then run it with a spec
|
7
|
+
# filename. If the spec uses spec_helper, it'll be run inside Bundler.
|
8
|
+
# Otherwise, it'll be run directly with whatever `rspec` executable is on the
|
9
|
+
# path.
|
10
|
+
|
11
|
+
set -e
|
12
|
+
|
13
|
+
need_rails=1
|
14
|
+
|
15
|
+
if [ $# -gt 0 ]; then # we have args
|
16
|
+
filename=$1
|
17
|
+
# Remove trailing line numbers from filename, e.g. spec/my_spec.rb:33
|
18
|
+
grep_filename=`echo $1 | sed 's/:.*$//g'`
|
19
|
+
|
20
|
+
(set +e; grep -r 'spec_helper' $grep_filename) > /dev/null
|
21
|
+
if [ $? -eq 1 ]; then # no match; we have a stand-alone spec
|
22
|
+
need_rails=''
|
23
|
+
fi
|
24
|
+
else # we have no args
|
25
|
+
filename='spec'
|
26
|
+
fi
|
27
|
+
|
28
|
+
command='rspec'
|
29
|
+
|
30
|
+
if [ $need_rails ]; then
|
31
|
+
command="ruby -S bundle exec $command"
|
32
|
+
fi
|
33
|
+
|
34
|
+
RAILS_ENV=test $command $filename
|
35
|
+
|
data/yarlisp.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yarlisp/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yarlisp"
|
7
|
+
s.version = Yarlisp::VERSION
|
8
|
+
s.authors = ["Mark Simpson"]
|
9
|
+
s.email = ["verdammelt@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A toy implementation of McCarthy's LISP in Ruby.}
|
12
|
+
s.description = %q{I must assume that someone has already implmented Lisp in Ruby and thus I name this 'Yet Another Ruby Lisp"}
|
13
|
+
|
14
|
+
s.rubyforge_project = "yarlisp"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yarlisp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Simpson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2157015400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157015400
|
25
|
+
description: I must assume that someone has already implmented Lisp in Ruby and thus
|
26
|
+
I name this 'Yet Another Ruby Lisp"
|
27
|
+
email:
|
28
|
+
- verdammelt@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .rvmrc
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/yarlisp.rb
|
39
|
+
- lib/yarlisp/version.rb
|
40
|
+
- script/test
|
41
|
+
- yarlisp.gemspec
|
42
|
+
homepage: ''
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: yarlisp
|
62
|
+
rubygems_version: 1.8.10
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: A toy implementation of McCarthy's LISP in Ruby.
|
66
|
+
test_files: []
|