Re: PROTOPROPOSAL FOR NEW BACKSLASH is still Re: implied pascal-like"with" or "express"

[email protected] (Damian Conway)
Newsgroups perl.perl6.language.objects
Message-ID <[email protected]>
   > And that's just too much punctuation for too little value.
   > 
   > How special purpose is "with"?  Do people envision using it *only* on
   > hashes?  (I did until this email)  If so, I like Damian's version best:
   > 
   > http://www.mail-archive.com/[email protected]/msg02649.html

Unfortunately, as has been subsequently pointed out, that cunning plan is
fatally flawed, if you rely on higher order functions to keep the syntax
clean.

So I'm back to proposing that

	with (%hash) {
		...
		print $_{name};
		print @_{qw(name rank snum};
		print keys %_;
		...
	}
	
simply be sugar for:

	{ local %_=%hash;
	  do {
		...
		print $_{name};
		print @_{qw(name rank snum};
		print keys %_;
		...
	     }
	}

Oh, and %_ could become the default argument to the various hash-related
builtins, allowing for:

	with (%hash) {
		...
		print keys;
		...
	}

This is no more typing than:

	with (%hash) {
		...
		print ->{name};
		print ->{qw(name rank snum};
		print keys ??????;
		...

And it's entirely consistent with existing Perl
(it doesn't even add a new punctuation variable).

I'd also suggest that C<with> also be allowed to take 
a reference to a hash and alias %_ to the hash.
That would simplify handling nested data structures:

	with ($loholoh->[1]{to}[4]{see}) {
		...
		$_{field1} = $data1;
		$_{field2} = $data2;
		$_{field3} = $data3;
		...
	}

Damian

PS: Just *love* Larry's "yadda yadda yadda" operator!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.