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, #define_var_stl, #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
262
263
264
265
266
267
268
|
# File 'lib/lisp/interpreter/core/functional.rb', line 262
def apply(other)
raise arg_err_build 'at least 2', 0 if other.nil? || other.empty?
func, other = valid_function other
raise arg_err_build 'at least 2', 1 if other.empty?
values = find_all_values other
apply_helper func, values
end
|
#compose(other) ⇒ Object
270
271
272
273
274
275
276
|
# File 'lib/lisp/interpreter/core/functional.rb', line 270
def compose(other)
if other[0] != 'compose'
do_not_call_compose other
else
call_compose other
end
end
|
#define(other) ⇒ Object
286
287
288
289
|
# File 'lib/lisp/interpreter/core/functional.rb', line 286
def define(other)
raise arg_err_build 2, other.size if other.size < 2
fetch_define other
end
|
#filter(other) ⇒ Object
236
237
238
239
240
241
242
243
|
# File 'lib/lisp/interpreter/core/functional.rb', line 236
def filter(other)
raise arg_err_build 2, other.size if other.size < 2
func, other = valid_function other
raise arg_err_build 2, 1 if other.empty?
values = find_all_values other
values = find_list_function_value [values[0]]
filter_helper func, values
end
|
#foldl(other) ⇒ Object
222
223
224
225
226
227
|
# File 'lib/lisp/interpreter/core/functional.rb', line 222
def foldl(other)
raise arg_err_build 'at least 2', other.size 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
229
230
231
232
233
234
|
# File 'lib/lisp/interpreter/core/functional.rb', line 229
def foldr(other)
raise arg_err_build 'at least 2', other.size 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
278
279
280
281
282
283
284
|
# File 'lib/lisp/interpreter/core/functional.rb', line 278
def lambda(other)
if other[0] == 'lambda'
eval_lambda other[1..-1]
else
proc_lambda other
end
end
|
#member(other) ⇒ Object
245
246
247
248
249
250
251
252
|
# File 'lib/lisp/interpreter/core/functional.rb', line 245
def member(other)
raise arg_err_build 2, other.size 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
254
255
256
257
258
259
260
|
# File 'lib/lisp/interpreter/core/functional.rb', line 254
def remove(other)
raise arg_err_build 2, other.size 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
|