> I've given it some thought and it seems it has to be a compiler level
> feature. Am I right?
You could implement Common Lisp-style "return-from" with a custom
exception class:
public class BlockException extends Exception {
String name;
Object val;
public BlockException(String name, Object val) {
this.name = name;
this.val = val;
}
public String name() { return this.name; }
public Object value() { return this.val; }
}
(defmacro block [name & body]
`(try
(do ,@body)
(catch BlockException e
(if (= (.name e) (name ,name))
(.value e)
(throw e)))))
(defmacro return-from [name expr]
`(throw (BlockException. (name ,name) ,expr)))
Then use it:
(defn foo []
(block outside
(do-something
;; ...
(return-from outside 5)
;; ...
)))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---