Hyper-operators and Underscore

2001-10-06 Thread Erik Lechak



Hello all,

I have been using Perl for years.  It is the language of choice for most
of my needs. This is my first time posting.  I have read Apocalypse 3
and many of your responses.

Issues:

1)  Binary _or string concatenation
2)  RFC 082: Arrays: Apply operators element-wise in a list context
3)  Special variable representing index of array in foreach
structure $# maybe (not in apocalypse3, I think)


1) Binary _or string concatenation

The thought of using _ to concatenate strings is a little
disappointing to me.

reasons for the disappointment :

 a) I just plain don't like to use the _ key.  Hitting the shift key
and the - key just does not feel right.  I call this the
Huffman-Carpel-Tunnel coded argument.  That is to say that the more
often an operator is used, make it cause the least amount of pain and
physical damage.  And I merge strings a lot in Perl.

 b) I do not like the idea that you must have a space before the
underscore so that it is not lumped into the variable name.
  i.e.  $a=$b_$c;  is wrong.  You must type$a=$b _$c
$a_=$b; is wrong.  You must type $a _=$b;

  Even though it is a little cramped, sometimes I code that way.  Perl5
lets me put that operator right up next to the variable and I want Perl6
to allow it as well.  I have looked at tons of other programmers code
and most do this and take it for granted.  And be honest with a quick
look above can you see the difference.

 c) Because of reason b.  I find a little comfort in thinking of the
string concatenation operator as  _ that is a space followed by the
underscore. That way I could apply that rule universally. And then I
thought of the RFC 082 section of Apocalypse3 and hyper operators.
Because if it eases your mind to think of it as  _, then to be
consistent the hyper operator should be ^ _ not ^_.
  i.e.  @a=@b^_@c;   Correct according to apocalypse 3, but what
happened to the space
@a=@b$ _@c;   Super ugly but would be consistent;
@a^_=@b; O man, can it get worse
@a^ _=@b;Why, yes it can.  Looks like the makings of a
neat regex, just throw an s or m in front.

 d) To me the underscore represents something special.  Like the
variables $_, or @_, __DATA__ not string concatenation.


possible solution :

I listed out characters to me that mean concatenate or merge.
 Here is the list:
  a)   AND. Great, However it denotes a subroutine in perl.
  b) +  ADD or PLUS. Read somewhere in the camel book that
concatenation strings is not adding. and would confuse the math.
  c) -  Hyphen.  When pronounced hyphen it sounds great.  When
pronounced minus ... well that won't work.

 Then I thought of it.  In school whenever I separated a single word
into two words my paper would come back with a small red arch joining
the two words together into one.  Of course that symbol was usually
followed by a -5 or something like that.  So I scanned the keyboard for
something that looked like that small arch. Then I found it.  The ^
symbol.  Since I have a problem with the hyper operator idea, Maybe it
could be used here.  But what about xor.  I can honestly say I have
never used ^ to mean xor.  The Huffman coded concept should make the
use of xor rather than ^ a viable alternative.  I read through
Apocolypse3 and saw this justification:

 However, Perl has a built-in xor operator, so this isn't really
much of an issue. And there's a lot to be said for forcing parentheses
in that last expression anyway, just for clarity. So unless anyone comes
up with a large objection that I'm not seeing, this RFC is accepted

 I like the idea of forcing me to use parentheses around xor more than
forcing me to put a space before an operator.




2)  RFC 082: Arrays: Apply operators element-wise in a list context
(hyper operators)
and
3)  Special variable representing index of array in foreach structure
$# maybe (not in apocolypse3, I think)

There are many times that hyper-operators would come in handy.  And I
have prayed for the special index variable in foreach loops.  At first
they both sounded like welcome additions to Perl.  Then I started to
think about them.  I am an engineer at heart.  Granted I say I am a
programmer, but I am an engineer.  When I saw hyper operators I was
excited.  I thought to my self if you are going to allow that type of
operation what about all the other goodies that come along with Vector
and Matrix arithmetic.  Dreams of multiplying a Jacobian
multidimensional array to an input vector array were dancing in my
head.  I wonder what operator that would be.

Then I regained my composure and asked why do I really want these
things.  I can do what I need in Perl5. This is why:

 my @x=(1,2,3,4,5);
 my @y=(2,3,4,5,6);
 my @z=(4,5,6,7,8);

 my @result;
 my $index = 0;

 for my $x (@x){
  push(@result,$x+$y[$index]+$z[$index]);
  $index++;
 }

All of that just to add these three arrays together.  You can see that
the auto index variable $# would make life 

Re: Hyper-operators and Underscore

2001-10-06 Thread Jeremy Howard

Erik Lechak wrote:
 2)  RFC 082: Arrays: Apply operators element-wise in a list context
 (hyper operators)
 and
 3)  Special variable representing index of array in foreach structure
 $# maybe (not in apocolypse3, I think)

Hi Eric. Thanks for your comments. Unfortunately it's a little early for
detailed consideration of vector and matrix operations, which will be
covered in more detail in a later Apocolypse. However, here's a couple of
pointers from the RFCs that may appear in some form in Larry's later
musings.

First, check out:
  http://dev.perl.org/rfc/207.html

This provides looping indices for multidimensional arrays. Please read RFCs
202-206 first though, since RFC 207 draws heavily on them.

Next, note that hyper-operators are a bit smarter than the behaviour you
indicate. Most notably, they 'broadcast' lower dimensionality structures to
the highest dimensionality structure. We're only up to 1-dim structures in
the Apocolypses so far, so for now that just means that
  @a = @b ^+ 1;
works as it should. This is a more interesting issue when, for instance,
broadcasting a vector across a matrix, but now I'm getting ahead of
myself...

Finally, note that there is an RFC which can simplify iteration through
lists n-at-a-time:
  http://dev.perl.org/rfc/90.html

So you can then pull the first element from each list with:
  my ($a,$b,$c) = merge(@a,@b,@c)





Re: Hyper-operators and Underscore

2001-10-06 Thread Erik Lechak


Thanks for the info,


Bryan,

Thank you for the info.  I am more engineer than computer scientist, so
please excuse the ignorance behind these questions.



 Except that the operator truly is simply an underscore.  But it's also a
 valid identifier character, so where it may be confused with that, you are
 simply required to make it less ambiguous to the parser.

 $a _= $b _ $c;  # $a _= $b _$c;
 ${a}_=${b}_$c;
 %h{$s}_=Hello, _world!\n;

 As Larry said, no different that the other operators that also consist of
 valid character identifiers.

I understand that the operator is just the underscore.  However, in the third
edition of the camel book on page 49, the second paragraph, it states that An
identifier is a token that starts with a letter or underscore and contains only
letters, digits, and underscores.   Since there are no singel letter operators,
no single digit operators, but now we see the advent of the underscore operator,
it follows that the underscore will be the only operator that could be confused
as part of the variable name.

1) My question is what other operator could be confused with an identifier?

2) Where did Larry say no different that the other operators that also consist
of valid character identifiers. ?




 IIRC, '^' was considered earlier.  (And it's shifted, BTW.)


3) What do you mean by shifted?


Thank you ,
Erik Lechak



Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinumrefcd=PT97



Re: Hyper-operators and Underscore

2001-10-06 Thread Bryan C . Warnock

On Saturday 06 October 2001 03:47 pm, Erik Lechak wrote:
 Thank you for the info.  I am more engineer than computer scientist,
 so please excuse the ignorance behind these questions.

No problem.  


  Except that the operator truly is simply an underscore.  But it's also a
  valid identifier character, so where it may be confused with that, you
  are simply required to make it less ambiguous to the parser.
 
  $a _= $b _ $c;  # $a _= $b _$c;
  ${a}_=${b}_$c;
  %h{$s}_=Hello, _world!\n;
 
  As Larry said, no different that the other operators that also consist
  of valid character identifiers.

 I understand that the operator is just the underscore.  However, in the
 third edition of the camel book on page 49, the second paragraph, it
 states that An identifier is a token that starts with a letter or
 underscore and contains only letters, digits, and underscores.   Since
 there are no singel letter operators, no single digit operators, but now
 we see the advent of the underscore operator, it follows that the
 underscore will be the only operator that could be confused as part of the
 variable name.

'x' is a single letter operator.


 1) My question is what other operator could be confused with an
 identifier?

Not including the list operators or control flow keywords:
eq, ne, gt, lt, ge, le, cmp, x, and, or, not, xor

$a = $bx4; # $a = $bx4;  $a = $b x 4;
if ($one foo || $o nefoo) # if ($one foo); if ($o ne foo) ; if (${o}nefoo)
etc...


 2) Where did Larry say no different that the other operators that also
 consist of valid character identifiers. ?

Hmm.  It looks like he didn't.  That must have been a point someone had made 
in a subsequent posting.  I apologize.


  IIRC, '^' was considered earlier.  (And it's shifted, BTW.)

 3) What do you mean by shifted?

A caret on a standard US qwerty keyboard is shift-6'.  (In reponse to your 
complaint (a), about the underscore requiring the shift key.)

-- 
Bryan C. Warnock
[EMAIL PROTECTED]



Re: Hyper-operators and Underscore

2001-10-06 Thread Erik Lechak




Bryan,

I guess my biggest complaint was that underscore would be the only single
character operator that would be in danger of  being lumped into the variable
name.  I forgot about  x .  I use it all the time.  If  x  has that constraint
why not the underscore.  I worked at a place where
variables_with_names_like_this_were_common. You can see why I have reservations
about the overuse of underscores.

And about that shifted question.  I guess I am drinking ways too much Mountain
Dew.  I was thinking shift as in pop as opposed to shift as in keyboard.  Sorry.

Erik Lechak


Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinumrefcd=PT97



Re: General Feelings on Apoc 3

2001-10-06 Thread Rafael Garcia-Suarez

David M. Lloyd wrote:
 On Thu, 4 Oct 2001, Michael G Schwern wrote:
 
   Backtracking is at the heart of Logic Programming (or Declarative
   Programming, if you like). This is one of the 3 main programming paradigms
   (along with procedural and functional). The most popular Declarative
   language is Prolog. It is great for writing programs that are largely about
   resource allocation and constraints. There's some links to start you off
   here:
  
   http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?backtracking
 
  Sounds like a chess computer.
 
 It kind of struck me that this type of concept might be handy for writing
 parsers directly in Perl without an 'intermediate' parsing language.  Or
 for making it easier to write such an intermediate language.

Backtracking is typically not used in parser implementations because
it's slow over other predictive techniques. It's needed in a few cases
of highly ambiguous languages (e.g. LL-infinite parsers).

Another idea : it should be possible to write makefile-like rules with
backtracking.



TIMTOWT concat / hypo-operators

2001-10-06 Thread Edwin Steiner


Hello!

Is this going to concat $a,$b and $c?

$foo = _($a,$b,$c);

(One way to save underlines and spaces.)
Or would that be:

$foo = _@($a,$b,$c);

BTW: what will these do?

$a _=_ ($b,$c);

$a ^_= ($b,$c);  # (better with hypo-operator?, see below)

(WIM in Perl 5: $a .= $b.$c ?)

Could there also be *hypo*-operators, i.e. operators which try to
*lower* (reduce) the dimensionality of their operands to the lowest
common dim. So

$foo = 5 +^ (1,2);

would set $foo to (5 + 1) + 2 and

$foo = $a _^ ($b,$c);
$a _=^ ($b,$c);

would do the same concats as above respectively?
Another application:

$sum = 0 +^ @values;

Granted: ^ is not the best choice for a meta-operator which lowers
something. :)

-Edwin




RE: TIMTOWT concat / hypo-operators

2001-10-06 Thread Brent Dax

Edwin Steiner:
# Is this going to concat $a,$b and $c?
#
#   $foo = _($a,$b,$c);
#
# (One way to save underlines and spaces.)
# Or would that be:
#
#   $foo = _@($a,$b,$c);

That would be C$foo=join('', $a, $b, $c), just like in Perl 5.

# BTW: what will these do?
#
#   $a _=_ ($b,$c);

That's concatenating a stringified list ($b, $c) to $a.  (Unary _ is the
stringification operator.)

#   $a ^_= ($b,$c);  # (better with hypo-operator?, see below)
#
# (WIM in Perl 5: $a .= $b.$c ?)

No, that'll be the same as C$a _= $c, since $a creates a scalar
context.

# Could there also be *hypo*-operators, i.e. operators which try to
# *lower* (reduce) the dimensionality of their operands to the lowest
# common dim. So
#
#   $foo = 5 +^ (1,2);
#
# would set $foo to (5 + 1) + 2 and
#
#   $foo = $a _^ ($b,$c);
#   $a _=^ ($b,$c);
#
# would do the same concats as above respectively?
# Another application:
#
#   $sum = 0 +^ @values;
#
# Granted: ^ is not the best choice for a meta-operator which lowers
# something. :)

I don't really see the use of hypo-operators.

Note that everything I said here is subject to overriding by someone who
knows more than me.  :^)

--Brent Dax
[EMAIL PROTECTED]
Configure pumpking for Perl 6

They *will* pay for what they've done.




Quick EX3 question

2001-10-06 Thread John Siracusa

Are these the same thing?

print _@{$data.{costs}};
print _ $data{costs};

-John




Re: Customizable default hash and array values.

2001-10-06 Thread Bart Lateur

On Fri, 28 Sep 2001 21:27:48 +0200, Johan Vromans wrote:

Michael G Schwern [EMAIL PROTECTED] writes:

 so if $key does not exist you'll get 'some default' instead of undef.

Except that a more common case is

  my $foo = $hash{foo} || 'some default';
  my $bar = $hash{bar} || 'some other default';

What about zero.

Oh, wait, we're back at that ?? discussion again.

-- 
Bart.



EX3: $a == $b != NaN

2001-10-06 Thread John Siracusa

Okay, so this:

100  -s $filepath = 1e6

really means this:

100  -s $filepath-s $filepath = 1e6

which means that this:

$a == $b != NaN

really means this:

$a == $b  $b != NaN

But $a == $b != NaN is supposed to [solve] the problem of numerical
comparisons between non-numeric strings.  Well, what if:

$a = 'hello';
$b = 0;

Doesn't that mean:

hello == 0  0 != NaN

will evaluate to true?  Is that expected behavior for comparing
hello and 0 with the EQ operator?  Or am I not getting the
purpose of the $a == $b != NaN idiom?

-John




EX3: Adverbs and print()

2001-10-06 Thread John Siracusa

From EX3:
 A subroutine's adverbs are specified as part of its normal parameter list, but
 separated from its regular parameters by a colon:

 my sub operator:… is prec(\operator:+($)) ( *@list : $filter //= undef)
 { ...

 This specifies that operator:… can take a single scalar adverb, which is bound
 to the parameter $filter. When there is no adverb specified in the call,
 $filter is default-assigned the value undef.

So, in the … operator, the filter is the adverb:

$sum = … @costs : {$^_  1000};

Does that mean that in the built-in print, the file handle is the only
in-band argument, and all the actual items to be printed are merely
adverbs?

print $data.{fh} : $data.{qw(name vers stat)}, _@{$data.{costs}}, $rest;

Or am I confusing uses of the colon?

-John




Re: EX3: $a == $b != NaN

2001-10-06 Thread John Siracusa

On 10/6/01 10:27 PM, Damian Conway wrote:
 Doesn't that mean:
 
 hello == 0  0 != NaN
 
 will evaluate to true?
  
 No. The step you're missing is that the non-numeric string hello,
 when evaluated in a numeric context, produces NaN. So:
 
hello == 0  0 != NaN
 
 is:
 
Nan == 0  0 != NaN
 
 which is false.

Heh, my brain's Perl interpreter needs to be upgraded, obviously.
It sees hello == 0 and produces 0 == 0.

Thanks for the clarification :)

-John




Re: Are .key and .value right for Pairs?

2001-10-06 Thread Randal L. Schwartz

 Damian == Damian Conway [EMAIL PROTECTED] writes:

Too much typing:

Damian module PAIR;

Damian method car { return .key }
Damian method cdr { return .value }

Damian method AUTOVIVIFY (default, $name) {
Damian if ($name =~ m/^c([ad])([ad]*)r$/) {

Replace:

Damian my $next = c$2r;
Damian given ($1) {
Damian when 'a': { return sub { .car.$next() } }
Damian when 'd': { return sub { .cdr.$next() } }
Damian }

with:

my $this = c$1r;
my $next = c$2r;
return sub { { .$this().$next() } };

Damian }
Damian }


Right?  Plus or minus a set of parens or something, eh?

-- 
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!