things that look different

Scott Penrose scottp at dd.com.au
Tue Oct 7 18:58:32 CDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Wednesday, Oct 8, 2003, at 00:28 Australia/Melbourne, Michael 
Stillwell wrote:

> On the topic of things that look different but do (almost?) the same 
> thing, is there ever any reason to prefer one of these over the other:
>
> my $v1 = do {
>   1;
> };
>
> my $v2 = sub {
>   1;
> }->();
>
> ?

I guess it is just execution time. I would prefer the first...

It is clearer to the next programmer if they see...

	do = Execute now
	sub = Keep for later

Of course you can do the sub { ... }->() but that is just ugly (as you 
said) and adds some confusion.

On the other hand it is always good to know how something works. You 
can see now how a do {} can be created from a sub {} :-)

Scott

> (The sub approach lets you do an actual return, which does suit the 
> construction, but the "}->();" bit sure is ugly...)
>
>
>
>
> --M.
>
> -- 
> http://beebo.org
>
>
>
>
>
>
> -- 
> http://beebo.org
>
>
>
>
- -- 
Scott Penrose
Welcome to the Digital Dimension
http://www.dd.com.au/
scottp at dd.com.au

Dismaimer: Contents of this mail and signature are bound to change 
randomly. Whilst every attempt has been made to control said 
randomness, the author wishes to remain blameless for the number of 
eggs that damn chicken laid. Oh and I don't want to hear about 
butterflies either.

Please do not send me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (Darwin)
Comment: For info see http://www.gnupg.org

iD8DBQE/g1MrDCFCcmAm26YRAjgvAKCBetXUKKTJo+EPlXm8vD4DELEKzwCgnx8i
RgD3j2IMmjQLRi1P7vUyhLg=
=ZmI7
-----END PGP SIGNATURE-----




More information about the Melbourne-pm mailing list