Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
141 stars 1 forks source link

deflazy #50

Closed Mercerenies closed 3 years ago

Mercerenies commented 3 years ago

I propose a new construct deflazy. deflazy has a name and an expression. The expression is lazily initialized the first time the name is referenced.

(deflazy foo 1)

compiles to a nullary function which initializes the value if needed, and then returns it. We can use the same construction we used for defobject here. Additionally, once we have deflazy, defobject could be defined as, roughly,

(defmacro defobject (name parent &rest body)
  `(deflazy ,name (new ,parent ,@body)))
Mercerenies commented 3 years ago

deflazy is implemented as of d310c48 (with a partial fix for #56 implemented in bfa7f47). The rest of #56 is a known bug which will be dealt with over in that issue.

This issue will remain open until defobject is converted to deflazy as well.

Mercerenies commented 3 years ago

e430d1d converts defobject to be a macro which uses deflazy, thus closing this issue.