module FunctionalScheme

Functional programming main functions

Public Instance Methods

apply(other) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 265
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) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 273
def compose(other)
  if other[0] != 'compose'
    do_not_call_compose other
  else
    call_compose other
  end
end
define(other) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 289
def define(other)
  raise arg_err_build 2, other.size if other.size < 2
  fetch_define other
end
filter(other) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 239
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) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 225
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) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 232
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) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 281
def lambda(other)
  if other[0] == 'lambda'
    eval_lambda other[1..-1]
  else
    proc_lambda other
  end
end
member(other) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 248
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) click to toggle source
# File lib/lisp/interpreter/core/functional.rb, line 257
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