[erlang-questions] Why does Erlang have control structures?
dmitry kolesnikov
dmkolesnikov@REDACTED
Wed Aug 29 05:40:14 CEST 2012
Hello,
Did I missed something but given Scala constructions has equivalents
in Erlang? See below
Regards,
Dmitry
On 29.8.2012, at 2.36, Toby Thain <toby@REDACTED> wrote:
> On 28/08/12 7:04 PM, Volodymyr Kyrychenko wrote:
>> Jayson Barley wrote:
>>> I am not sure I understand why we have them. For instance I can take the
>>> following code
>>>
>>> is_greater_than(X, Y) ->
>>> if
>>> X>Y ->
>>> true;
>>> true -> % works as an 'else' branch
>>> false
>>> end.
>>>
>>> And make it
>>>
>>> is_true(true) ->
>>> true;
>>> is_true(false) ->
>>> false.
>>>
>>> is_greater_than(X, Y) ->
>>> is_true(X>Y).
>>
>> Because erlang has no call-by-name/need.
>>
>> What you're proposing exists in Smalltalk.
>>
>> x ifTrue: [ code ]
>
> This lazy block passing also exists in Scala, which enables various forms of ad-hoc control structures like:
>
> spawn {
> // code block to run in another thread
> }
>
In Erlang
spawn(
fun()->
// code block to run
end
)
> or
>
> val f = future { /* some computation wanted later */ }
>
F = fun() ->
// some computation
end
> Other Scala features of interest to Erlangers are immutable bindings, pattern matching, and of course actors.
>
> --Toby
>
>>
>> In erlang for this to work it should be like:
>>
>> if_(X>Y, fun() -> do something end, fun() ->
>> this_is_else_for_something_to_return_if_not end).
>>
>> For this to work without having to wrap everything into funs there
>> should be lazy evaluation order in the language.
>>
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list