Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Compiler by

Apparently the JVM has a label/goto mechanism. Would it be possible to add such a capability to the Clojure language?

I suppose there are two questions which could be addressed 100% independently.
1. whether it is theoretically possible. i.e., to the JVM instructions really permit such a Clojure primitive at all. Perhaps I'm mistaken, and it is really not possible.
2. whether the core Clojure maintainers can be convinced of the merits of the request.

In general goto is useful in machine generated code, not so much in human written code.

I have at least three use cases where I'd like to have such a mechanism.

  1. serialization of deterministic finite automata
  2. serialization of discrimination nets
  3. translation of Knuth style algorithms into Clojure from Art of Computer Programming.

I know that lots of people might respond with philosophical arguments about why you shouldn't use goto. I hope to avoid such a discussion here.

One possibility which seems reasonable to me would be a Clojure primitive similar to the Common Lisp prog although the ability to bind variables is not really necessary, as it could easily be implemented by the user by using let with some macrology.

1 Answer

0 votes

One relevant issue is some work done by Michal Marczyk around recur-to which is a mechanism in loop which allows different recur targets.


Jira issue:

We’ve looked at this proposal some, hard for me to say if/when it will ever be included.
Alex, can you speak to some of the pros and cons which have been discussed?