develooper Front page | perl.perl6.language.io | Postings from September 2000

Re: RFC 181 (v1) Formats out of core / New format syntax

From:
Tom Christiansen
Date:
September 18, 2000 07:43
Subject:
Re: RFC 181 (v1) Formats out of core / New format syntax
Message ID:
12471.969288185@chthon
>> >perl5 formats do NOT support lexicals
>> 
>> Eh? It looks like it, though.
>> 
>> 	my $foo;
>> 	format STDOUT =
>> 	@>>>>>>>
>> 	$foo
>> 	.
>> 
>> 	$foo = 123;
>> 	write;
>> 	$foo = 45;
>> 	write;
>> 
>> It looks *so much* that way, that I think you must be wrong.

>my $foo = 3;
>format STDOUT =
>@<<
>$foo
>.

>{ my $foo = 5;
>  write;
>  }
>---
>3

I do not think you two are arguing about the same thing.

Certainly as Bart has shown, formats *can* see lexicals.  Your
illustration does not disprove that.  It simply shows that lexical
scoping is static scoping, not dynamic scoping, and that the binding
of the variable to the format occurs as the format is declared, not
when a write executed.

This is exactly the same thing as occurs with closures in terms of
declaration/creation versus their execution.  All that matters is
what's in scope when the format or closure template is brought into
existence.  It doesn't matter what happens later, which would be
dynamic scoping, not static scoping.  And this is surely not
considered "not supporting lexicals".

--tom



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