I feel like adding a new macro this similar to *with *would just bloat the 
Elixir spec. That being said, adding shorthand for tagged matches with to 
support tagged matches would be nice as long as it doesn't pollute the 
spec. 
Personally, I don't like the idea of adding new syntax to describe this.

Under the hood all this shorthand should be creating is something like: 
[{:tag, {:ok,    user}}] <- ...
[{:tag, {:error, msg }}] -> ...

If a shorthand for this is to be added, I think it should conform to the 
existing Elixir conventions. 

My first thought was using unwrapped keyword list syntax. 

with all: {:ok, users} <- all: cashed_users(),
     best: {:ok, user} <- best: get_best_user(users)
do   state
else all: {:error, msg} -> dostuff
     best: {:error, msg} -> dostuff


This is existing syntax and is instantly recognizable by someone familiar 
with Elixir.  
The issue is that it is ambiguous. If you allow for unwrapped keyword 
lists, there is no way to tell when the keyword list ends and the next 
pattern begins.

with *all**: {:ok, users}, other: other <- all: cashed_users(), other: 
other(), # ?????*
     best: {:ok, user} <- best: get_best_user(users)
do   state
else all: {:error, msg} -> dostuff
     best: {:error, msg} -> dostuff

It's definitely worth some thought. But I think the best solution would be 
something like is very close to existing syntax, such as the above example. 
 
  
On Sunday, July 23, 2017 at 1:06:04 PM UTC-7, niahoo osef wrote:
>
> Hi, 
>
> I would like yo know your opinion about cunstructs like this one. I guess 
> this is not a priority for Elixir, and I know I can add it to Hex.pm. I'm 
> just unhappy with the `with` block and I want to know what you think.
>
> I made a simple implementation here : https://github.com/niahoo/ctrl with 
> detailed information of the annotation feature.
>
> Basically it's a `with` block but with standard block syntax and match 
> selection with tags :
>
>
> ctrl do
>   {:ok, state} <- init()                              # Classic `with` 
> clause
>   %{id: id, opts: opts} = state                       # Any expression
>   :ok <- register(id)
>   :f_repo | {:ok, repo} <- Keyword.fetch(opts, :repo) # Tagged match
>   :f_user | {:ok, user} <- Keyword.fetch(opts, :user) # Different tagged 
> match
>   {:ok, do_something(id, repo, user)}
> else
>   {:error, _} = err -> err                            # Errors with info
>   :f_repo | :error -> {:error, :no_repo_option}       # Errors on :repo 
> only
>   :f_user | :error -> {:error, :user_not_set}         # Errors on :user 
> only
> end
>
>
>
> Thanks for reading :)
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/82273946-05ff-4dbf-8baa-8cb321511670%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to