On Mon, Apr 23, 2001 at 12:36:47PM -0400, Dan Sugalski wrote:
> At 02:52 PM 4/23/2001 +0200, Davíð Helgason wrote:
> >"H.Merijn Brand" wrote:
> > >
> > > > > $a = $b ~ $c; # Mmm!
> > > > >
> > > > > I like that last one a lot, because it doesn't disturb anything.
> > > > > You'd have to alter ~'s precedence so that binary ~ is higher
> > > > > than named unary operators. (It's print($a~$b), not print $a (~b).)
> > > >
> > > > I am not sure I do like the use of ~ here. It does not screan concatenate
> > > > to me (but then again neither did . when I started perl)
> > > >
> > > > I am thinking that maybe it should be a 2 character operator with at
> > > > least one of then being + as + is common in many other languages
> > > > for doing concatenation.
> >
> >Which of qw[~ ++ +~ + &] do we dislike the least?  Using + would be
> >nice, but introduce no end of problems with number/sting behaviour. '&'
> >is too much like a certain unpopular language. And there was no end to
> >the quabbling :(
> 
> What's wrong with something like:
> 
>    $foo = $a :+ $b;

I was thinking along those lines too.

In fact it made me think of something Larry said (I think) about operators
operating on whole arrays. So :+ might be the addition of all elements, eg

  @foo = @a :+ @b;

So if a leading : would mean the operator was an array operator, maybe we
could use something else for string operators (say ~). This would also help
disambiguate the difference of & when its operands are numbers or strings
as & would always be for numbers and ~& would be for strings. eg

  $foo = $a + $b;  # addition
  $foo = $a ~+ $b; # concat
  $foo = $a & $b;  # logical and of IVs
  $foo = $a ~& $b; # bitwise and of PVs
  @foo = @a :+ @b; # same as @foo = map { $a[$_] + $b[$_] } for 0..max($#a,$#b);
  @foo = $a :+ @b; # same as @foo = map { $a + $b[$_] } for 0..$#b;

  etc...

Graham.

Reply via email to