Re: study

2005-03-21 Thread Nicholas Clark
On Sun, Mar 20, 2005 at 10:54:15PM -0700, Luke Palmer wrote:

 in the same form if it does come back.  So consider 6.0 its usage
 deprecation cycle, so we can redefine its meaning (if we decide to).

I don't see why study needs a deprecation cycle when length doesn't get one.
It seems fair game to me that (some) things can change disjointly in Perl 6

(providing that not too many things change such that the language is no
longer perl. Which I don't think is happening, and if you do think it's
happening, there's still always going to be perl 5 for you to use)

Also it sounds like study fits much better as a method on a scalar, rather
than a function in *::

Nicholas Clark


Re: study

2005-03-21 Thread Luke Palmer
Nicholas Clark writes:
 On Sun, Mar 20, 2005 at 10:54:15PM -0700, Luke Palmer wrote:
 
  in the same form if it does come back.  So consider 6.0 its usage
  deprecation cycle, so we can redefine its meaning (if we decide to).
 
 I don't see why study needs a deprecation cycle when length doesn't get one.
 It seems fair game to me that (some) things can change disjointly in Perl 6

Sorry.  I misspoke (My brain forgot what a deprecation cycle does).
`study` should not be in 6.0.

Luke


Re: .method == $self.method or $_.method?

2005-03-21 Thread Peter Haworth
On Fri, 18 Mar 2005 09:45:57 -0800, Larry Wall wrote:
 I think we'll need to figure out how to shorten $_.foo instead.

It looks short enough to me already. More importantly, its meaning
is immediately obvious.

 Either that, or there has to be a way to explicitly make $_ the
 invocant of a subblock.

How about something like this?

  method foo{
.bar; # Acts on self
for @stuff {
  .bar; # Acts on self
}
for @stuff - $_ :self {
  .bar; # Acts on self, which is currently $_
}
  }

Seems like overkill for trivial blocks though:

  map - $_ :self { .bar } 1..10;

but you can still just write $_.bar

Maybe we could allow $_ to be elided?

  map - :self { .bar } 1..10;


 At the moment I'm trying to see if I could get used to ..method
 meaning $_.method, and whether it buys me anything psychologically.

I still prefer $_.method


 Suppose you are one of those rare people who actually checks the
 return value of print to see if you filled up the disk:

 if print {...}

 That doesn't parse currently ... (Backtracking the parser is
 probably not the right answer.)

If you're going to the trouble to check that (which I do,
sometimes), surely two extra characters [$_ or ()] aren't that
much of a problem? You probably wouldn't be using implicit
variables, anyway.

A backtracking parser seems pretty scary to me. If it takes a lot of
work for the compiler to figure things out, it's going to be even
harder for the programmer.

-- 
Peter Haworth   [EMAIL PROTECTED]
I think this is one of those traumatic things eggs have to face
 to prepare a good omelette.
-- Jarkko Hietaniemi


Re: New S29 draft up

2005-03-21 Thread Juerd
John Macdonald skribis 2005-03-18 12:00 (-0500):
 I've had times when I wanted to be able to use chop at either
 end of a string.

In fact, won't things be much easier if shift and pop workend on strings
as well as on arrays? Now that we have multis, this should be easy to
do.

(For symmetry, this'd also require push to be a synonym for ~= and
unshift to be a synonym for s/^/.../. Two things I would certainly like
having. (The symmetry is slightly broken, though, because if you push
foo once, you have to pop three times to get it back. I don't think
this is a problem.))

This kind of dwimmery already exists for reverse and would work well
with split (regex or string) too. If slice is added to splice, substr
can just be an alias for slice (or disappear), and slice can call splice
if there's a 4th argument. 


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: eval (was Re: New S29 draft up)

2005-03-21 Thread Juerd
Paul Seamons skribis 2005-03-18  9:46 (-0700):
  eval slurp foo;

That requires foo to have an #line directive (or whatever its Perl 6
equivalent will be) in order to be useful when debugging.

See also http://tnx.nl/include (I want Perl 6 to have this function that
evals a file such that in it, lexical variables are visible).


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: New S29 draft up

2005-03-21 Thread Larry Wall
On Sun, Mar 20, 2005 at 08:54:54PM -0600, Rod Adams wrote: Okay,
I've come around to liking it, but I think we have to say that 0x,
0d, 0o, 0b, and whatever else we come up with are just setting the
default radix.  If a string comes in with an explicit 0x, 0d, 0o,
or 0b, we believe that in preference to the operator.  The operator
just says what to assume in the absence of an explicit marker.  Then
we just tell people that ordinary str-to-num conversion happens to
be identical to the 0d operator.

Larry


Re: New S29 draft up

2005-03-21 Thread John Macdonald
On Mon, Mar 21, 2005 at 03:31:53PM +0100, Juerd wrote:
 [...] (The symmetry is slightly broken, though, because if you push
 foo once, you have to pop three times to get it back. I don't think
 this is a problem.))

That's not a new break to the symmetry of push and pop:

@b = (1,2,3);
push( @a, @b ); # needs 3 pops to get all of 1,2,3 back

and in both the original array form and in the treat a string
as an array form, you can retrieve a multi-element thing that
was push'ed in a single operation by using a single invokation
of splice.

-- 


Re: Perl6 and Duff's Device

2005-03-21 Thread Larry Wall
On Sun, Mar 20, 2005 at 05:27:56PM -0700, Luke Palmer wrote:
: I believe Perl 6 hasn't changed its policy on labels, so you should be
: able to write that in Perl 6.  But your behavior might be undefined.
: It's weird to jump into the middle of a loop.  We may only allow you to
: jump outwards from your dynamic scope.  

Perl 5's policy is to prohibit goto into anything that has to
execute code to set up execution of the block, so you can't jump
into a foreach loop, but you can jump into more basic sorts of loops.
Perl 5 preallocates pad entries for loops within the outer sub's pad,
so if you bypass a my you just get an undefined value but not a
core dump.  With the possibility of user-defined control structures,
we may have to limit goto to blocks that we know we can inline,
unless we define a goto interface for them.  (On the other hand,
we've been talking about multiple entry points for routines based on
whether you've already done the argument type checking, and that's
sort of the same idea.  So it might just fall out naturally from that.
I'm not holding my breath on it, though.)

Larry


Re: chr and ord

2005-03-21 Thread Larry Wall
On Sun, Mar 20, 2005 at 10:33:04PM -0600, Rod Adams wrote:
: I'm thinking Cchr and Cord should be strictly Code Point level 
: activities, but I'm not sure.

Alternately, since Num implies arbitrary precision, we *could* define
a value that can hold as many code points as you like, mod 2**32 or some
such.  But I'm not sure either.

: They likely need to be renamed, in any event, to better reflect the fact 
: that everything is Unicode these days.

And to reflect the fact that Unicode is many things these days.

Larry


Re: nothing

2005-03-21 Thread Larry Wall
On Sun, Mar 20, 2005 at 09:08:08PM -0600, Rod Adams wrote:
: Does Perl need a no-op function?
: 
: With the addition of no bare literals, it makes constructs like
: 
: 1 while some_func();
: 
: an error.

Well, it's not a bareword--it's just potentially a useless use of
the value in a void context, and we could suppress that warning for
0 and 1 like we do Perl 5 without violating our no barewords dictum.

: I propose creating a no-op function nothing that can be used 
: here or anywhere else you specifically wish to do nothing at all.
: 
:  given $this {
:when Even  { nothing };
:when Prime { ... };
:default{ ... };
:  }

We use null in rules, and Ada used null as a keyword, so I'd probably
prefer that if there are no serious objections and if nobody has a better
idea.

: As a side question, I assume that there's a predicate form of when, 
: but it's not mentioned.
: 
:  given $this {
:nothing when Even;
: 
:when Prime { ... };
: 
:default{ ... };
:  }

It's mentioned somewhere, I forget where, but its semantics are
currently defined such that it would not bypass the other cases.
It's possible that's a Surprise, but we were invisioning it as a
mechanism for adding extra tests against the topic when you don't
want to break out.  And we wanted to encourage people to use the
comb structure when they really are dealing with exclusive options.

Larry


Re: nothing

2005-03-21 Thread Rod Adams
Larry Wall wrote:
On Sun, Mar 20, 2005 at 09:08:08PM -0600, Rod Adams wrote:
: I propose creating a no-op function nothing that can be used 
: here or anywhere else you specifically wish to do nothing at all.
: 
:  given $this {
:when Even  { nothing };
:when Prime { ... };
:default{ ... };
:  }

We use null in rules, and Ada used null as a keyword, so I'd probably
prefer that if there are no serious objections and if nobody has a better
idea.
 

It's potentially confusing for the database crowd, where the word null 
is pretty much a synonym for a Perl undef. Being part of that crowd, 
null is invariably locked into my head as a value. It works in the 
Rule sense of null, since you're looking for the value which is nothing.

I also think a huffman level of 7 makes more sense than 4, so I still 
prefer nothing.

That being said, I'm sure people could learn the difference if they 
needed to.

: As a side question, I assume that there's a predicate form of when, 
: but it's not mentioned.
: 
:  given $this {
:nothing when Even;
: 
:when Prime { ... };
: 
:default{ ... };
:  }

It's mentioned somewhere, I forget where, but its semantics are
currently defined such that it would not bypass the other cases.
It's possible that's a Surprise, but we were invisioning it as a
mechanism for adding extra tests against the topic when you don't
want to break out.
possible surprise? Every other conditional holds its semantics whether 
in predicate or subjective form, so why should it be surprising when 
when changes it's semantics?

If you want to test against the topic without breaking out, you still 
have if and $_ at your disposal, which should always be clear what 
you're doing.


 And we wanted to encourage people to use the
comb structure when they really are dealing with exclusive options.
 

What's wrong with
 given somefunc() {
   die errorwhen 0;
   print_status   when 1;
   prompt_options when 2;
   die impossible;
 }
as an alternative to the comb in the cases where all the commands are 
short? That seems cleaner to me than:

 given somefunc() {
   when 0  { die error  };
   when 1  { print_status };
   when 2  { prompt_options   };
   default { die impossible };
 }
No, the former doesn't look a lot like the classical switch statement, 
but this is the land of TMTOWTDI.

-- Rod Adams




Re: nothing

2005-03-21 Thread Juerd
Rod Adams skribis 2005-03-21 14:25 (-0600):
   if $expr {
 nothing;
   }
 is harder to get confused over, IMO

Except writing something when you mean nothing is kind of weird. It
makes sense in rules because it doesn't usually make sense to match
nothingness, but for blocks, I'd hate to see { } be invalid or meaning
anything other than the proposed nothing.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: nothing

2005-03-21 Thread Austin Hastings
Juerd wrote:
Rod Adams skribis 2005-03-21 14:25 (-0600):
 

 if $expr {
   nothing;
 }
is harder to get confused over, IMO
   

Except writing something when you mean nothing is kind of weird. It
makes sense in rules because it doesn't usually make sense to match
nothingness, but for blocks, I'd hate to see { } be invalid or meaning
anything other than the proposed nothing.
Juerd
 

I'd like to see nothing as just an alias for {}.
 if $expr
 {
   do nothing;
 }
Possibly the most clear piece of P6 code ever.
=Austin


Re: nothing

2005-03-21 Thread Juerd
Austin Hastings skribis 2005-03-21 15:55 (-0500):
 I'd like to see nothing as just an alias for {}.
  if $expr
  {
do nothing;
  }
 Possibly the most clear piece of P6 code ever.

Dangerous, though :)

do nothing if $input =~ /\W/;
system rm -- $input; 

But yes, an alias would be nice. There have been some cases where I
wanted to explicitly state } else { do nothing } to make clear that it
was not a design bug.

However, the very same thing can be done with a simple comment:

} else {
# do nothing
}

And that is exactly what I do.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: nothing

2005-03-21 Thread Rod Adams
Juerd wrote:
Austin Hastings skribis 2005-03-21 15:55 (-0500):
 

I'd like to see nothing as just an alias for {}.
if $expr
{
  do nothing;
}
Possibly the most clear piece of P6 code ever.
   

Dangerous, though :)
   do nothing if $input =~ /\W/;
   system rm -- $input; 

But yes, an alias would be nice. There have been some cases where I
wanted to explicitly state } else { do nothing } to make clear that it
was not a design bug.
However, the very same thing can be done with a simple comment:
   } else {
   # do nothing
   }
And that is exactly what I do.
 

But you can't solve
 nothing while something();
with a comment. Well, not gracefully. Not without inline comments, at least.
There seems to be some support for just saying:
 {} while something();
I would also hope the compiler could optimize away something like:
 sub nothing () {};
-- Rod Adams