Fork me on GitHub
#babashka
<
2020-06-18
>
jeroenvandijk12:06:08

Funny, following works in Babashka but not in Clojure

(defn non-tail-recur []
  (loop [i 100]
    (try
      (if (> i 10)
        (throw (ex-info "foo" {}))
        i)
      (catch Exception e
        (recur (dec i))))))
Clojure says: Can only recur from tail position

borkdude12:06:46

would you like bb to report an error here?

jeroenvandijk12:06:46

No, I think it’s ok. I was just debugging something and thought maybe was the cause, but it was something else

jeroenvandijk12:06:04

Clojure is pretty clear about it, in Babashka you are just lucky πŸ™‚

borkdude12:06:25

hehe, maybe for compatibility it's good to just throw. issue welcome

jeroenvandijk12:06:58

I guess the check would need to happen at the analyzer level, right?

borkdude12:06:43

I'm not sure if recur is analyzed at all right now

borkdude13:06:24

what happens at runtime is that this loop is running within a function and when you call recur, it recurs the function call.

borkdude13:06:38

this is how recur is implemented in sci

jeroenvandijk18:06:10

Maybe analysing a function is enough:

(fn [] (try 1 (catch Exception e (recur))))
Syntax error (UnsupportedOperationException) compiling recur at (REPL:1:34).
Can only recur from tail position
πŸ™‚ (in clojure)

borkdude18:06:07

did you know this is valid? clj -e "(recur)"

jeroenvandijk18:06:56

haha wow no, i never had a usecase for that πŸ˜…

borkdude18:06:27

I'll fix it at one point. Don't worry about a patch

borkdude18:06:32

already made an issue