Syntax q's

Ulf Wiger etxuwig@REDACTED
Tue Nov 2 16:42:56 CET 1999


On Tue, 2 Nov 1999, Craig Dickson wrote:


crd>First, in a function head, to bind a record argument to a variable,
crd>and also perform pattern-matching on its fields, you have to say:
crd>
crd>    f(R)
crd>        when ... R#rtype.field1 ..., ... R#rtype.field2 ... ->
crd>
crd>which isn't bad, except that it would be convenient to also bind
crd>those fields to variables at the same time. The first time I wanted
crd>to do this, it seemed intuitively obvious to me that the following
crd>should work, but it doesn't:
crd>
crd>    f(R#rtype{field1 = Var1, field2 = Var2})
crd>        when ... Var1 ..., ... Var2 ... ->

Since OTP R5B (the commercial release), and thus in the upcoming next
release of OSE, you can write:

f(R = #rtype{field1 = Var1, ...}) ->
  ...


crd>My other complaint is that the standard libraries have functions
crd>that take module and function atoms (e.g. apply/3), but which
crd>cannot take funs. For example, I would like to be able to
crd>experiment with timer:tc/3 in the Erlang shell by just declaring a
crd>fun interactively and calling tc like this:
crd>
crd>    F = fun(...) -> ... end.
crd>    timer:tc(F, [args...]).
crd>
crd>But this isn't possible because tc doesn't take a fun. I suppose
crd>this is a historical artifact, since funs are a relatively recent
crd>addition to the language. Still, it would be nice to allow funs to
crd>be used more universally.

I believe that in the next release of OSE, you'll be able to use funs in
more places than today, e.g. in spawn/1.

Perhaps not in timer:tc/1 or apply/1... yet.


/Uffe

Ulf Wiger, Chief Designer AXD 301         <ulf.wiger@REDACTED>
Ericsson Telecom AB                          tfn: +46  8 719 81 95
Varuvägen 9, Älvsjö                          mob: +46 70 519 81 95
S-126 25 Stockholm, Sweden                   fax: +46  8 719 43 44




More information about the erlang-questions mailing list