Guard questions

Craig Dickson crd@REDACTED
Wed Mar 31 15:27:04 CEST 1999


Joe Armstrong wrote:

> >     (2a) f(X) when record(X, x) -> X#x.field.
> >
> >     (2b) f(#x{field = Field}) -> Field.
>
> In this case particular case I wonder why you
> use a function to abstract out the record.

Oh, that was just to provide enough of an example to demonstrate the two
possible ways of expressing the idea that the function expected an x record
as its argument, but only really wanted a field or two from it. I wouldn't
really use a function just to pull a named field out of a record! But
sometimes I've had functions that took records, but didn't really need the
record as such, only the fields; in those cases, I considered it best just
to take the record as an argument, but declare names for the field values in
the function head, as in (2b). My question was really whether the two heads
will behave any differently; (2a) is clearly going to be bypassed if X is
not of type record(x), and I was pretty sure the same was true of (2b), but
I thought I might as well ask the experts even though it seems to be
working. (You never know -- there might be some non-obvious reason to prefer
(2a).)

Thanks for your reply!

Craig




More information about the erlang-questions mailing list