Use-defined guard (was: RE: Enhanced type guard syntax])

Fredrik Linder fredrik.linder@REDACTED
Thu Sep 18 16:13:11 CEST 2003



> -----Original Message-----
> From: Joe Armstrong [mailto:joe@REDACTED]
> Sent: den 18 september 2003 15:58
> To: Fredrik Linder
> Cc: erlang-questions@REDACTED
> Subject: RE: Enhanced type guard syntax]
>
>
> On Thu, 18 Sep 2003, Fredrik Linder wrote:
>
> > > foo(A/integer, B/integer) ->
> > >       A * B.
> > >
> > > {X/float, Y/float} = graph:coordinates(),
> >
> > This looks really really nice!
> >
> > Again, I'd like to ask for user-defined guards, as it would
> really enhance
> > ... erlang(?).
> >
>
>   No - guards are extensions of patterns. They have to be  simple,
> so that a pattern matching compiler can do a good job on them.
>
>   If we had user defined guards somebody will write:
>
> 	foo(X) when bar(X), a == b ->
> 	   ...
>
>   Where bar(X) a user defined guard.
>
>   Now what happens if somebody writes:
>
> 	bar(P) -> P ! a, true.
>
>   But the guard fails (ie a==b) fails, did the message get sent?????
>
>   Cheers
>
> /Joe

Yes, you are right in the sense that code that utilize distribution should
not be allowed as guard functions, neither should those utilizing
"permanent" storage, such as accessing ets tables and files.

And I do realize the potential overwelming task of keeping track of these
things.

However, by allowing only a limited set of operations in guard-declared
functions (such as only allowing then to call other guard-functions) could
be the fine line that increases usability while still preserving the
consistency of the program.

The usage I am targeting is to have user-defined guards as
inspectors/selectors on ADTs.

Cheers
/Fredrik




More information about the erlang-questions mailing list