Lexical scoping is working, but defun broke because of that.
Need macros next
This commit is contained in:
+23
-6
@@ -1,12 +1,29 @@
|
||||
|
||||
(defun make-vector (x y z)
|
||||
(let ((local-x x)
|
||||
(local-y y)
|
||||
(local-z z))
|
||||
(lambda ()
|
||||
local-x)))
|
||||
(let ((local-x x)
|
||||
(local-y y)
|
||||
(local-z z)
|
||||
(defun (macro (@name @params :rest @body)
|
||||
(eval (pair 'define-upwards (pair @name (pair (pair 'lambda (pair @params @body)) nil)))))))
|
||||
|
||||
(defun set-x (new-x) (mutate local-x new-x))
|
||||
(defun set-y (new-y) (mutate local-y new-y))
|
||||
(defun set-z (new-z) (mutate local-z new-z))
|
||||
|
||||
(defun dispatch (message)
|
||||
(if (= message ::get-x)
|
||||
local-x
|
||||
(if (= message ::set-x)
|
||||
set-x
|
||||
nil)))
|
||||
|
||||
(break)
|
||||
dispatch))
|
||||
|
||||
(define v (make-vector 1 2 3))
|
||||
(print (v))
|
||||
|
||||
(print (v ::get-x))
|
||||
((v ::set-x) 19)
|
||||
(print (v ::get-x))
|
||||
|
||||
(read " ")
|
||||
|
||||
Reference in New Issue
Block a user