-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorelib.rb
More file actions
26 lines (26 loc) · 1.87 KB
/
corelib.rb
File metadata and controls
26 lines (26 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Lasp
CORELIB = {
:+ => ->(*args) { args.reduce(:+) },
:- => ->(*args) { args.reduce(:-) },
:* => ->(*args) { args.reduce(:*) },
:/ => ->(*args) { args.reduce(:/) },
:< => ->(*args) { args.each_cons(2).all? { |a, b| a < b } },
:> => ->(*args) { args.each_cons(2).all? { |a, b| a > b } },
:<= => ->(*args) { args.each_cons(2).all? { |a, b| a <= b } },
:>= => ->(*args) { args.each_cons(2).all? { |a, b| a >= b } },
:"=" => ->(*args) { args.uniq.count == 1 },
:list => ->(*args) { args },
:head => ->(list) { list.first },
:tail => ->(list) { list.drop(1) },
:cons => ->(item, list) { [item] + list },
:dict => ->(*args) { Hash[*args] },
:get => ->(key, a) { a[key] },
:assoc => ->(dst, key, val) { dst.dup.tap { |d| d[key] = val } },
:dissoc => ->(dst, key) { dst.dup.tap { |d| d.delete(key) } },
:not => ->(arg) { !arg },
:print => ->(*output) { STDOUT.print(*output) },
:readln => ->() { STDIN.gets.chomp },
:apply => ->(f, list) { f.call(*list) },
:send => ->(m, o, *args) { o.public_send(m, *args) },
}.freeze
end