Mercerenies / gdlisp

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

break and continue #20

Closed Mercerenies closed 2 years ago

Mercerenies commented 3 years ago

Currently, we have no way of using the Godot control flow break and continue statements.

Now, we could naively implement them as keywords, but there is another option, provided we implement #19.

We could change while to impl-while (or some other esoteric name) and let while be a macro that expands roughly as follows.

(while cond body...)
;; becomes
(macrolet ((break () '(imp-break)))
  (imp-while cond body))

And the same for for. That way, break and continue can only be used inside of the appropriate constructs, and we can verify that at compile-time. Of course, this won't stop you from using them in a closure inside of a while, which is harder to detect. So it's possible that doing the check halfway would just confuse people further.

Mercerenies commented 2 years ago

fd17df6 implements these two keywords.

For the moment, at least, they are language primitives, and we have a special ad-hoc check to make sure they are (a) in a loop, and (b) not inside a closure that blocks us from the loop. If we get some more syntactic awareness within macros, we'll definitely revisit the idea of making them macros. But the feature is available now, so this issue is closed.