[erlang-questions] Tried this... Thought it interesting... But it didn't work.

Sergej Jurečko sergej.jurecko@REDACTED
Wed Sep 2 15:03:32 CEST 2015


Your question gave me a simple usage example that I just encountered. It is
trivial.

Instead of:

case check_something() of
ok ->
  ok;
_ ->
  exit(error)
end.

You can write:
[ exit(error) || check_something() /= ok ].


Sergej


On Wed, Sep 2, 2015 at 1:46 AM, <lloyd@REDACTED> wrote:

> Hi Sergei,
>
> But if X is defined outside the list comprehension, isn't it immutable?
>
> Can you show me an example that works?
>
> Thanks,
>
> Lloyd
>
> -----Original Message-----
> From: "Sergej Jurečko" <sergej.jurecko@REDACTED>
> Sent: Tuesday, September 1, 2015 11:33am
> To: lloyd@REDACTED, "erlang-questions" <erlang-questions@REDACTED
> >
> Subject: Re: [erlang-questions] Tried this... Thought it interesting...
> But it didn't work.
>
> Both X and Y must be defined outside that list comprehension.
>
>
> Sergej
>
>
>
>
>
> On 01/09/15 17:30, "erlang-questions-bounces@REDACTED on behalf of
> lloyd@REDACTED" <erlang-questions-bounces@REDACTED on behalf of
> lloyd@REDACTED> wrote:
>
> >So, I ran across this tidbit in the Erlang cybersphere:
> >
> >List Comprehension without generators
> >
> >
> http://blog.equanimity.nl/blog/2015/03/15/erlang-one-weird-trick-goodiebag/
> >
> >1> Y = 3.
> >3
> >2> Z = [X || Y > 2].
> >* 1: variable 'X' is unbound
> >
> >OK.So I tried...
> >
> >-module(test).
> >
> >-compile(export_all).
> >
> >test(Y) ->
> >  [ X || Y > 2].
> >
> >>3 test:test().
> >Error: variable 'X' is unbound
> >
> >Waah...is someone pulling my leg?
> >
> >This worked...
> >
> >4> Z = [X || X <- [Y >2]].
> >
> >But it seems rather pointless.
> >
> >I didn't check to see if the original post was dated circa April 1.
> >
> >Best wishes,
> >
> >LRP
> >
> >
> >
> >_______________________________________________
> >erlang-questions mailing list
> >erlang-questions@REDACTED
> >http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150902/4bf33eb9/attachment.htm>


More information about the erlang-questions mailing list