[erlang-questions] Recless
Yariv Sadan
yarivvv@REDACTED
Thu Oct 12 14:34:29 CEST 2006
Hi
> This looks like a good idea to work further with.
>
> There are some problems about it, however:
> * the syntax issue, of course. I think that attempts to just use a
> parse transform (as opposed to change the parser itself) won't provide
> very readable results. Or as with the a.b.c.d suggestion, it will
> clash with something else.
Recless only applies a transformation to expressions that start with a
variable name, e.g. A.b.c.d but not a.b.c.d (at least, that's what it
*should* do -- otherwise, it's a bug). If it can't ascertain that A is
of a record type that has the field 'c', and that 'c' the field 'c' is
an instance of a record type has a field 'd', then it will compain
about a type inference error but and abandon the transformation.
Btw, only setters currently have the aformentioned syntax conflict.
Getters are safe (I'm pretty sure). E.g.
Ciry = Project.owner.city
works.
> * since one is required to declare the types of record variables,
> I'm not sure how easy it would be to use. Should the default value of
> a record field serve as a type declaration? How to handle 'undefined'
> values then? We would have to handle the equivalent of
> NullPointerExceptions :-\
Recless does look at the default declaration for a record. It searches
for fields that are records by default, and when it sees a record
instantiation, it applies the full type to the variable it matches
against. For example, this works:
-record(bar, {d,e,f = "baz"}).
-record(foo, {a,b,c=bar{})).
test() ->
A = foo{}
undefined = A.b,
"baz" = A.c.f.
Recless also understands lists and tuple matching. E.g.
[A.B] = [foo{}, foo{}],
"baz" = A.c.f,
"baz" = B.c.f
works.
>
> Finally, as a personal wish, I would rather see an implementation of
> Richard O'Keefe's abstract patterns proposal (see
> http://www.erlang.org/ml-archive/erlang-questions/200309/msg00309.html).
> It might need to be revised a little, since it is a few years old.
That would be very nice :)
Regards,
Yariv
More information about the erlang-questions
mailing list