Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The idiomatic way would be to exit the array paradigm and use an imperative (while.) or functional (recursion) method. APL and J both have "repeat until convergence" functionality, which stops when the same result is returned twice in a row, but to use this you'd have to artificially create a result that changes each time.

When designing BQN I embraced the limited nature of array primitives, so that most primitives can only implement efficiently parallelizable programs and none of them can perform infinite loops. Flip this around and you get guarantees: if you create a function by composing primitives you know it will halt, and if you avoid using modifiers in complicated ways it's easy to prove good sequential and parallel bounds on the runtime.[0] Although BQN has no tail recursion (J also doesn't; Dyalog does), it's possible to implement loop functionality that uses only logarithmic stack space in the number of iterations, with low overhead (I just measured 30ns/iteration in CBQN for a simple incrementing loop).[1]

[0] https://mlochbaum.github.io/BQN/doc/primitive.html

[1] https://mlochbaum.github.io/BQN/doc/control.html#low-stack-v...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: