Hi,

I like it! But I still think that there is a place for punning in the elixir 
language, as with this macro we are trading one simplification for an extra 
function call.

The main problem seems to be that there are two ways of pattern matching — by 
atom or by string. Perhaps it would be possible to first look for an atom key 
and if that key is not there look for a string key. There are not many use 
cases that you have identical keys both as a string and an atom in a map. We 
could then have: %{foo, bar, baz} = %{“foo” => “foo”, bar: “bar”, baz: “baz”} 
in the language.

Cheers,

Jaap


> On Aug 30, 2016, at 6:29 PM, Hassan Zamani <[email protected]> wrote:
> 
> One of main differences of Synex and ShortMaps is that Synex supports nested 
> stractures:
> iex> params(%{a => %{b, c}}) = %{"a" => %{"b" => 2, "c" => 3}}
> iex> {b, c}
> {2, 3}
> iex> a
> %{"b" => 2, "c" => 3}
> 
> It supports map update syntax:
> iex> person = %{"name" => "Jack", "age" => 26}
> iex> name = "John"
> iex> params(%{person | name, "age" => 28}) 
> %{"name" => "John", "age" => 28}
> 
> iex> map = %{a: 1, b: 2, c: 3, d: 4}
> iex> {a, b} = {10, 20}
> iex> keys(%{map | a, b, c: 100, d: 200}) 
> %{a: 10, b: 20, c: 100, d: 200} 
> 
> For more info you can find docs for keys 
> <https://hexdocs.pm/synex/Synex.Keys.html> and params 
> <https://hexdocs.pm/synex/Synex.Params.html> on hexdocs.pm 
> <http://hexdocs.pm/>
> 
> 
> On Monday, August 29, 2016 at 9:01:36 PM UTC+4:30, OvermindDL1 wrote:
> Looks interesting, but how does it compare to 
> https://hex.pm/packages/short_maps <https://hex.pm/packages/short_maps> as it 
> adds a sigil that does something similar?
> ```elixir
> import ShortMaps
> 
> my_map = %{foo: 1, bar: 2, baz: 3}
> 
> ~m(foo bar baz)a = my_map
> foo #=> 1
> import ShortMaps
> 
> name = "Meg"
> 
> # String keys by default (or with the 's' modifier)
> ~m(name) #=> %{"name" => "Meg"}
> # Atom keys with the 'a' modifier
> ~m(name)a #=> %{name: "Meg"}
> iex(1)> import ShortMaps
> nil
> iex(2)> name = "Meg"
> "Meg"
> iex(3)> ~m(^name)a = %{name: "Meg"}
> %{name: "Meg"}
> iex(4)> ~m(^name)a = %{name: "Megan"}
> ** (MatchError) no match of right hand side value: %{name: "Megan"}
> ```
> And other stuff
> 
> 
> On Sunday, August 28, 2016 at 11:13:55 AM UTC-6, Hassan Zamani wrote:
> No comments?
> 
> On Saturday, August 13, 2016 at 2:53:56 PM UTC+4:30, Hassan Zamani wrote:
> I would appreciate hearing your thoughts on https://github.com/hzamani/synex 
> <https://github.com/hzamani/synex>. It has two macros: keys and params, first 
> one for expansion of atom-value pairs in keyword lists, maps and structs, and 
> other for expansion of string-value pairs in maps. Both of them have variable 
> pinning and map update support and params supports nested maps:
> 
> iex> params(%{a => %{b, c}}) = %{"a" => %{"b" => 2, "c" => 3}}
> iex> a
> %{"b" => 2, "c" => 3}
> iex> c
> 3
> 
> Hassan
> 
> On Wednesday, February 17, 2016 at 1:29:31 PM UTC+3:30, Jaap Frolich wrote:
> Very nice Johan,
> 
> Love the power of macros. Is there any resolution if this will make the 
> standard library? I have a lot of repetition in my maps as well in my current 
> app, and this is one of the things I like in ES6 that I really miss in Elixir 
> (mostly it is of course the other way around ;)).
> 
> Cheers,
> 
> Jaap
> 
> On Monday, August 10, 2015 at 4:57:02 PM UTC+8, Johan Wärlander wrote:
> After playing around a bit with the ~m sigil, I proposed a couple of updates 
> (one which touched on work that Andrea had alredy done, but with a twist); 
> short_maps now support the following:
> 
> # Equality checks
> foo = 1
> bar = 2
> ~m(foo bar)a == %{foo: 1, bar: 2} #=> true
> 
> # Matching
> ~m(foo bar)a = %{foo: 12, bar: "baaz"}
> foo #=> 12
> 
> # Pinning (NEW)
> foo = 1
> ~m(^foo bar)a = %{foo: 1, bar: "baaz"} #=> %{foo: 1, bar: "baaz"}
> ~m(^foo bar)a = %{foo: 5, bar: "baaz"} #=> MatchError
> 
> # Structs, when first word starts with '%' (NEW)
> defmodule Foo do
>   defstruct bar: nil
> end
> ~m(%Foo bar)a = %Foo{bar: "baaz"}
> bar #=> "baaz"
> 
> For anyone else interested, please do get the latest version from Andrea's 
> repository (https://github.com/whatyouhide/short_maps 
> <https://github.com/whatyouhide/short_maps>), then play around with it and 
> see how it feels.
> 
> On Friday, June 19, 2015 at 12:02:36 PM UTC+2, Andrea Leopardi wrote:
> I stood against the %{foo, bar, baz} syntax and deemed that too implicit, but 
> I'm in favour of a possible ~m sigil. I think it may still be a bit implicit, 
> but I can see it would make code much more concise in a lot of situations. I 
> took a stab at it and wrote a simple implementation for such sigil, here 
> <https://github.com/whatyouhide/short_maps>. We can try it out and see if we 
> like it (and please, have a look at the implementation as well as I'm not 
> sure it's bulletproof).
> 
> 
> 
> On Sunday, May 31, 2015 at 12:19:46 PM UTC+2, Devin Torres wrote:
> Taking a pretty cool page out of ES6:
> 
> # If `method`, `url`, `headers`, and `payload` are already bound
> %Request{method, url, headers, payload}
> 
> # If e.g. `payload` hasn't been bound yet
> %Request{method, url, headers, payload: get_payload()}
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "elixir-lang-core" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/elixir-lang-core/NoUo2gqQR3I/unsubscribe 
> <https://groups.google.com/d/topic/elixir-lang-core/NoUo2gqQR3I/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-core/127db373-9bd4-4806-b901-f9ea049fcc99%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/elixir-lang-core/127db373-9bd4-4806-b901-f9ea049fcc99%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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/2518C1B3-EA9E-4D18-965A-DEFF1222EFCF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to