Re: What can be hyperoperated?

2002-01-29 Thread Dave Storrs


Note:  I'm actually not talking about hyperoperators below, or
map/grep/sort.  Just 'for'.


On Sat, 26 Jan 2002 12:32:06 -0600, Jonathan Scott Duff wrote:

 @result = for @a; @b - $a; $b { $a op $b }

I'd like to chime in withthe people who have already said that the
semicolons are a bit confusing.

I'd like to propose a slightly different syntax.  Is this maybe valid, or
have I missed a gaping problem?


#   Simplest case: one data source, pulling elements one at a time,
#   operating against a constant
@result = for @a - ($a)  { $a + 2 }

More formally, this would be:

for LIST - LIST [[, LIST - LIST]...] CLOSURE (returns: LIST)

So, you could write things like so:

#   pull elements off two-by-two
for @a - $x, $y { ... }

#   flatten @a, @b together, pull elements off two-by-two
for @a, @b - $x, $y { ... }

#   pull one off @a, one off @b
for @a - $x,
@b - $y
{ ... }

#   pull one off @a, two off @b
for @a - $x,
@b - $y, $z
{ ... }


Of course, all of these only DWIM if - knows that it takes exactly one
item on the left, and a list on the right.

As an extra bit of magic, perhaps, when the only thing to the left of -
is a scalar, it could reduce to this (in Perl5 terms):

#   This Perl6:
for $_ - $x { ... }

#   is the same as this Perl5:
{
  my $x = $_;
  local ($_);
  { ... }
}


Dave Storrs





Re: What can be hyperoperated?

2002-01-28 Thread Larry Wall

[EMAIL PROTECTED] writes:
: Simon wrote:
: 
:  Given hyperoperators, I wonder if we can actually drop map.
: 
: So:
: 
:   @result = map { block } @data;
: 
: becomes:
: 
:   @result = {block}^.(@data);
: 
: Hmmm.

Some people might think of it more like this:

@result = @data ^. {block};

except that {block} would be parsed as a subscript, and you want
argument binding, so it starts looking more like:

@result = @data ^- $a {block};

But - really is a term-forcer, so that means we're really talking
about the bare ^ operator:

@result = @data ^ $subref;

That's gettin' kinda scary.

Larry



Re: What can be hyperoperated?

2002-01-28 Thread Simon Cozens

On Mon, Jan 28, 2002 at 11:30:41AM -0800, Larry Wall wrote:
   @result = @data ^ $subref;
 
 That's gettin' kinda scary.

Hence the original question. :)

-- 
Sendmail may be safely run set-user-id to root.
-- Eric Allman, Sendmail Installation Guide



RE: What can be hyperoperated?

2002-01-28 Thread Brent Dax

Larry Wall:
# Some people might think of it more like this:
#
#   @result = @data ^. {block};
#
# except that {block} would be parsed as a subscript, and you want
# argument binding, so it starts looking more like:
#
#   @result = @data ^- $a {block};
#
# But - really is a term-forcer, so that means we're really talking
# about the bare ^ operator:
#
#   @result = @data ^ $subref;
#
# That's gettin' kinda scary.

Then maybe we require (or at least request) a do:

@result = @data ^do $subref;

Is that a little closer to the comfort zone?

However, note that that still leaves grep as-is, with the old format.
Perhaps that's a clue that we should leave this alone, though perhaps
with the args to map and grep rearranged.

--Brent Dax
[EMAIL PROTECTED]
Parrot Configure pumpking and regex hacker
Check out the Parrot FAQ: http://www.panix.com/~ziggy/parrot.html (no,
it's not mine)

obra . hawt sysadmin chx0rs
lathos This is sad. I know of *a* hawt sysamin chx0r.
obra I know more than a few.
lathos obra: There are two? Are you sure it's not the same one?




Re: What can be hyperoperated?

2002-01-28 Thread Richard J Cox

In article [EMAIL PROTECTED], [EMAIL PROTECTED] 
(Simon Cozens) wrote:

 On Sat, Jan 26, 2002 at 04:52:53PM -0800, Larry Wall wrote:
  Perhaps we shouldn't be using ; for this.
 
 Given hyperoperators, I wonder if we can actually drop map.

Something like

@res = ^{ DoSomething($a) }, @source - $a;

?

But that's put the block first again...


-- 
[EMAIL PROTECTED]



Re: What can be hyperoperated?

2002-01-28 Thread Larry Wall

Simon Cozens writes:
: Given hyperoperators, I wonder if we can actually drop map.

Before someone panics completely, I suppose I should point out that I'm
not terribly interested in dropping the current Cmap syntax.  It's
essentially a method on a closure in its current form, which doesn't
rule out reversing it and having a Cmap method on a list that takes a
closure as an argument.  Nor does it rule out turning Cmap inside out
into some fandangled hyperoperator that people will be looked at funny
for using anywhere except in an obfuscated Perl code contest.

Part of the idea of relaxing what's a keyword and what's just a global
subroutine or a universal method is that we can do TMTOWTDI even better.
Our quest is not to reinvent a certain constrictive snake, poorly or
otherwise.

Larry



Re: What can be hyperoperated?

2002-01-28 Thread Larry Wall

[EMAIL PROTECTED] writes:
: On Fri, Jan 25, 2002 at 06:03:55PM -0800, Larry Wall wrote:
:  Do they need to?  In the simple case, the hyperoperator provides list
:  context to its arguments, but just calls the scalar operation repeatedly
:  to fake up the list operation.  Any operator
:  
:  @result = @a ^op @b
:  
:  is really just something like
:  
:  @result = for @a; @b - $a, $b { $a op $b }
: 
: Just to make sure I'm not confused, the for loop above should really
: look like this:
: 
:   @result = for @a; @b - $a; $b { $a op $b }
: 
: right?  I re-read the Apocalypse and it says that both of these would
: be the same, but if that's the case, then I don't understand how you
: would take items two at a time across multiple streams.

Good question.  Maybe we'll just have to require the semicolon.  That
would make one less exception, and allow your two-at-a-time-alternately
to work.  Though if that's not what they intended, it'd be a subtle bug...

Larry



Re: What can be hyperoperated?

2002-01-27 Thread Randal L. Schwartz

 Damian == Damian  [EMAIL PROTECTED] writes:

Damian @result = {block}^.(@data);

But hyperdot sort hyperdot doesn't roll off the tongue as easy as
map sort map!

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: What can be hyperoperated?

2002-01-27 Thread damian

 Damian @result = {block}^.(@data);
 
 But hyperdot sort hyperdot doesn't roll off the tongue as easy as
 map sort map!

H. You could always overload binary - to implement the sort.
Then it would be:

hyper dot dash dot

Otherwise known in Morse circles as:

hyper-r

;-)

Damian



Re: What can be hyperoperated?

2002-01-26 Thread Randal L. Schwartz

 Larry == Larry Wall [EMAIL PROTECTED] writes:

Larry @result = for @a; @b - $a, $b { $a op $b }

Larry (presuming we make Cfor actually act like Cmap).

Why not just make map do that?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: What can be hyperoperated?

2002-01-26 Thread Damian Conway

 Larry @result = for @a; @b - $a, $b { $a op $b }
 
 Larry (presuming we make Cfor actually act like Cmap).
 
 Why not just make map do that?

The order of Cmap's arguments is wrong. To make the - extraction
syntax work we need the data being iterated to be on the left and the
processor block (actually a closure in Perl 6) to be on the right.

Damian



Re: What can be hyperoperated?

2002-01-26 Thread Jonathan Scott Duff

On Fri, Jan 25, 2002 at 06:03:55PM -0800, Larry Wall wrote:
 Do they need to?  In the simple case, the hyperoperator provides list
 context to its arguments, but just calls the scalar operation repeatedly
 to fake up the list operation.  Any operator
 
 @result = @a ^op @b
 
 is really just something like
 
 @result = for @a; @b - $a, $b { $a op $b }

Just to make sure I'm not confused, the for loop above should really
look like this:

@result = for @a; @b - $a; $b { $a op $b }

right?  I re-read the Apocalypse and it says that both of these would
be the same, but if that's the case, then I don't understand how you
would take items two at a time across multiple streams.

I expect @a;@b-$a;$b to assign @a[0] to $a, @b[0] to $b, etc.
and @a;@b-$a,$b to assign @a[0] to $a, @a[1] to $b, etc, 

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]



Re: What can be hyperoperated?

2002-01-26 Thread Larry Wall

Damian Conway writes:
:  Larry @result = for @a; @b - $a, $b { $a op $b }
:  
:  Larry (presuming we make Cfor actually act like Cmap).
:  
:  Why not just make map do that?
: 
: The order of Cmap's arguments is wrong. To make the - extraction
: syntax work we need the data being iterated to be on the left and the
: processor block (actually a closure in Perl 6) to be on the right.

Well, that's not insurmountable, but it would require parens if we
stuck with the semicolon notation.  This would find an end of statement
too soon, after the @a:

 @result = map - $a; $b { $a op $b } @a; @b;

so it'd probably have to be written as one of

 @result = map - $a; $b { $a op $b }, (@a; @b);
 @result = map (- $a; $b { $a op $b }, @a; @b);
 @result = (map - $a; $b { $a op $b }, @a; @b);
 (@result = map - $a; $b { $a op $b }, @a; @b);

That's starting to get up there on the grottiness meter.  Since semicolon
is probably just separating lists within lists, perhaps

 @result = map - $a; $b { $a op $b }, [@a], [@b];

is a valid alternative.  But it's still not as comely as the Cfor,
which never needs the parens, since it knows the {} is coming.

Perhaps we shouldn't be using ; for this.

Larry



Re: What can be hyperoperated?

2002-01-26 Thread damian

Larry pondered:

 Perhaps we shouldn't be using ; for this.

That has occurred to me on several occasions but, checking my pockets, I
find I'm fresh out of spare symbols to replace it with.

We could always use colon, of course ;-)

Damian



Re: What can be hyperoperated?

2002-01-26 Thread Larry Wall

[EMAIL PROTECTED] writes:
: Larry pondered:
: 
:  Perhaps we shouldn't be using ; for this.
: 
: That has occurred to me on several occasions but, checking my pockets, I
: find I'm fresh out of spare symbols to replace it with.
: 
: We could always use colon, of course ;-)

Well, more likely than that would be double colon.  It would stand out
better:

for @a :: @b :: @c - $a :: $b :: $c { ... }

And it would probably not interfere much with the doubledoubledots
of the ??:: operator.  (Certainly less than the ; overloading.)

On the other hand, semicolon works out really nicely within brackets
for multidimensional slices, and the mathematicians like it.  And I
don't know how the :: would fit in with other adverbial generalities.

Larry



Re: What can be hyperoperated?

2002-01-26 Thread Simon Cozens

On Sat, Jan 26, 2002 at 04:52:53PM -0800, Larry Wall wrote:
  @result = map - $a; $b { $a op $b } @a; @b;

Something seems wrong with this, but I can't quite put my finger
on what it is. I think it's the - directly after map - - looks
too much like an operator. And even if you read - as the natural
to, you get map to $a and $b, perform $a op $b, for @a and @b  
I'd be happier with

map @a; @b - $a; $b { $a op $b }

(Map elements of @a and @b to $a and $b, and do '$a op $b') but
the semicolons seem blecherous there. But this is starting to look
more like ML than Perl.

 That's starting to get up there on the grottiness meter.  Since semicolon
 is probably just separating lists within lists, perhaps
 
  @result = map - $a; $b { $a op $b }, [@a], [@b];

But (@a; @b) *is* a list of two lists, so you'd want to keep that.

 is a valid alternative.  But it's still not as comely as the Cfor,
 which never needs the parens, since it knows the {} is coming.
 
 Perhaps we shouldn't be using ; for this.

Given hyperoperators, I wonder if we can actually drop map.

-- 
Calm down, it's *only* ones and zeroes.



Re: What can be hyperoperated?

2002-01-26 Thread damian

Simon wrote:

 Given hyperoperators, I wonder if we can actually drop map.

So:

@result = map { block } @data;

becomes:

@result = {block}^.(@data);

Hmmm.

Damian



Re: What can be hyperoperated?

2002-01-26 Thread damian

 On the other hand, semicolon works out really nicely within brackets
 for multidimensional slices, and the mathematicians like it.  And I
 don't know how the :: would fit in with other adverbial generalities.

Yes, I think semicolon is the correct solution.

We just have to explain that it's only allowed to be a naked
singularity within a Cfor. Elsewhere it has to be decently shielded
by the statement event horizon of a pair of brackets.

;-)

Damian



What can be hyperoperated?

2002-01-25 Thread Simon Cozens

I'm trying to answer the question what does ^ mean?.
Can anything be hyperoperated, or just a built-in set of operations?
If anything, can user's subroutines be hyperoperated? How will they
know that they're being called in hyper context? If a built-in set
of operations, which ones?

-- 
You are in a maze of UUCP connections, all alike.



Re: What can be hyperoperated?

2002-01-25 Thread Larry Wall

Simon Cozens writes:
: I'm trying to answer the question what does ^ mean?.
: Can anything be hyperoperated, or just a built-in set of operations?

Probably anything that is sufficiently scalar in its typology.

: If anything, can user's subroutines be hyperoperated?

Why not?  (Provided the type signature isn't too wacky.)

: How will they know that they're being called in hyper context?

Do they need to?  In the simple case, the hyperoperator provides list
context to its arguments, but just calls the scalar operation repeatedly
to fake up the list operation.  Any operator

@result = @a ^op @b

is really just something like

@result = for @a; @b - $a, $b { $a op $b }

(presuming we make Cfor actually act like Cmap).

For the case where one or the other argument is a scalar, we can just
replicate it to a list.

If the PDL folks want to get fancier, I'm sure we can arrange overloading
of ^op as easily as op.

Larry



Re: What can be hyperoperated?

2002-01-25 Thread Simon Cozens

On Fri, Jan 25, 2002 at 06:03:55PM -0800, Larry Wall wrote:
 Do they need to?  In the simple case, the hyperoperator provides list
 context to its arguments, but just calls the scalar operation repeatedly
 to fake up the list operation. 

Cool. So as far as the parser cares, ^ is simply a flag meaning carry
out the next operation in an interesting way. That helps.

-- 
He was a modest, good-humored boy.  It was Oxford that made him insufferable.