At 07:51 +0200 10/21/03, Rafael Garcia-Suarez wrote:
>Dave Mitchell wrote:
>>
>> I provisonally propose the new syntax:
>>
>> sub foo() : constant { ...}
>> and
>> sub() : constant { ...}
>>
>> which has the effect of:
>>
>> for a named sub: as soon as the sub is compiled, it is executed once in
>> scalar context, and the return value is used at the basis for a new
> > CONST CV which replaces the original CV.
>At least Eiffel uses the keyword "once" for such subroutines (that
>are executed once.) It may be more clear.
I guess it's a matter of what it is used for and how it does it.
German used to have a word for modem that described what it does:
"Datenfernuebertragungsanlage" (device to transfer data over large
distances). I'm sure glad Germans now also understand "modem"
(which, at least initially, described _how_ it's done: modulation /
demodulation). Saves a lot on the keyboard and screen space (try
translating English courseware to German within the same screen space
;-).
I like the "once" because it's shorter. On the other hand, "once" is
not a good description. In that sense, "cached" or "memoized" would
be a better description.
Finally, I think it still is a (bad) hack to have constants in a
language as a sort of second class subroutines with all the oddities
involved (most notably, not being able to use constants in a double
quoted string). So maybe we should keep it like it is (but document
it better) until we figure out what is best. There are plenty of
other things in Perl5 that catch people unsuspectedly. I think we
can live with it.
>Offhand I don't remember seeing something like this in Perl 6.
Aren't Perl6's (constant) macro's really what we're talking about here?
Liz