mitranim/jisp

Better options for iterating

Closed this issue · 2 comments

I'm not sure if this is the best way to provide this feedback, but I'm very close to wanting to use this language for serious projects.

My hangup is a lack of good iterator forms. I don't want all my iterators to rely on arrays thus using extra memory, or make an awkward looking while loop(this requires additional let and do statements)

You describe a not yet implemented feature on the jisp.io homepage, where the for statement would accept an integer. That would be awesome.

In general I would like to see the iterable parameter to the for loop accept any function as an iterable(a closure, it would need to be stateful). So long as it returns a non-null value it continues iterating.

I honestly wouldn't mind a for loop syntax that was more of a direct mapping of javascript's for loop, even though that doesn't conform to functional paradigms.

There's some tricky language decisions involved and I respect the challenge of this problem.

I have been trying to figure out the best form I prefer for writing array comprehensions as well, but they use memory so I don't like them for some cases.

I don't know if you have that NYI integer for loop committed already to a branch, I would like to see that be a top priority because it is an important use case for me.

That's my feedback. Thanks.

Silly me, I can write my own macros to make the language work like I like it. It's a tricky yet fun exercise.

This is me purely being nostalgiac, I love that you can do this with the language, though some may find it offensive.

; the forloop macro tries to imitate the procedural form of the forloop.
; it doesn't require wrapping multiple loop body statements inside a 'do'
(mac forloop init test incr ...body 
  `(do ,init
     (while ,test (do ,...body ,incr))))

(forloop (= i 0) (< i 10) (++ i)
  (= x (* i i))
  (console.log x))