Re: Cfor loop variations

2002-04-17 Thread Dave Mitchell

On Tue, Apr 16, 2002 at 06:17:24PM -0700, David Wheeler wrote:
 In Exegesis 4, Damian writes:
 
 blockquote
 It's important to note that writing:
 
 
 for a; b - $x; $y {...}
 # in parallel, iterate a one-at-a-time as $x, and b one-at-a-time as
 $y
 
 is not the same as writing:
 
 
 for a, b - $x, $y {...}
 # sequentially iterate a then b, two-at-a-time as $x and $y
 /blockquote
 
 Now, I love that the for loop can do both of these things, but the subtlety
 of the difference in syntax is likely, IMO, to lead to very difficult-
 to-find bugs. It's very easy to miss that I've used a comma when I meant to
 use a semicolon, and vice versa. And what's the mnemonic again?

Personally I really hate the use of the semicolon here - it's
counter-intuitive to everything you expect from semicolons in the 'C'
stable of languages (and English too) - ie my brain groups the terms in

for a; b - $x; $y {...}
like
for [@a]; [@b - $x]; [$y] {...}
rather than
for [@a; b] - [$x; $y] {...}

Maybe we should have something like
for a - $x; b - $y {...}
Instead.
This has the advange of being writeable as the following for clarity:
for
a - $x;
b - $y
{


But hey, what do I know - I'm not a linguist or language designer :-)

-- 
But Pity stayed his hand. It's a pity I've run out of bullets, he
thought. - Bored of the Rings



Re: Cfor loop variations

2002-04-17 Thread David Wheeler

On 4/17/02 5:38 AM, Piers Cawley [EMAIL PROTECTED] claimed:

 I've got the horrible feeling that doing it this way will lead to
 nasty ambiguities in parsing, but if that's not the case then I must
 confess that I prefer this syntax. Especially if you want to do
 something like:
 
   for @a, @b ; @c, @d - $x ; $y {...} # Apocalypse
   for @a, @b - $x ; @c, @d - $y {...}
 
 I think the second version of that looks cleaner, but neither of them
 is exactly gorgeous.

I have to agree that the second syntax is a lot cleaner for me to read. But
I see two problems with it. First, it breaks the consistency of the user of
the - operator, since that operator is now a way of declaring the arguments
to the closure that follows it. That is to say, this

  for @a - $x {...}

Is more or less equivalent to

  for @a sub ($x) {...} # pseudocode

So if you have more than one arrow operator, you're declaring more than one
subroutine closure. The arguments for each - would go into only one
closure, and it's a syntax error to not follow each one with its own
closure.

The second issue is that this syntax doesn¹t appear to support parallel
processing (or mixed processing!) unless you still use different separators
',' and ';'. IOW, in this example:

  for @a, @b - $x, $y ; @c, @d - $z {...}

Does the $x go with @a and the $y with @b? Or are @a and @b flattened and $x
and $y take two items at a time? This is the reason for the distinction
between '.' and ';' in the current proposal.

So really, I can't think of a syntax other than the one that Larry has
proposed without either violating the current rules governing the -
operator or creating new ambiguities.

FBOFW, I think we'll just have to start thinking about formatting the
proposed syntax so that it's easier to read (but obfuscators can still be
happy with cramming it all on one line). To quote Damian:

blockquote
One thing that might help is to get yourself into the habit of writing
sequential iterations on a single line:

for @x, @y - $a, $b {...}

and parallel iterations on two lines:

for @x ; @y
 - $a ; $b {...}

That generalizes nicely on the very rare occasions that you need to use
both:

for @x, @y ; @z
 - $a ; $b, $c {...}
/blockquote

And then we just have to be aware that this could be the source of subtle
bugs, and use the formatting to help us spot it.

Regards,

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





named params, @_, and pass-by-reference

2002-04-17 Thread Dave Storrs



On Thu, 11 Apr 2002, Damian Conway wrote:

 Piers wrote:

  one could always handle the first case
  more explicitly by doing:
 
 sub load_data ($filename; $version) {
$version = 1 if _.length  2;
...
 }

 Err...no. If you specify named parameters, you don't get _.


I'm a couple months behind on the discussion and haven't read
Apoc4 carefully yet, so my apologies if this has already been hashed out.

Something I've always wished for in Perl (which of course I didn't
think of during the RFC period) was a way to have self-documenting
parameter names inside a function, but still maintain pass-by-reference
semantics, and do it all without fancy, hard-to-read aliasing tricks.
Ideally, I want something like:

sub load_data ( \$filename; $version; _ ) {
$filename =~ s{/$}{};  # Affects $filename back in caller
my $protocol = shift || 'html'; # shift defaults to _
...
}

Note that here, $filename is pass-by-reference, $version is
pass-by-value, and, if extra arguments are passed, they will come in
through _ so that I can still take advantage of the fact that most list
operators default to _.  (Whether the contents of _ are p-b-v or p-b-r
I'm not weighing in on.)

Perhaps using \ in the signature to indicate p-b-r is not the
best...it could confuse people into thinking that they will need to
manually dereference the variable, which they shouldn't need to do.


Is there a way to do this now?  If not, will there be a way in
Perl6?


Dave Storrs




Re: named params, @_, and pass-by-reference

2002-04-17 Thread Jonathan Scott Duff

On Wed, Apr 17, 2002 at 11:15:15AM -0700, Dave Storrs wrote:
   Perhaps using \ in the signature to indicate p-b-r is not the
 best...it could confuse people into thinking that they will need to
 manually dereference the variable, which they shouldn't need to do.
 
   Is there a way to do this now?  If not, will there be a way in
 Perl6?

I think the syntax is now 

sub load_date ($filename is rw; $version) { ... }

Changes to $filename within load_data() affect the caller.

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]



Re: named params, @_, and pass-by-reference

2002-04-17 Thread Trey Harris

In a message dated Wed, 17 Apr 2002, Dave Storrs writes:
   sub load_data ( \$filename; $version; _ ) {

I think you can do exactly this with
sub load_data ( $filename is rw, $version, _ ) {

Yes?  Or maybe
sub load_data ( $filename is rw, $version, *@_) {

to make sure _ gets flattened?

Trey
-- 
Trey Harris
Secretary and Executive
SAGE -- The System Administrators Guild (www.sage.org)
Opinions above are not necessarily those of SAGE.





// in Perl 5.8?

2002-04-17 Thread David Wheeler

Anyone know what the chances are that some enterprising C hacker
can/will/did get the // and //= operator into Perl 5.8? Seems like it
wouldn't be a huge deal to add, and I'd love to have it sooner rather than
later.

Regards,

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





Re: Cfor loop variations

2002-04-17 Thread Aaron Sherman

On Wed, 2002-04-17 at 11:23, Jonathan Scott Duff wrote:
 On Wed, Apr 17, 2002 at 01:38:59PM +0100, Piers Cawley wrote:
  I've got the horrible feeling that doing it this way will lead to
  nasty ambiguities in parsing, but if that's not the case then I must
  confess that I prefer this syntax. Especially if you want to do
  something like:
  
  for a, b ; c, d - $x ; $y {...} # Apocalypse
  for a, b - $x ; c, d - $y {...} 
  
  I think the second version of that looks cleaner, but neither of them
  is exactly gorgeous.
 
 And while we're at it, could someone write out the equivalent of this in
 perl6 without the use of the - or the funny for syntax? I find it hard
 to think of - as synonymous to sub with either syntax above.

As usual, I'm coming into this late, and so I'm going to sound a little
wild-eyed (how do I *sound* any such thing, you may ask...)

I think this syntax is sensible in concept, but in practice, it breaks
down into incomprehensible very quickly.

If I step, back, the goal was this, right?

for LIST[;LIST...] - ARG[,ARG...][;ARG[,ARG...]...] BLOCK

It seems simple enough, but we're getting hung up because of the
multiple list thing...

I agree that while

for LIST - ARG[,ARG...] [; LIST - ARG[,ARG...]...] BLOCK

may LOOK, better, it's very broken WRT the idea that -x is sub(x) in
disguise (with topicalization, of course), and it's still hard to read,
just not AS hard.

What you're trying to have is a loop union construct, and semicolon is
fairly hard to interpret in that way. However, since this is not likely
to be the common case (not rare, but uncommon) Larry's Huffman-style
coding of syntax would seem to suggest that a longer operator is called
for anyway.

for LIST - ARG during LIST - ARG BLOCK

would seem to fit nicely (notice I'm simplifying ARG to save typing
here, but the complex case still holds), and if you accept that this is
a special case short-hand for:

for LIST - ARG during for LIST - ARG BLOCK

then you have two loops sharing a block in a well defined way to create
a single closure, and yet it stays fairly readable. Want more?

for a - $a during  - $_ during 0 .. Inf {
last unless exists $a  exists $_
...
}

If you read this as you do in English, the length of the last during
clause should control the length of the loop, so this is a nice way to
say keep looping until both are exhausted. After all, if you eat popcorn
during the big game, you don't stop watching the big game when the
popcorn runs out, but you stop eating popcorn when the game is over (at
least, I would).

This gets ugly when you mix in traditional C for (are we keeping that in
Perl6?):

for a - $a during for ($i=1000;$i$a;$i-=$a) {...}

but not by a whole lot.





Re: Cfor loop variations

2002-04-17 Thread David Wheeler

On 4/17/02 1:20 PM, Aaron Sherman [EMAIL PROTECTED] claimed:

 This gets ugly when you mix in traditional C for (are we keeping that in
 Perl6?):

Yes, but it's name is changing to Cloop.

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





Re: named params, @_, and pass-by-reference

2002-04-17 Thread Dave Storrs

[Several people said something like $var is rw  will do it)

Ah, that's right.  I had forgotten about this.

Thanks to everyone who responded.

Dave




Re: // in Perl 5.8?

2002-04-17 Thread Dave Mitchell

On Wed, Apr 17, 2002 at 01:09:43PM -0700, David Wheeler wrote:
 Anyone know what the chances are that some enterprising C hacker
 can/will/did get the // and //= operator into Perl 5.8? Seems like it
 wouldn't be a huge deal to add, and I'd love to have it sooner rather than
 later.

I hope you're referring to 5.8.x for some x != 0  ???  :-)

-- 
print+qq$}$$/$s$,$*${$}$g$s$@$.$q$,$:$.$q$^$,$@$*$~$;$.$q$mif+map{m,^\d{0\,},,${$::{$'}}=chr($+=$||1)}q10m22,42}6:17*2~2.3@3;^2$g3q/s=~m*\d\*.*g



Re: // in Perl 5.8?

2002-04-17 Thread David Wheeler

On 4/17/02 1:51 PM, Dave Mitchell [EMAIL PROTECTED] claimed:

 I hope you're referring to 5.8.x for some x != 0  ???  :-)

Do you know how late in the development process the $coderef-() feature was
added to Perl (in whatever release that was)? Ask Randal to talk about it
sometime. ;-)

But maybe things are more rigorous now, and it should be 5.8.1. Personally,
I'd rather see it sooner than later.

David

-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





Re: // in Perl 5.8?

2002-04-17 Thread Graham Barr

On Wed, Apr 17, 2002 at 01:09:43PM -0700, David Wheeler wrote:
 Anyone know what the chances are that some enterprising C hacker
 can/will/did get the // and //= operator into Perl 5.8? Seems like it
 wouldn't be a huge deal to add, and I'd love to have it sooner rather than
 later.

It is not hard todo. If you look in the archives you can probably find it, although
it will be there as ??

The problem with // is that it already has a meaning and although perl6 will redefine 
it
can we do so in perl5 ? I don't think we can.

Graham.



Re: // in Perl 5.8?

2002-04-17 Thread David Wheeler

On 4/17/02 2:17 PM, Graham Barr [EMAIL PROTECTED] claimed:

 The problem with // is that it already has a meaning and although perl6 will
 redefine it
 can we do so in perl5 ? I don't think we can.

Oh yeah, you're right. Perl 5 would have to require that it be m//, and that
would break a lot of existing code. Good point, I hadn't thought of that.

Regards,

David
-- 
David Wheeler AIM: dwTheory
[EMAIL PROTECTED] ICQ: 15726394
http://david.wheeler.net/  Yahoo!: dew7e
   Jabber: [EMAIL PROTECTED]





RE: // in Perl 5.8?

2002-04-17 Thread Brent Dax

Randal L. Schwartz:
#  David == David Wheeler [EMAIL PROTECTED] writes:
# David Anyone know what the chances are that some 
# enterprising C hacker 
# David can/will/did get the // and //= operator into Perl 5.8? Seems 
# David like it wouldn't be a huge deal to add, and I'd love 
# to have it 
# David sooner rather than later.
# 
# Not in 5.8, which is in the final freezy stages.
# Perhaps in 5.9 thus 5.10.

I'm working on a preliminary version right now.  So far it's been
surprisingly easy--touches toke.c, perly.y, opcode.pl, pp.c, and
pp_hot.c.  (Of course, it's also off an old bleadperl, but I doubt those
files change that actively.)

BTW, so far toke.c hasn't been as bad as I've heard it is.  :^)

--Brent Dax [EMAIL PROTECTED]
@roles=map {Parrot $_} qw(embedding regexen Configure)

#define private public
--Spotted in a C++ program just before a #include