cons 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cons.rb +196 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f805721ecfb3bf54166c7b54683bdbf5381618c6
|
4
|
+
data.tar.gz: dcb41ae9a86ec64045f5327ee33cecc650ff01e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c41095b955c9a93b94c6b2e76d970ba0fec7b1216d9f78f8da3ec287d7e3f3615a6f7c1207f04e3d82328f6cc88f5cd0052f113bc99729257d251a4f994c8f2
|
7
|
+
data.tar.gz: 79c1b01c1c8282d0fcb30d13bf064b706103855f99edd9a3d3d81c3c48aa347b6f8aec7cee6b8b86216440903d7ada17044b898c8cb69f840f40d9644b065da4
|
data/lib/cons.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# -*- mode: Ruby -*-
|
3
|
+
|
4
|
+
# Copyright © 2016, Christopher Mark Gore,
|
5
|
+
# Soli Deo Gloria,
|
6
|
+
# All rights reserved.
|
7
|
+
#
|
8
|
+
# 2317 South River Road, Saint Charles, Missouri 63303 USA.
|
9
|
+
# Web: http://cgore.com
|
10
|
+
# Email: cgore@cgore.com
|
11
|
+
#
|
12
|
+
# Redistribution and use in source and binary forms, with or without
|
13
|
+
# modification, are permitted provided that the following conditions are met:
|
14
|
+
#
|
15
|
+
# * Redistributions of source code must retain the above copyright
|
16
|
+
# notice, this list of conditions and the following disclaimer.
|
17
|
+
#
|
18
|
+
# * Redistributions in binary form must reproduce the above copyright
|
19
|
+
# notice, this list of conditions and the following disclaimer in the
|
20
|
+
# documentation and/or other materials provided with the distribution.
|
21
|
+
#
|
22
|
+
# * Neither the name of Christopher Mark Gore nor the names of other
|
23
|
+
# contributors may be used to endorse or promote products derived from
|
24
|
+
# this software without specific prior written permission.
|
25
|
+
#
|
26
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
27
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
28
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
29
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
30
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
31
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
32
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
33
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
34
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
35
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
36
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
37
|
+
|
38
|
+
class Array
|
39
|
+
def to_cons
|
40
|
+
Cons.from_array self
|
41
|
+
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
def from_cons cons
|
45
|
+
cons.to_a
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Cons
|
51
|
+
attr_accessor :car, :cdr
|
52
|
+
|
53
|
+
def initialize car=nil, cdr=nil
|
54
|
+
@car, @cdr = car, cdr
|
55
|
+
end
|
56
|
+
|
57
|
+
def ==(rhs)
|
58
|
+
rhs.kind_of? Cons and car == rhs.car and cdr == rhs.cdr
|
59
|
+
end
|
60
|
+
|
61
|
+
alias first car
|
62
|
+
alias first= car=
|
63
|
+
alias rest cdr
|
64
|
+
alias rest= cdr=
|
65
|
+
|
66
|
+
def nthcdr n
|
67
|
+
if not n.kind_of? Integer or n < 0
|
68
|
+
raise ArgumentError, "n for nthcdr must be a non-negative integer"
|
69
|
+
elsif n == 1
|
70
|
+
self
|
71
|
+
elsif n > 1
|
72
|
+
if cdr.nil?
|
73
|
+
nil
|
74
|
+
else
|
75
|
+
cdr.nthcdr n-1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def nth n
|
81
|
+
i = nthcdr n
|
82
|
+
if i.nil?
|
83
|
+
nil
|
84
|
+
else
|
85
|
+
nthcdr(n).car
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def nth_eq(n, value)
|
90
|
+
puts "nth= n=#{n} value=#{value}"
|
91
|
+
i = nthcdr(n)
|
92
|
+
if i.nil?
|
93
|
+
raise RuntimeError
|
94
|
+
else
|
95
|
+
nthcdr(n).car= value
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def first
|
100
|
+
car
|
101
|
+
end
|
102
|
+
|
103
|
+
def first_eq value
|
104
|
+
@car = value
|
105
|
+
end
|
106
|
+
|
107
|
+
[[:second, 2],
|
108
|
+
[:third, 3],
|
109
|
+
[:fourth, 4],
|
110
|
+
[:fifth, 5],
|
111
|
+
[:sixth, 6],
|
112
|
+
[:seventh, 7],
|
113
|
+
[:eighth, 8],
|
114
|
+
[:ninth, 9],
|
115
|
+
[:tenth, 10]].each do |fname, i|
|
116
|
+
class_eval %{
|
117
|
+
def #{fname}
|
118
|
+
nth #{i}
|
119
|
+
end
|
120
|
+
|
121
|
+
def #{fname}=(value)
|
122
|
+
nth_eq(#{i}, value)
|
123
|
+
end
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
["aa",
|
128
|
+
"ad",
|
129
|
+
"da",
|
130
|
+
"dd",
|
131
|
+
"aaa",
|
132
|
+
"aad",
|
133
|
+
"ada",
|
134
|
+
"add",
|
135
|
+
"daa",
|
136
|
+
"dad",
|
137
|
+
"dda",
|
138
|
+
"ddd",
|
139
|
+
"aaaa",
|
140
|
+
"aaad",
|
141
|
+
"aada",
|
142
|
+
"aadd",
|
143
|
+
"adaa",
|
144
|
+
"adad",
|
145
|
+
"adda",
|
146
|
+
"addd",
|
147
|
+
"daaa",
|
148
|
+
"daad",
|
149
|
+
"dada",
|
150
|
+
"dadd",
|
151
|
+
"ddaa",
|
152
|
+
"ddad",
|
153
|
+
"ddda",
|
154
|
+
"dddd"].each do |middle|
|
155
|
+
path = middle.split("").map {|i| "c#{i}r"}.join "."
|
156
|
+
fname = "c#{middle}r"
|
157
|
+
class_eval %{
|
158
|
+
def #{fname}
|
159
|
+
#{path}
|
160
|
+
end
|
161
|
+
|
162
|
+
def #{fname}= value
|
163
|
+
#{path}= value
|
164
|
+
end
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
def to_a
|
169
|
+
if not car or car.nil?
|
170
|
+
[]
|
171
|
+
elsif not cdr or cdr.nil?
|
172
|
+
[car]
|
173
|
+
else
|
174
|
+
[car] + cdr.to_a
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class << self
|
179
|
+
def from_array array, initial=true
|
180
|
+
car, *cdr = array
|
181
|
+
if car.nil?
|
182
|
+
if initial
|
183
|
+
self[nil, nil]
|
184
|
+
else
|
185
|
+
nil
|
186
|
+
end
|
187
|
+
else
|
188
|
+
self[car, from_array(cdr, false)]
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def [] car=nil, cdr=nil
|
193
|
+
new car, cdr
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Mark Gore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Teepee is a markup language, loosely based on Lisp and TeX, for ThinkingBicycle.com.
|
28
|
+
email: cgore@cgore.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/cons.rb
|
34
|
+
homepage: https://github.com/cgore/ruby-cons
|
35
|
+
licenses: []
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.4.5.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Teepee is a markup language for ThinkingBicycle.com.
|
57
|
+
test_files: []
|