is_struct is impossible to implement right now. The implementation in the 
linked library is faulty and will fail as soon as you use the or operator or 
multiple when clauses. For example, given an is_struct/2 guard when we use it 
as:

    def foo(arg) when is_struct(arg, Decimal) or is_integer(arg)

There is no way to translate this to valid Elixir syntax. Such a change would 
require changes to VM itself and expanding the guard functions with a map_get/2 
or something similar. As far as I know, allowing for pattern matching or case 
in guards was already rejected by the OTP team.

Michał.

On 27 Sep 2017, 20:38 +0200, José Valim <[email protected]>, wrote:
> > > Though yes, I do conceed that defining these structural matches has a 
> > > more front-end one-time cost (via PR) in that you have to add loaders to 
> > > various syntax constructs in addition to potentially having to duplicate 
> > > bodies into different heads (as heads may need to be duplicated at times 
> > > since you cannot match an 'or' of structures), but that is all still only 
> > > a one-time cost to be able to define new guards that are *significantly* 
> > > more powerful than what a comparatively simple macro could do, thus 
> > > allowing you to make things like `is_struct/1`/`is_struct/2` or 
> > > `is_exception/...` and others, including for very specific internal 
> > > information that a library may want to expose a guard for that the 
> > > current 1.6.0 proposal is entirely incapable of.
> >
> > While I agree it would be awesome to have an is_struct/1 guard, the correct 
> > solution to this problem is to contribute this feature upstream and allow 
> > map access in guards. So I agree your proposal does add new possibilities 
> > but that's not how we should go about implementing them, especially because 
> > of the complexity it would add to the compiler and the cost in the 
> > duplication of clauses (space and time).
> >
> --
> 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/CAGnRm4%2BgL%2BRUnA279KPZMsjQkMJOhXr4q6xEVGQb%3DHu5ReaQVg%40mail.gmail.com.
> For more options, visit 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/0c8913d2-0952-4aeb-b0e9-31a0e9e09b64%40Spark.
For more options, visit https://groups.google.com/d/optout.

Reply via email to