[erlang-questions] guards

Dave Pawson dave.pawson@REDACTED
Sat Jul 25 10:46:55 CEST 2009


2009/7/25 Hynek Vychodil <vychodil.hynek@REDACTED>:
>
>
> On Sat, Jul 25, 2009 at 4:50 AM, Dave Pawson <dave.pawson@REDACTED> wrote:
>>
>> filterHelper(Lst,Int,Result) when ((length(Lst) == 1) and
>> (lists:nth(1,Lst) =< Int)) ->
>>    [lists:nth(1,Lst) | Result];
>
> 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?
As well as the value being <=  (who the heck chose =<
that is a real kludge!!!) Int?



>
> and also lists:nth(1,L) is equivalent of hd(L) which can be used in guards
> but in most of time use list decomposition in pattern match is more
> effective way to do it.

Ah! Didn't know about hd(L).
   Is there a quick reference chart for Erlang Bofs, perhaps the common
  module functions?
  Seems its something to fight going into any language!

Thanks Kynek.


regards
-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk


More information about the erlang-questions mailing list