Hi,
I recently discovered in Erlang the capability to do OO-style method
dispatch. It's pretty neat. I had no idea it worked but it does. For
example, take an ErlyDB module, e.g. 'person', then type:
P = person:new_with({name, "Foo"}),
P:save().
It's equivalent to
P = person:new_with({name, "Foo"}),
Module = element(1, P),
Module:save(P).
That's very cool. It gives you a convenient way to write generic logic
with runtime type resolution. I prefer it to writing
P = person:new_with({name, "Foo"}),
person:save(P).
which is slightly more verbose and less generic.
Here's the problem: this works for the 'save()' function because it
takes only one parameter, but because of the way ErlyDB orders
parameters in generated code, it doesn't work with functions with
multiple parameters. Specifically, the Tuple:function() notation
passes the Tuple value as the *last* parameter to the function,
whereas ErlyDB expects it to be the _first_ parameter. E.g., to set
the name, you could write
person:name(P, "John")
but this wouldn't work:
P:name("John")
because of ErlyDB's parameter ordering. To make it work, we would have
to change the order of parameters in setters, e.g.
person:name("John", P).
So, to take advantage of this language feature, we would have to
change all of ErlyDB's functions that take a record as their first
parameter, and make it their last parameter. What do you think? This
change will break a lot of existing code, but I think in the long run
it'll be worth it.
Another option is to keep the old code generation style optional via a
compilation flag. It'll be more work to implement and will cause more
bloat in ErlyDB, but some people may appreciate the backwards
compatibility.
Yariv
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---