I would prefer to not support improper lists as second argument for now. It
is unnecessary complexity which doesn't seem to be needed yet. However,
note we end-up supporting them as first argument of starts_with? by
definition, since we don't want to traverse the whole list.


*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Tue, Feb 21, 2017 at 7:03 PM, eksperimental <[email protected]>
wrote:

> Sorry José, I was wrong when i wrote
> > If we support improper lists, prefix could be any term, not just a list.
>
> what meant is that if we support List.ends_with?/2, then suffix could be
> any term (but I will show
> that this is still wrong)
>
> List.ends_with?([1, 2 | 3], 3)
> #=> true
>
> but that could be ambiguous,
> List.ends_with?([1, 2, 3], [2, 3])
> #=> true
>
> List.ends_with?([1 | [2, 3]], [2, 3])
> #=> true
>
> So suffix could ONLY be a list or an improper list.
>
> List.ends_with?([1, 2 | 3]], [2 | 3])
> #=> true
>
> List.ends_with?([1, 2 | 3]], [2 | 3])
> #=> true
>
> Regarding prefixes.
> We could still support improper lists as the first argument,
>
> List.starts_with?([1, 2 | 3], [1, 2])
> #=> true
>
> and improper lists as the prefix (returns true only if both lists are the
> same)
> List.starts_with?([1, 2 | 3], [1, 2 | 3])
> #=> true
>
> So wrapping up,
> lists, prefixes and suffixes could be all maybe_improper_list
>
>
> On Tue, 21 Feb 2017 16:02:58 +0100
> José Valim <[email protected]> wrote:
>
> > Excellent questions!
> >
> > I don't think we should support improper lists because there is no notion
> > of prefix for improper list. For instance, I would not expect this to
> match:
> >
> > List.starts_with?([1, 2], [1 | 2])
> >
> >
> > Because we would compare 1 == 1 and then [2] to 2. The only situation
> they
> > would match is if they are exactly equal and then the function is no
> longer
> > necessary.
> >
> >
> > *José Valim*
> > www.plataformatec.com.br
> > Skype: jv.ptec
> > Founder and Director of R&D
> >
> > On Tue, Feb 21, 2017 at 3:38 PM, eksperimental <
> [email protected]>
> > wrote:
> >
> > > Hi, List.starts_with?/2 have recently been introduced
> > > https://github.com/elixir-lang/elixir/pull/5789
> > >
> > > I was working on improving the specs and the code,
> > > and I have realized there are a few issues I would to work on.
> > >
> > > Initially would like to to know whether we should support improper
> lists,
> > > that would determine how
> > > the code can be optimized.
> > >
> > > I would say yes, we should support improper lists.
> > > But we also need to keep in mind that we will probably will end up
> adding
> > > List.ends_with?/2 too,
> > > so we need to keep that in mind
> > >
> > > If we support improper lists, prefix could be any term, not just a
> list.
> > >
> > > --
> > > 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/ms
> > > gid/elixir-lang-core/20170221213857.6c3a8f4f.eksperimental%4
> 0autistici.org
> > > .
> > > 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/ms
> gid/elixir-lang-core/20170222010356.6eaf2436.eksperimental%40autistici.org
> .
> 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/CAGnRm4%2B1LLiMX3L%3D6egZHVmQkay-L7T7Sr4zM1CeLxJvoO00TA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to