"<->" as "->" with automatic "is rw"

I like that arguments will be readonly by default. But when I look at my
current code, I see that I would be typing " is rw" quite a lot, which in
my opinion is too long for a thing that occurs very often.
Every such situation in my code is a foreach loop. A thing that in Perl
6 will mostly be used with the pointy sub declaration syntax.
If I'm not mistaken, <-> is still available. It communicates
"bidirectional" and that is more or less the same as read/write access.
I'm proposing
    for zip(@foos, @bars, @xyzzies) <-> $foo, $bar, $xyzzy { ... }
    for %quux.kv <-> $key, $value { ... }
to mean
    for zip(@foos, @bars, @xyzzies) -> $foo is rw, $bar is rw, $xyzzy is rw { ... }
    for %quux.kv -> $key is rw, $value is rw { ... }
Comments, anyone?

Juerd
0
juerd
8/20/2004 8:07:02 PM
📁 perl.perl6.language
📃 6843 articles.
⭐ 0 followers.

💬 7 Replies
👁️‍🗨️ 1304 Views


On Fri, Aug 20, 2004 at 10:07:02PM +0200, Juerd wrote:
: I'm proposing
: 
:     for zip(@foos, @bars, @xyzzies) <-> $foo, $bar, $xyzzy { ... }
:     for %quux.kv <-> $key, $value { ... }
That'd probably work on the keys only if the hash was declared to have
object keys.  At least in Perl 5, the key is always a copy.
: to mean
: 
:     for zip(@foos, @bars, @xyzzies) -> $foo is rw, $bar is rw, $xyzzy is rw { ... }
:     for %quux.kv -> $key is rw, $value is rw { ... }
: 
: Comments, anyone?
It's really sick, and cute, and I love it.  Unfortunately I'm not sure
it passes the "Are there already too many ways to declare a sub?" test...
It's vaguely possible I could be persuaded on the basis that
    for zip @a � @b <-> { ($^a,$^b) = ($^b,$^a) }
could be made to work.  But I'm still dubious.  And arguably -> {...}
means the same as sub () {...}, implying there are no arguments.
Larry
0
larry
8/20/2004 8:31:12 PM
On Fri, 20 Aug 2004 13:31:12 -0700, Larry Wall <larry@wall.org> wrote:
> It's vaguely possible I could be persuaded on the basis that
>=20
>     for zip @a =A5 @b <-> { ($^a,$^b) =3D ($^b,$^a) }
Shouldn't that be:
    for zip @a, @b <-> { ... }
              --or--
    for @a =A5 @b <-> { ... }
?
--
matt
0
mddiep
8/20/2004 8:46:33 PM
On Fri, Aug 20, 2004 at 04:46:33PM -0400, Matt Diephouse wrote:
: On Fri, 20 Aug 2004 13:31:12 -0700, Larry Wall <larry@wall.org> wrote:
: > It's vaguely possible I could be persuaded on the basis that
: > 
: >     for zip @a � @b <-> { ($^a,$^b) = ($^b,$^a) }
: 
: Shouldn't that be:
: 
:     for zip @a, @b <-> { ... }
:               --or--
:     for @a � @b <-> { ... }
: 
: ?
Yes, a typo.  Though it's not actually clear yet whether you have to
write zips args with semicolons, which is why I partially switched
to � in midthink.
Larry
0
larry
8/20/2004 8:49:46 PM
On Fri, 20 Aug 2004 13:49:46 -0700, Larry Wall <larry@wall.org> wrote:
> Yes, a typo.  Though it's not actually clear yet whether you have to
> write zips args with semicolons, which is why I partially switched
> to =A5 in midthink.
Just checking. I wondered if you'd introduced a new feature midthink
(and I'd missed it).
--
matt
0
mddiep
8/20/2004 8:56:41 PM
On Fri, 20 Aug 2004, Larry Wall wrote:
> On Fri, Aug 20, 2004 at 10:07:02PM +0200, Juerd wrote:
> : I'm proposing
> :
> :     for zip(@foos, @bars, @xyzzies) <-> $foo, $bar, $xyzzy { ... }
> :     for %quux.kv <-> $key, $value { ... }
>
> That'd probably work on the keys only if the hash was declared to have
> object keys.  At least in Perl 5, the key is always a copy.
>
> : to mean
> :
> :     for zip(@foos, @bars, @xyzzies) -> $foo is rw, $bar is rw, $xyzzy i=
s rw { ... }
> :     for %quux.kv -> $key is rw, $value is rw { ... }
> :
> : Comments, anyone?
>
> It's really sick, and cute, and I love it.  Unfortunately I'm not sure
> it passes the "Are there already too many ways to declare a sub?" test...
>
> It's vaguely possible I could be persuaded on the basis that
>
>     for zip @a =A5 @b <-> { ($^a,$^b) =3D ($^b,$^a) }
>
> could be made to work.  But I'm still dubious.  And arguably -> {...}
> means the same as sub () {...}, implying there are no arguments.

Arguably it already means that.  But if <-> were added, it might be a good
reason to make -> {...} mean -> $_ {...}, using <-> {...} for -> $_ is rw
{...}.  A good way to remove one more special case (maybe offsetting the ex=
tra
way to declare a sub, and sweeten the whole deal).
--=20
Adam Lopresto
http://cec.wustl.edu/~adam/
Yesterday upon the stair
I met a man who wasn't there.
He wasn't there again today --
I think he's from the CIA.
0
adam
8/20/2004 9:17:11 PM
Larry Wall skribis 2004-08-20 13:31 (-0700):
> Unfortunately I'm not sure it passes the "Are there already too many
> ways to declare a sub?" test...
I'm not seeing it as another way. Technically, of course it is
different, but by the user, <-> and -> will probably be seen as one
thing, with one of them being the other's specialized form.
> It's really sick
Sick would be if <- were introduced to make the variable write-only ;)
         W   R
    @foos  -> $foo
    @foos <-> $foo
    @foos <-  $foo
It would be consistent, though...

Juerd
0
juerd
8/21/2004 10:08:01 AM
Juerd <juerd@convolution.nl> writes:
> Sick would be if <- were introduced to make the variable write-only ;)
Sicker still would be if - were introduced to make the variable
neither readable nor writeable.  HTH.HAND.
-- 
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,"ten.thgirb\@badanoj$/ --";$\=$ ;-> ();print$/
0
jonadab
8/22/2004 3:55:36 AM
Reply: