[erlang-questions] guards

Martin Engström <>
Sat Jul 25 11:23:20 CEST 2009


On Sat, Jul 25, 2009 at 11:11 AM, Dave Pawson <> wrote:

> 2009/7/25 Johnny Billquist <>:
>
> >>> It is little bit overcomplicated version of
> >>>
> >>> filterHelper([X], Int, Result) when X =< Int -> [X|Result];
> >>
> >> Mmm. Thanks... I think :-)
> >> (I'm trying to learn!)
> >>
> >> Does that check for a list length of 1?
> >
> > A pattern of [X] can only match a list with one element.
>
> Couldn't X be a variable which might be a tuple or ... almost anything?
> Or is this pattern matching logic, that implies it is as you say?
>
 Yes, X would match anything. But [X] matches only a list with exactly one
element. ;)
/Martin


More information about the erlang-questions mailing list