mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 09:17:17 +00:00
Properly handle recursion with labels.
Use an empty buffer, which has pointer equality semantics, for tag from a label.
This commit is contained in:
parent
05bd5767de
commit
734c85d7ef
@ -317,7 +317,7 @@
|
||||
that will be bound to the label."
|
||||
[name & body]
|
||||
~(do
|
||||
(def ,name ',(gensym))
|
||||
(def ,name @"")
|
||||
,(apply prompt name body)))
|
||||
|
||||
(defn return
|
||||
|
@ -70,7 +70,16 @@
|
||||
(test-bf "+[+[<<<+>>>>]+<-<-<<<+<++]<<.<++.<++..+++.<<++.<---.>>.>.+++.------.>-.>>--."
|
||||
"Hello, World!")
|
||||
|
||||
# Prompts
|
||||
# Prompts and Labels
|
||||
|
||||
(assert (= 10 (label a (for i 0 10 (if (= i 5) (return a 10))))) "label 1")
|
||||
|
||||
(defn recur
|
||||
[lab x y]
|
||||
(when (= x y) (return lab :done))
|
||||
(def res (label newlab (recur (or lab newlab) (+ x 1) y)))
|
||||
(if lab :oops res))
|
||||
(assert (= :done (recur nil 0 10)) "label 2")
|
||||
|
||||
(assert (= 10 (prompt :a (for i 0 10 (if (= i 5) (return :a 10))))) "prompt 1")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user