Module: SchemeLists
Overview
Instance Method Summary
collapse
#build_cons_from_list, #build_function_car_cdr, #build_list, #call_car_cdr_infinite, #car_cdr_values, #cons_helper, #find_idx_for_list, #find_list_function_value, #generate_infinite_car_cdr, #get_cons_values, #map_helper, #map_validate_helper, #no_eval_list, #split_list_as_string, #split_list_string
Instance Method Details
#car(other) ⇒ Object
113
114
115
116
117
|
# File 'lib/lisp/interpreter/core/list.rb', line 113
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
163
164
165
166
167
168
169
|
# File 'lib/lisp/interpreter/core/list.rb', line 163
def car_cdr_infinite(other)
fn = other[1]
values = find_all_values other[2..-2]
return call_car_cdr_infinite fn, values if @procs.key? fn.to_s
raise arg_err_build 1, values.size unless values.size == 1
(generate_infinite_car_cdr fn).call values[0]
end
|
#cdr(other) ⇒ Object
119
120
121
122
123
124
|
# File 'lib/lisp/interpreter/core/list.rb', line 119
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
104
105
106
107
|
# File 'lib/lisp/interpreter/core/list.rb', line 104
def cons(other)
raise arg_err_build 2, other.size if other.size != 2
cons_helper other
end
|
#length(other) ⇒ Object
141
142
143
|
# File 'lib/lisp/interpreter/core/list.rb', line 141
def length(other)
(find_list_function_value other).size
end
|
#list(other) ⇒ Object
109
110
111
|
# File 'lib/lisp/interpreter/core/list.rb', line 109
def list(other)
build_list other
end
|
#list?(other) ⇒ Boolean
126
127
128
129
|
# File 'lib/lisp/interpreter/core/list.rb', line 126
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
150
151
152
153
154
155
156
|
# File 'lib/lisp/interpreter/core/list.rb', line 150
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
136
137
138
139
|
# File 'lib/lisp/interpreter/core/list.rb', line 136
def null?(other)
raise arg_err_build 1, other.size if other.size != 1
other[0] == '\'()' ? '#t' : '#f'
end
|
#pair?(other) ⇒ Boolean
131
132
133
134
|
# File 'lib/lisp/interpreter/core/list.rb', line 131
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
145
146
147
148
|
# File 'lib/lisp/interpreter/core/list.rb', line 145
def reverse(other)
value = find_list_function_value other
build_list value.reverse
end
|
#shuffle(other) ⇒ Object
158
159
160
161
|
# File 'lib/lisp/interpreter/core/list.rb', line 158
def shuffle(other)
values = find_list_function_value other
build_list values.shuffle
end
|