[erlang-questions] Why does Erlang have control structures?
Volodymyr Kyrychenko
vladimir.kirichenko@REDACTED
Wed Aug 29 01:04:36 CEST 2012
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 ]
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.
--
Volodymyr Kyrychenko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120829/25279fe2/attachment.bin>
More information about the erlang-questions
mailing list