mirror of
https://github.com/vonhyou/lisp-interpreter.git
synced 2025-06-08 02:02:01 +00:00
rewrite env
This commit is contained in:
parent
19b8871a06
commit
b0bd6e899d
1 changed files with 9 additions and 2 deletions
11
prol.rb
11
prol.rb
|
@ -51,10 +51,17 @@ module Lisp
|
|||
def self.make_global
|
||||
@global_env ||= begin
|
||||
ops = %i[== != < <= > >= + - * / % & | ^ ~]
|
||||
ops.inject({}) do |scope, op|
|
||||
scope.merge op => ->(*args) { args.inject(&op) }
|
||||
ops.inject({}) do |sp, op|
|
||||
sp.merge op => ->(*args) { args.inject(&op) }
|
||||
end
|
||||
end
|
||||
|
||||
@global_env.merge! quote: ->(*args) { args.to_a }
|
||||
@global_env.merge! cons: ->(*args) { args.to_a }
|
||||
@global_env.merge! car: ->(arr) { arr[0] }
|
||||
@global_env.merge! cdr: ->(arr) { arr[1..-1] }
|
||||
@global_env.merge! print: ->(arg) { p arg }
|
||||
@global_env
|
||||
end
|
||||
|
||||
##### Lisp Eval
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue