module SchemeListsHelper
Helper functions for SchemeLists
Public Instance Methods
build_cons_from_list(values)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 25 def build_cons_from_list(values) spacer = values[1].size == 3 ? '' : ' ' values[0].to_s + spacer + values[1][2..-2].to_s end
build_function_car_cdr(fn)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 81 def build_function_car_cdr(fn) prepare_call = ['(', fn, 'x', ')'] fn[1..-2].each_char do |t| prepare_call += (t == 'a' ? ['(', 'car'] : ['(', 'cdr']) end prepare_call << 'x' (fn.size - 2).times { prepare_call << ')' } prepare_call end
build_list(values)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 21 def build_list(values) '\'(' + values.join(' ') + ')' end
call_car_cdr_infinite(fn, values)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 96 def call_car_cdr_infinite(fn, values) @procs[fn.to_s].call values end
car_cdr_values(other)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 63 def car_cdr_values(other) raise arg_err_build 1, other.size if other.size != 1 return find_list_function_value other if other[0].list? (split_list_string other[0].to_s)[2..-2] if other[0].pair? end
cons_helper(values)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 30 def cons_helper(values) result = if values[1].to_s[0..1] == '\'(' build_cons_from_list values else values[0].to_s + ' . ' + values[1].to_s end '\'(' + result + ')' end
find_idx_for_list(tokens)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 13 def find_idx_for_list(tokens) if tokens[0] == '(' find_bracket_idx tokens, 0 elsif tokens[1] == '(' find_bracket_idx tokens, 1 end end
find_list_function_value(other)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 52 def find_list_function_value(other) raise arg_err_build 1, other.size if other.size != 1 raise type_err '<list>', other[0].type unless other[0].list? split_list_as_string other[0].to_s end
generate_infinite_car_cdr(fn)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 91 def generate_infinite_car_cdr(fn) prepare_call = build_function_car_cdr fn define_function prepare_call end
get_cons_values(tokens)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 40 def get_cons_values(tokens) result = get_k_arguments tokens, false, 2 raise arg_err_build 2, result.size if result.size != 2 result end
map_helper(lst, func)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 69 def map_helper(lst, func) return lst.map { |t| func.call(*t) } if func.is_a? Proc lst.map { |t| send func, t } end
map_validate_helper(other)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 74 def map_validate_helper(other) raise arg_err_build 'at least 2', 0 if other.empty? func, other = valid_function other raise arg_err_build 'at least 2', 1 if other.empty? [func, other] end
no_eval_list(tokens, no_quotes = false)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 3 def no_eval_list(tokens, no_quotes = false) result = [] until tokens.empty? value, tokens = build_next_value_as_string tokens value = value[1..-2] if no_quotes && (check_for_string value.to_s) result << value end result end
split_list_as_string(list_as_string)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 58 def split_list_as_string(list_as_string) split_value = split_list_string list_as_string.to_s no_eval_list split_value[2..-2] end
split_list_string(list)
click to toggle source
# File lib/lisp/interpreter/core/list.rb, line 46 def split_list_string(list) result = list.split(/(\(|\)|\.)|\ /) result.delete('') result end