mirror of
https://github.com/vonhyou/lisp-interpreter.git
synced 2025-06-08 02:02:01 +00:00
add quote
This commit is contained in:
parent
3cb684840a
commit
b3adb30967
1 changed files with 3 additions and 2 deletions
|
@ -72,6 +72,7 @@ def generate_env
|
|||
'car': ->(arr) { arr[0] },
|
||||
'cdr': ->(arr) { arr[1..-1] },
|
||||
'cons': ->(arr) { arr },
|
||||
'quote': ->(arr) { arr },
|
||||
'print': ->(arg) { p arg },
|
||||
'begin': ->(*_args) { true }
|
||||
}
|
||||
|
@ -89,7 +90,7 @@ end
|
|||
|
||||
$global_env = generate_env
|
||||
def lisp_eval(elem, env = $global_env)
|
||||
if elem.instance_of?(Symbol)
|
||||
if elem.instance_of? Symbol
|
||||
env[elem]
|
||||
elsif elem.instance_of?(Integer) || elem.instance_of?(Float)
|
||||
elem
|
||||
|
@ -128,4 +129,4 @@ def print_value(value)
|
|||
end
|
||||
|
||||
repl()
|
||||
# lisp_eval(parse('(begin (def var1 7) (if (> var1 8) (+ 3 11) (/ 7 3)))'))
|
||||
# p lisp_eval(parse('(if (> 7 8) (+ 3 11) (/ 7 3))'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue