[erlang-bugs] : bug
Fri Nov 30 10:28:19 CET 2007
Actually it was my impression that guard predicates could only occur
after a "when" keyword or in an "if"
and not anywhere else. This is consistent with the view that a guard
is an extension of pattern
matching and is there to produce better code in the pattern matcher.
Guard test functions are not boolean functions which return true or
false - but things which succeed or fail
in pattern matching.
Actually they could be overloaded so as to be interpreted as boolean
functions when used in expressions.
How is it today? The reference manual on the net says that guard
sequences can only occur in "if" and
after a when - and that guard tests are part of guard sequences. It
makes no mention of them
being allowed in expressions.
On Nov 30, 2007 8:53 AM, Raimo Niskanen
> My first reaction to this was that maybe is_reference/1 is
> autoimported, but it would be nice and clear if the
> "fun is_reference/1" syntax did not do autoimporting. Easier to know
> what you get. You can use "fun erlang:is_reference/1" if so inclined.
> Then again: if e.g "fun abs/1" has done autoimporting
> for years I can only say "fun is_reference/1" working
> the way Joe found out is a (mis)feature.
> On Thu, Nov 29, 2007 at 05:03:23PM +0100, Richard Carlsson wrote:
> > Bjorn Gustavsson wrote:
> > > "Joe Armstrong" <> writes:
> > >> start() ->
> > >> lists:filter(fun is_reference/1, [1,2,3]).
> > >>
> > >> %% this program compiles correctly
> > >> %% it should fail with a missing function
> > >
> > > Maybe. I am not sure whether this is a bug or a feature.
> > > ...the guard BIF is_reference/1 will be called, so the code
> > > will actually work.
> > If this is ok:
> > start() ->
> > lists:filter(fun (X) -> is_reference(X) end, [1,2,3]).
> > i.e., if is_reference/1 is in scope, being automatically imported
> > from the module 'erlang' (just like is_atom/1 and the rest), then
> > your example should also be perfectly legal and well defined.
> > (The old-style names reference/1, atom/1, etc., are however not
> > in scope outside guards, so 'fun reference/1' should cause complaints
> > about a missing function, unless you have defined it yourself.)
> > /Richard
> > _______________________________________________
> > erlang-bugs mailing list
> > http://www.erlang.org/mailman/listinfo/erlang-bugs
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
> erlang-bugs mailing list
More information about the erlang-bugs