Module: FunctionalScheme
Overview
Functional programming main functions
Instance Method Summary
collapse
#arg_finder, #arg_finder_helper, #define_func_helper, #define_function, #define_var, #equalize_lists, #eval_lambda, #fetch_define, #find_params_lambda, #foldl_helper, #foldr_helper, #member_helper, #proc_lambda, #proc_lambda_helper, #set_values_define
Methods included from Optimize
#apply_helper, #build_compose_expr, #call_compose, #call_compose_helper, #do_not_call_compose, #fetch_inner_scope, #filter_helper, #fold_values_helper, #get_fold_values, #inner_scope_replace, #rm_from_in_scope
Instance Method Details
#apply(other) ⇒ Object
249
250
251
252
253
254
255
256
257
|
# File 'lib/lisp/interpreter/functional.rb', line 249
def apply(other)
raise 'Incorrect number of arguments' if other.nil? || other.empty?
func, other = valid_function other
values = find_all_values other
*vs, lst = values
raise 'Incorrect data type' unless lst.list?
(find_list_function_value [lst]).each { |t| vs << t }
apply_helper func, vs
end
|
#compose(other) ⇒ Object
259
260
261
262
263
264
265
|
# File 'lib/lisp/interpreter/functional.rb', line 259
def compose(other)
if other[0] != 'compose'
do_not_call_compose other
else
call_compose other
end
end
|
#define(other) ⇒ Object
275
276
277
278
|
# File 'lib/lisp/interpreter/functional.rb', line 275
def define(other)
raise 'Incorrect number of arguments' if other.size < 2
fetch_define other
end
|
#filter(other) ⇒ Object
223
224
225
226
227
228
229
230
|
# File 'lib/lisp/interpreter/functional.rb', line 223
def filter(other)
raise 'Incorrect number of parameters' if other.size < 2
func, other = valid_function other
raise 'Incorrect number of parameters' if other.empty?
values = find_all_values other
values = find_list_function_value [values[0]]
filter_helper func, values
end
|
#foldl(other) ⇒ Object
209
210
211
212
213
214
|
# File 'lib/lisp/interpreter/functional.rb', line 209
def foldl(other)
raise 'Incorrect number of parameters' if other.size < 2
func, other = valid_function other
val_one, val_two = get_fold_values other
foldl_helper func, val_one, val_two
end
|
#foldr(other) ⇒ Object
216
217
218
219
220
221
|
# File 'lib/lisp/interpreter/functional.rb', line 216
def foldr(other)
raise 'Incorrect number of parameters' if other.size < 2
func, other = valid_function other
val_one, val_two = get_fold_values other
foldr_helper func, val_one, val_two
end
|
#lambda(other) ⇒ Object
267
268
269
270
271
272
273
|
# File 'lib/lisp/interpreter/functional.rb', line 267
def lambda(other)
if other[0] == 'lambda'
eval_lambda other[1..-1]
else
proc_lambda other
end
end
|
#member(other) ⇒ Object
232
233
234
235
236
237
238
239
|
# File 'lib/lisp/interpreter/functional.rb', line 232
def member(other)
raise 'Incorrect number of arguments' unless other.size == 2
to_check = other[0]
split_val = split_list_string other[1]
raise 'Invalid argument' unless split_val.pair? || split_val.list?
values = find_all_values split_val[2..-2]
member_helper to_check, values
end
|
#remove(other) ⇒ Object
241
242
243
244
245
246
247
|
# File 'lib/lisp/interpreter/functional.rb', line 241
def remove(other)
raise 'Incorrect number of arguments' unless other.size == 2
to_remove = other[0]
values = find_list_function_value [other[1]]
values.delete_at(values.index(to_remove) || values.length)
build_list values
end
|