Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For - cycle? #28

Open
const-rs opened this issue Sep 20, 2016 · 1 comment
Open

For - cycle? #28

const-rs opened this issue Sep 20, 2016 · 1 comment

Comments

@const-rs
Copy link

What about including Ocaml-style for cycle:

for i = 1 to 18 do ... done (or end)

It is very handy when iterating through arrays or strings. Also, it does not
let one make common mistake with repeating calls in condition, like

for( i = 0; i < strlen(s); i++)

@JohnReppy
Copy link
Contributor

It is not a very functional programming style to use loops. Why not just define a combinator?

fun foreach (lo, hi) f = let
      fun lp i = if (i <= hi) then (f i; lp(i+1)) else ()
      in
        lp lo
      end

so you can write

foreach (1, 18) (fn i => ...)

If we are going to add syntax for loops, then I would be much more interested in list/vector comprehensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants