4 ms·
that's how common lisp and clojure still work too!
by phyrex 4y ago
that's how common lisp and clojure still work too!
- cyberbanjo 4y agoHow does it work in Clojure? Attempting to compile/evaluate this: (defn foobar [] (undef-fn)) gives: 1. Caused by java.lang.RuntimeException Unable to resolve symbol: undef-fn in this context Attempting to call foobar: (foobar) gives: 1. Unhandled java.lang.IllegalStateException Attempting to call unbound fn: #'user/foobar Environment info: ;; CIDER 1.3.0 (Ukraine), nREPL 0.9.0 ;; Clojure 1.11.1, Java 18.0.2
- jhhh 4y agoOnly change is that you have to tell the compiler that 'undef-fn' exists but you don't have to provide an implementation. So, before all of that just do (def undef-fn) It should work after that.
- cyberbanjo 4y agoPre-declaring the undefined function does prevent the first of those exceptions. I guess it just feels weird to include Clojure here, because the CL experience is like it brings up an interactive debugger and asks if you wanna define the function now or abort.
- jhhh 4y agoRe-reading the original post I see what you mean now. But Clojure definitely fits the first part of the definition by compiling your methods instantly as you're writing them in the repl. For the second part I'm not aware of a prompt which would let you define a method in response to a missing function call. Might be an interesting feature.
- cyberbanjo 4y agoFor the second part: with restarts and conditions, CL pulls up an interactive debugger that asks if you would like to abort, continue/retry calling undefined or supply a definition now, amongst others. Evalutating this in CL (SBCL) (undef-fn) gives: Restarts: 0: [CONTINUE] Retry calling UNDEF-FN. 1: [USE-VALUE] Call specified function. 2: [RETURN-VALUE] Return specified values. 3: [RETURN-NOTHING] Return zero values. 4: [RETRY] Retry SLY interactive evaluation request. 5: [\*ABORT] Return to SLY's top level. 6: [ABORT] abort thread (#<THREAD "slynk-worker" RUNNING {100288C7E3}>) [... as well as a clipped stack trace ...] Pressing 1 will allow you to name an alternative function in a minibuffer prompt, 2 lets you set the return value of the undefined fn, etc.
- fulafel 4y agoDefining the function after the error and retrying does I think fit the description too. I guess the seamless continue without retry possibility could be useful if you are doing important side effects, but Clojure is quite functional unlike CL so it doesn't come up as much.