develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24250] "return" required in some anonymous closures

From:
Elizabeth Mattijsen
Date:
October 21, 2003 03:58
Subject:
Re: [perl #24250] "return" required in some anonymous closures
Message ID:
p05111b06bbbabe02d20b@[192.168.56.2]
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



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About