mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-26 21:27:42 +00:00 
			
		
		
		
	Add label macro.
A lexically scoped version of prompt is often useful.
This commit is contained in:
		| @@ -300,7 +300,7 @@ | ||||
|          (propagate ,r ,f))))) | ||||
|  | ||||
| (defmacro prompt | ||||
|   "Set up a prompt point that can be aborted to. Tag should be a value | ||||
|   "Set up a checkpoint that can be returned to. Tag should be a value | ||||
|   that is used in a return statement, like a keyword." | ||||
|   [tag & body] | ||||
|   (with-syms [res target payload fib] | ||||
| @@ -312,9 +312,17 @@ | ||||
|          ,payload | ||||
|          (propagate ,res ,fib))))) | ||||
|  | ||||
| (defmacro label | ||||
|   "Set a label point that is lexically scoped. Name should be a symbol | ||||
|   that will be bound to the label." | ||||
|   [name & body] | ||||
|   ~(do | ||||
|      (def ,name ',(gensym)) | ||||
|      ,(apply prompt name body))) | ||||
|  | ||||
| (defn return | ||||
|   "Return to a prompt point." | ||||
|   [to value] | ||||
|   [to &opt value] | ||||
|   (signal 0 [to value])) | ||||
|  | ||||
| (defmacro with | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose