Re: What's MY.line?
At 5:46 AM +0100 7/11/02, [EMAIL PROTECTED] wrote: >Dan Sugalski <[EMAIL PROTECTED]> writes: > >> At 4:24 PM +0100 7/10/02, [EMAIL PROTECTED] wrote: >> >Dan Sugalski <[EMAIL PROTECTED]> writes: >> > >> >> At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote: >> >> >3. Is C<%MY> intended to reflect the PAD? >> >> >> >> Yes. >> > >> >Hey! How's this for a scary thought: >> > >> >$continuation.the_pad >> >> What's that supposed to do, though? You want to alter the pad that >> gets put in place at the top of the pad list for a continuation? No >> problem. A bad idea, mind, but no problem... :) > >I was thinking it would get the pad of the block from which the >continuation was taken. Oh, OK. That makes perfect sense, then, and if you want to write introspective code I can see it being really useful. I'll try and make sure you can do it. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: What's MY.line?
At 11:52 PM -0400 7/10/02, Chip Salzenberg wrote: >According to Dan Sugalski: >> One pad per block, rather than per sub. > >Because, of course, all blocks are subs. Got it. Yep. (Well, modulo optimizations of course ;) The place where you'll run into problems in where you have multiple variables of the same name at the same level, which you can do in perl 5. That's more problematic, and I don't think we're going to allow that. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: What's MY.line?
According to Dave Mitchell: > Based on what I rememeber from the long threads about this, Ouch. I gather, then, that nntp.perl.org does not house complete list archives, or else the discussion was not on p6-language ... ? > sub import { > caller(1).MY{'&foo'} = sub { ... }; > } Got it. -- Chip Salzenberg - a.k.a. -<[EMAIL PROTECTED]> "It furthers one to have somewhere to go."
Re: What's MY.line?
According to Dan Sugalski: > One pad per block, rather than per sub. Because, of course, all blocks are subs. Got it. -- Chip Salzenberg - a.k.a. -<[EMAIL PROTECTED]> "It furthers one to have somewhere to go."
Re: What's MY.line?
On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: > The place where you'll run into problems in where you have multiple > variables of the same name at the same level, which you can do in > perl 5. can it? can you give an example? -- In England there is a special word which means the last sunshine of the summer. That word is "spring".
Re: What's MY.line?
On Wed, Jul 10, 2002 at 11:57:02PM -0400, Chip Salzenberg wrote: > According to Dave Mitchell: > > Based on what I rememeber from the long threads about this, > > Ouch. I gather, then, that nntp.perl.org does not house complete list > archives, or else the discussion was not on p6-language ... ? don't know about nntp, but see for example, http:[EMAIL PROTECTED]/msg08203.html -- You live and learn (although usually you just live).
Re: What's MY.line?
At 7:18 PM +0100 7/11/02, Dave Mitchell wrote: >On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: >> The place where you'll run into problems in where you have multiple >> variables of the same name at the same level, which you can do in >> perl 5. > >can it? Yes. >can you give an example? [localhost:~] dan% perl my $foo = 12; print $foo; my $foo = "ho"; print $foo; 12ho[localhost:~] dan% -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: What's MY.line?
On Thu, Jul 11, 2002 at 02:29:08PM -0400, Dan Sugalski wrote: > At 7:18 PM +0100 7/11/02, Dave Mitchell wrote: > >On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: > >> The place where you'll run into problems in where you have multiple > >> variables of the same name at the same level, which you can do in > >> perl 5. > > > >can it? > > Yes. > > >can you give an example? > > [localhost:~] dan% perl > my $foo = 12; > print $foo; > my $foo = "ho"; > print $foo; > 12ho[localhost:~] dan% ah, I see what you mean. I hope that'll be a syntax error rather than just a warning in perl6. -- "Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony." Dennis - Monty Python and the Holy Grail.
Re: What's MY.line?
At 2:47 PM -0400 7/11/02, Chip Salzenberg wrote: >According to Dan Sugalski: >> At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote: >> >3a. If so, how can one distinguish among the e.g. many C >> >variables declared within the current function? >> >> One pad per block, rather than per sub. > >I just remembered why I thought that woundn't work: BEGIN is a block. > >my $x = 1; >BEGIN { %MY::{'$y'} = \$x } >print $y; > >So what do I need to make this aliasing work? C<%OUTER::MY::>? Yup. Or caller, or something. I'm not sure what Larry's planning on for the syntax. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: What's MY.line?
At 7:35 PM +0100 7/11/02, Dave Mitchell wrote: >On Thu, Jul 11, 2002 at 02:29:08PM -0400, Dan Sugalski wrote: >> At 7:18 PM +0100 7/11/02, Dave Mitchell wrote: >> >On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: >> >> The place where you'll run into problems in where you have multiple >> >> variables of the same name at the same level, which you can do in >> >> perl 5. >> > >> >can it? >> >> Yes. >> >> >can you give an example? >> >> [localhost:~] dan% perl >> my $foo = 12; >> print $foo; >> my $foo = "ho"; >> print $foo; >> 12ho[localhost:~] dan% > >ah, I see what you mean. I hope that'll be a syntax error rather than just >a warning in perl6. Me too, since it makes pulling lexicals out by name rather tricky. Doable, but tricky. (And messy, and somewhat expensive) That's Larry's call, though. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: What's MY.line?
According to Dan Sugalski: > At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote: > >3a. If so, how can one distinguish among the e.g. many C > >variables declared within the current function? > > One pad per block, rather than per sub. I just remembered why I thought that woundn't work: BEGIN is a block. my $x = 1; BEGIN { %MY::{'$y'} = \$x } print $y; So what do I need to make this aliasing work? C<%OUTER::MY::>? -- Chip Salzenberg - a.k.a. -<[EMAIL PROTECTED]> "It furthers one to have somewhere to go."
Re: What's MY.line?
On Thu, Jul 11, 2002 at 02:29:08PM -0400, Dan Sugalski wrote: > At 7:18 PM +0100 7/11/02, Dave Mitchell wrote: > >On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: > >> The place where you'll run into problems in where you have multiple > >> variables of the same name at the same level, which you can do in > >> perl 5. > > > >can it? > > Yes. > > >can you give an example? > > [localhost:~] dan% perl > my $foo = 12; > print $foo; > my $foo = "ho"; > print $foo; > 12ho[localhost:~] dan% Of course it's a -w warning now: "my" variable $foo masks earlier declaration in same scope at - line 3. and I can imagine it becoming a mandatory warning in later versions of perl5 (and/or perhaps in future they'll be a way to enable warnings relevant to migration to perl6). Tim.
Re: What's MY.line?
On Thursday 11 July 2002 11:47 am, Chip Salzenberg wrote: > According to Dan Sugalski: > > At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote: > > >3a. If so, how can one distinguish among the e.g. many C > > >variables declared within the current function? > > > > One pad per block, rather than per sub. > > I just remembered why I thought that woundn't work: BEGIN is a block. > >my $x = 1; >BEGIN { %MY::{'$y'} = \$x } >print $y; Even worse, you should be able to modify lexicals even outside your scope. sub violate_me { caller(1).MY{'$y'} := caller(1).MY{'$x'};# hypothetical syntax } { my $x = 1; my $y; # Might be able to BEGIN { violate_me() } instead violate_me(); print $y; } Ashley Winters -- When you do the community's rewrite, try to remember most of us are idiots.
%MY (was What's MY.line?)
At 01:08 PM 7/11/2002 -0700, Ashley Winters wrote: >On Thursday 11 July 2002 11:47 am, Chip Salzenberg wrote: > > According to Dan Sugalski: > > > At 9:50 PM -0400 7/9/02, Chip Salzenberg wrote: > > > >3a. If so, how can one distinguish among the e.g. many C > > > >variables declared within the current function? > > > > > > One pad per block, rather than per sub. > > > > I just remembered why I thought that woundn't work: BEGIN is a block. > > > >my $x = 1; > >BEGIN { %MY::{'$y'} = \$x } > >print $y; > >Even worse, you should be able to modify lexicals even outside your scope. > >sub violate_me { > caller(1).MY{'$y'} := caller(1).MY{'$x'};# hypothetical syntax >} > >{ > my $x = 1; > my $y; # Might be able to BEGIN { violate_me() } instead > violate_me(); > print $y; >} This reminds me why I don't use Perl4 'local' anymore. And now we have even uglier ways to write poor code. :) The only real use I can see of %MY is debugging. If people are going to take handles to pads and modify lexicals in closures, continuations and routines from the outside, it probably means that the item needs to be a class. And side effects like "I call you, you modify me invisibly" seems more like taking dangerous drugs than programming. Yep, I warned you about calling that routine, now look what it did to your brains. -Melvin
Re: What's MY.line?
At 9:18 PM +0100 7/11/02, Tim Bunce wrote: >On Thu, Jul 11, 2002 at 02:29:08PM -0400, Dan Sugalski wrote: >> At 7:18 PM +0100 7/11/02, Dave Mitchell wrote: >> >On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: >> >> The place where you'll run into problems in where you have multiple >> >> variables of the same name at the same level, which you can do in >> >> perl 5. >> > >> >can it? >> >> Yes. >> >> >can you give an example? >> >> [localhost:~] dan% perl >> my $foo = 12; >> print $foo; >> my $foo = "ho"; >> print $foo; >> 12ho[localhost:~] dan% > >Of course it's a -w warning now: > > "my" variable $foo masks earlier declaration in same scope at - line 3. Yep, that's warned for as long as I can remember, though that isn't all that long, I suppose. Still, it's valid. Wonder how many people do that now, completely by accident... >and I can imagine it becoming a mandatory warning in later versions >of perl5 (and/or perhaps in future they'll be a way to enable >warnings relevant to migration to perl6). I'd hope that it would be one of the things we wouldn't support in the perl 5 to perl 6 migration tool. Since it's likely always (or darned close to always) an error, I don't think it'll be a big problem. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: What's MY.line?
On Thu, Jul 11, 2002 at 03:18:27PM -0400, Dan Sugalski wrote: > At 7:35 PM +0100 7/11/02, Dave Mitchell wrote: > >On Thu, Jul 11, 2002 at 02:29:08PM -0400, Dan Sugalski wrote: > >> At 7:18 PM +0100 7/11/02, Dave Mitchell wrote: > >> >On Thu, Jul 11, 2002 at 10:41:20AM -0400, Dan Sugalski wrote: > >> >> The place where you'll run into problems in where you have multiple > >> >> variables of the same name at the same level, which you can do in > >> >> perl 5. > >> > > >> >can it? > >> > >> Yes. > >> > >> >can you give an example? > >> > >> [localhost:~] dan% perl > >> my $foo = 12; > >> print $foo; > >> my $foo = "ho"; > >> print $foo; > >> 12ho[localhost:~] dan% > > > >ah, I see what you mean. I hope that'll be a syntax error rather than just > >a warning in perl6. > > Me too, since it makes pulling lexicals out by name rather tricky. > Doable, but tricky. (And messy, and somewhat expensive) That's > Larry's call, though. Is there any specific case where you can't treat { my $foo = 12; print $foo; my $foo = "ho"; print $foo; } as { my $foo = 12; print $foo; { my $foo = "ho"; print $foo; } } (where my outer {}s may just be the scope represented by the beginning and end of the file) ie implicitly start a new block just before any duplicate my, which continues until the point the current block ends. Nicholas Clark -- Even better than the real thing:http://nms-cgi.sourceforge.net/
Re: What's MY.line?
On Thu, Jul 11, 2002 at 10:37:27PM +0100, Nicholas Clark wrote: > Is there any specific case where you can't treat > > { > my $foo = 12; > print $foo; > my $foo = "ho"; > print $foo; > } > > as > > { > my $foo = 12; > print $foo; > { > my $foo = "ho"; > print $foo; > } > } Well, it B*gg*rs up %MY:: The currently planned semantics are: { my $x; exists %MY::{'$x'}; # true; } and { my $x; { exists %MY::{'$x'}; # false } } so consider: { my $x; my $dup; my $dup; exists %MY::{'$x'}; # true? } which invisibly becomes { my $x; my $dup; { my $dup; exists %MY::{'$x'}; # false? } } -- "But Sidley Park is already a picture, and a most amiable picture too. The slopes are green and gentle. The trees are companionably grouped at intervals that show them to advantage. The rill is a serpentine ribbon unwound from the lake peaceably contained by meadows on which the right amount of sheep are tastefully arranged." Lady Croom - Arcadia
Re: What's MY.line?
At 11:45 PM +0100 7/11/02, Dave Mitchell wrote: >On Thu, Jul 11, 2002 at 10:37:27PM +0100, Nicholas Clark wrote: >> Is there any specific case where you can't treat >> >> { >>my $foo = 12; >>print $foo; >>my $foo = "ho"; >>print $foo; >> } >> >> as >> >> { >>my $foo = 12; >>print $foo; >>{ >> my $foo = "ho"; >> print $foo; >>} >> } > >Well, it B*gg*rs up %MY:: True, but if we're only worrying about it for perl 5 code being translated, it's not a big deal since it won't be using %MY. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: %MY (was What's MY.line?)
At 4:43 PM -0400 7/11/02, Melvin Smith wrote: >The only real use I can see of %MY is debugging. If people are going >to take handles to pads and modify lexicals in closures, continuations >and routines from the outside, it probably means that the item needs to >be a class. Yeah, I'm expecting it to be used mainly for introspective things. It's also useful, at compile time, for changing the caller's environment, but that's not what we're worried about, I expect. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Perl6 grammar (take V)
It's time for my weekly post to this old thread. The grammar has grown enough to deserve more than one file, and is starting to change in new directions. For example, it's now Turing-complete, if you have a Parrot engine and a bit of spare time. Call it a primitive "demo version" of some of Perl 6's features. If nothing else, it will let you start training your fingers to 'concatenate' _$like _$this. What's currently "supported": - most binary operators - arithmetic hyper-operators - chained comparisons - the ternary operator (both r- and l-value) - if/elsif/else (even "unless" and the feared "elsunless";) - void subroutines with declared parameter lists (only) - local variables (only -- i.e. "use UberStrict"). - arrays and scalars (only -- no hashes, closures, references) The fact that I've been able to whip this up in a couple thousand lines of code is a remarkable testament to Parrot's maturity, and to the wealth of tools available in Perl 5. In particular, without The Damian's Parse::RecDescent, Melvin Smith's IMCC, and Sarathy's Data::Dumper, it never would have been possible. Grammar fixes: - Fixed a bug with parameter initializers: "sub f($x = 23, $y)" now parses as "f(($x = 23), ($y))", not "f($x = (23, $y))" - Fixed a number of bugs sent in by Jonh Kingsley: - "sub f($a; $b, *@c)" (i.e. a sub with both optional and slurping parameters) now parses. - low-precedence 'and', 'or', 'xor' are now allowed within suitably-parenthesized expressions, such as "if (1 and 2)". Interestingly, you can now put a multi-dimensional array as the test of an "if". This is probably a feature that will go away at some point in the future. - "if (a && b)" is parsed correctly, not as "if (a & (&b))" - "f(2,3),4" reverts to "(f(2,3)),4" rather than "f((2,3),4)" through a bit of chicanery that allows "if" and other control structures to take parens around their first arguments. - "%a{somefunction($withargs)}" is legal. It used to see 'somefunction' and treat it as a bare hash key, then freak out about the open paren. - "last if $foo" and related cases where a guard was parsed as a label name. - empty programs and blocks - "stmt until expr" Changes: - Kingsley's changes: - handles comments - foreach decl(?) '(' expr ')' block - statement guards (e.g. "do_something() unless $foo") cannot be used with functions taking a closure as their last argument (e.g. "for", "elsunless"). This avoids a nasty ambiguity with things like this: if 1 { A } if foo { B } ==> guarded_stmt("if(1, {A})", if, "foo({B})") or ==> stmts("if(1, {A})", "if(foo(), {B})") - significant reorganization and tidying of files. The grammar now lives in its own module, and doesn't stomp on main's namespace with wild abandon. It's not a simple one-file install anymore, but it's getting big enough to maybe justify jumping through more hoops. - "Human-readable" output is gone, as it was more trouble than it was worth to maintain. The default now is to output the parse tree through Data::Dumper (there may be other tools to inspect Perl data structures in a more legible format). Next to do: - Function return values. - More informative error messages. They're currently... cryptic. - Having no built-in functions is kind of frustrating. Adding a few more things would be nice. - sub declarations. A standard function for turning a prototype into an argument context rule is needed eventually, and would eliminate the current nasty builtin hack in the compiler and parser. - rip out - Globals. - Handling of "closures" for if-blocks is completely bogus now -- they're always inlined, as there are no nested scopes. Once these are in, the current closure-handling will go away. (If you've read this far, I'm impressed. It took me several tries to get here myself) /s grammar.tgz Description: Binary data
Re: %MY (was What's MY.line?)
On Thu, Jul 11, 2002 at 04:43:34PM -0400, Melvin Smith wrote: > And side effects like "I call you, you modify me invisibly" seems > more like taking dangerous drugs than programming. > > Yep, I warned you about calling that routine, now look what it did to > your brains. Um, I shouldn't really mention Devel::LexAlias then, since with it you can already write caller(1).MY{'$y'} := caller(1).MY{'$x'}; as lexalias(1, "$y", upto(1, "$x")); Where upto is would be a simple wrapper around my Devel::Caller::caller_cv and Robin Houston's PadWalker::peek_sub No, I'm not waiting till perl6 for the drugs to kick in... -- Richard Clamp <[EMAIL PROTECTED]>
Re: What's MY.line?
Chip Salzenberg writes: >Ouch. I gather, then, that nntp.perl.org does not house complete list >archives, or else the discussion was not on p6-language ... ? It should have complete archives. It uses the same backend data as the html version on archive.develooper.com.