Module: SchemeLists
Overview
Instance Method Summary
collapse
#build_cons_from_list, #build_list, #car_cdr_infinite_helper, #car_cdr_values, #cons_helper, #evaluate_list, #find_all_values_list_evaluate, #find_idx_for_list, #find_list_function_value, #find_to_evaluate_or_not, #get_cons_values, #map_helper, #map_validate_helper, #no_eval_list, #split_list_as_string, #split_list_string
Instance Method Details
#car(other) ⇒ Object
126
127
128
129
130
|
# File 'lib/lisp/interpreter/core/list.rb', line 126
def car(other)
value = car_cdr_values other
raise 'Cannot apply car on ' + other[0].to_s if value.nil? || value.empty?
value.shift
end
|
#car_cdr_infinite(other) ⇒ Object
177
178
179
180
181
182
|
# File 'lib/lisp/interpreter/core/list.rb', line 177
def car_cdr_infinite(other)
fn = other[1]
values = find_all_values other[2..-2]
raise 'Incorrect number of arguments' unless values.size == 1
car_cdr_infinite_helper values[0], fn
end
|
#cdr(other) ⇒ Object
132
133
134
135
136
137
|
# File 'lib/lisp/interpreter/core/list.rb', line 132
def cdr(other)
value = car_cdr_values other
raise 'Cannot apply cdr on ' + other[0].to_s if value.nil? || value.empty?
idx = value[1] == '.' ? 2 : 1
build_list value[idx..-1]
end
|
#cons(other) ⇒ Object
117
118
119
120
|
# File 'lib/lisp/interpreter/core/list.rb', line 117
def cons(other)
raise arg_err_build 2, other.size if other.size != 2
cons_helper other
end
|
#length(other) ⇒ Object
155
156
157
|
# File 'lib/lisp/interpreter/core/list.rb', line 155
def length(other)
(find_list_function_value other).size
end
|
#list(other) ⇒ Object
122
123
124
|
# File 'lib/lisp/interpreter/core/list.rb', line 122
def list(other)
build_list other
end
|
#list?(other) ⇒ Boolean
139
140
141
142
|
# File 'lib/lisp/interpreter/core/list.rb', line 139
def list?(other)
raise arg_err_build 1, other.size if other.size != 1
other[0].to_s.list? ? '#t' : '#f'
end
|
#map(other) ⇒ Object
164
165
166
167
168
169
170
|
# File 'lib/lisp/interpreter/core/list.rb', line 164
def map(other)
func, other = map_validate_helper other
lst = find_all_values other
lst = lst.map { |t| find_list_function_value [t] }
lst = (equalize_lists lst).transpose
build_list map_helper lst, func
end
|
#null?(other) ⇒ Boolean
149
150
151
152
153
|
# File 'lib/lisp/interpreter/core/list.rb', line 149
def null?(other)
raise arg_err_build 1, other.size if other.size != 1
return '#f' unless other[0].to_s.list?
other[0].to_s.size == 3 ? '#t' : '#f'
end
|
#pair?(other) ⇒ Boolean
144
145
146
147
|
# File 'lib/lisp/interpreter/core/list.rb', line 144
def pair?(other)
raise arg_err_build 1, other.size if other.size != 1
other[0].to_s.pair? ? '#t' : '#f'
end
|
#reverse(other) ⇒ Object
159
160
161
162
|
# File 'lib/lisp/interpreter/core/list.rb', line 159
def reverse(other)
value = find_list_function_value other
build_list value.reverse
end
|
#shuffle(other) ⇒ Object
172
173
174
175
|
# File 'lib/lisp/interpreter/core/list.rb', line 172
def shuffle(other)
values = find_list_function_value other
build_list values.shuffle
end
|