4 ms·
Is there any beam language that has regular 'for','while' loops and good OTP support?
by makemethrowaway 11mo ago
Is there any beam language that has regular 'for','while' loops and good OTP support?
- ahf8Aithaex7Nai 11mo agoJust write 'for' and 'while' yourself if you need it. Here is ‘for’ in Elm/Gren: for : Int -> Int -> Int -> (Int -> msg) -> List msg for start stop step action = let range = if step > 0 then List.range start (step) (stop - 1) else if step < 0 then List.range stop (abs step) (start - 1) |> List.reverse else [] in List.map action range It should be just as trivial to write this in Gleam.
- shawa_a_a 11mo agoI think that's going to be hard to find, depending on your definition of 'regular', tbh. The BEAM's grown up along with Erlang and so the culture and optimisations are built up all around function application, list processing, recursion, and pattern matching etc. https://github.com/llaisdy/beam_languages https://github.com/llaisdy/beam_languages is a decent list of the diverse languages that have been implemented on it, but nothing quite like 'regular for and while loops'. The BEAM itself is a plain aul register machine though, so it could be done! https://www.erlang.org/blog/a-brief-beam-primer/ https://www.erlang.org/blog/a-brief-beam-primer/
- lpil 11mo agoNo, the VM is functional and immutable so you cannot implement things like `while` on it efficiently. It is highly optimised for the functional immutable style of programming.