janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.38k stars 217 forks source link

let* please, possibly even letrec, letrec* #1352

Closed reuleaux closed 5 months ago

reuleaux commented 6 months ago

This is on my wishlist: let*

I am currently using nested let instead, which seems a little awkward:

(let [
         foo ‘bar
     ]
 (let [
           baz (do-something-with foo)
      ]
    body))

with let* this would be as simple as

(let [
            foo ‘bar
            bar (do-something-with foo)
     ]
   body)

Even one step further: recursive defs - with letrec/letrec* - have a look at the (Gauche- Guile-) Scheme src/docs for example. Thanks!

sogaiu commented 6 months ago

Doesn't let already do what you want?

$ janet
Janet 1.33.0-f91e5994 linux/x64/gcc - '(doc)' for help
repl:1:> (let [x 1 y x] (+ x y))
2
sogaiu commented 6 months ago

Regarding letrec and friends, it's not the same, but see this discussion.

iacore commented 6 months ago

(def [x y] [1 2])

reuleaux commented 6 months ago

Hm - my bad then, I guess, and sorry for the noise - I was pretty sure, that I ran in a situation, where this did not work, but now, that you are pushing me, and I am trying again, it seems to work for me.

I have these nested let in a couple of places now, and will get rid of them one by one (and I will shout out, in case of some issue remaining for me, i.e. if I keep quiet, than everything's fine).

Thanks for your feedback. -A

sogaiu @.***> writes:

Doesn't let already do what you want?

$ janet Janet 1.33.0-f91e5994 linux/x64/gcc - '(doc)' for help repl:1:> (let [x 1 y x] (+ x y)) 2

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.