How to handle nested case
Gian Lorenzo Meocci
glmeocci@REDACTED
Sun Sep 19 17:35:27 CEST 2021
the proposal and the implementation are pieces of art!
Thanks for your work.
On Sun, 19 Sept 2021 at 17:02, Gian Lorenzo Meocci <glmeocci@REDACTED>
wrote:
> Thanks a lot for the link!
>
> On Sun, 19 Sept 2021 at 16:40, Paulo F. Oliveira <
> paulo.ferraz.oliveira@REDACTED> wrote:
>
>> Hi, Gian.
>>
>> You might be interested in reading [1], first shown to the Erlang world
>> in [2] (there's more info. in the archives, if you search).
>>
>> FYI, it is being hacked away, at this very moment, in SpawnFest 2021:
>> https://github.com/spawnfest/eep49ers.
>>
>> Cheers.
>>
>> - Paulo F. Oliveira
>>
>> [1] https://github.com/erlang/eep/blob/master/eeps/eep-0049.md
>> [2] http://erlang.org/pipermail/eeps/2018-September/000554.html
>>
>> On Sun, 19 Sept 2021 at 14:37, Gian Lorenzo Meocci <glmeocci@REDACTED>
>> wrote:
>>
>>> I think that there isn't a generic solution for this problem. It’s time
>>> to introduce the 'with' operator in Erlang
>>>
>>> Il Dom 19 Set 2021, 09:06 Attila Rajmund Nohl <attila.r.nohl@REDACTED>
>>> ha scritto:
>>>
>>>> Hello!
>>>>
>>>> One way (I haven't actually tried to compile this, but hopefully you
>>>> get the idea):
>>>>
>>>> get_nas_from_conf() ->
>>>> try
>>>> {ok, Server} = get_radius_host(),
>>>> {ok, Port} = get_radius_port(),
>>>> {ok, Secret} = get_radius_secret(),
>>>> {Server, Port, Secret};
>>>> catch
>>>> error:{badmatch, E} ->
>>>> E
>>>> end.
>>>>
>>>> Of course, if the badmatch comes from the get_* functions, this
>>>> construct might catch that too, but you might be able to ensure this
>>>> doesn't happen.
>>>>
>>>> Gian Lorenzo Meocci <glmeocci@REDACTED> ezt írta (időpont: 2021.
>>>> szept. 18., Szo, 22:50):
>>>> >
>>>> > Hi,
>>>> > I have a function like this:
>>>> >
>>>> > get_nas_from_conf() ->
>>>> > case get_radius_host() of
>>>> > {ok, Server} ->
>>>> > case get_radius_port() of
>>>> > {ok, Port} ->
>>>> > case get_radius_secret() of
>>>> > {ok, Secret} ->
>>>> > {Server, Port, Secret};
>>>> > E -> E
>>>> > end;
>>>> > E ->
>>>> > E
>>>> > end;
>>>> > E ->
>>>> > E
>>>> > end.
>>>> >
>>>> > Which is the best way to write this kind of function?
>>>> >
>>>> > I'd like to have a with operator like in Elixir, to rewrite my
>>>> function in this way:
>>>> >
>>>> > get_nas_from_conf() ->
>>>> > with {ok, Server} <- get_radius_host(),
>>>> > {ok, Port} = get_radius_port(),
>>>> > {ok, Secret} = get_radius_secret() ->
>>>> > {Server, Port, Secret};
>>>> > catch
>>>> > {error, _Reason} = E ->
>>>> > E
>>>> > end.
>>>> >
>>>> > Any suggestion?
>>>> >
>>>> > --
>>>> > GL
>>>> > https://www.meocci.it
>>>>
>>>
>
> --
> GL
> https://www.meocci.it <https://meox.github.io>
>
--
GL
https://www.meocci.it <https://meox.github.io>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210919/6db7c374/attachment.htm>
More information about the erlang-questions
mailing list