|User defined literals firstname.lastname@example.org (Charles Fiterman) (1997-12-14)|
|From:||Charles Fiterman <email@example.com>|
|Date:||14 Dec 1997 22:37:47 -0500|
In object oriented languages we don't get to define literals. I've
always thought this was odd. We can have a class for complex numbers
but we can't say 5.7+3.51e10i. We would have to say something like
complex("5.7+3.51e10i") or complex(5.7, 3.51e10).
What would it mean to do it right?
Let us assume literals are defined by patterns and anything matching a
literal pattern would go to the right constructor. That is
5.7+3.51e10i is really shorthand for complex("5.7+3.51e10i").
We would have to have domains in which various literal patterns were
valid. The complex literal pattern might override the normal float
literal. We would need to be able to detect the intersection of
various literal definitions. That is if I added a new literal
definition and it conflicted with existing definitions I would need
meaningful error messages.
This means I would need to detect intersection of patterns. Having a
function that did that would be useful for many things
e.g. generalized locking mechanisms.
Return to the
Search the comp.compilers archives again.