Re: Chained Comparisons ?

2008-04-16 Thread Joe Gottman

Brandon S. Allbery KF8NH wrote:


On Apr 16, 2008, at 3:49 , John M. Dlugosz wrote:
Or, are the operators written in a tricky way, to return an object 
that encapsulates the original right argument and the proper boolean 
result, and has forms to take this object as well?  IOW, no built-in 
support.


Yes, they use multiple-typed values such that (3  5) returns (5 but 
True), which used in a numeric context is a 5 that can be chained with 
further infix:{''}s but in a boolean context is True.



So does (5  3) return (3 but False)  or just False ?

Joe Gottman


Definition of Order in S29

2008-01-23 Thread Joe Gottman
  In the definition of cmp, S29 says the function returns 
|Order::Increase|, |Order::Decrease|, or |Order::Same| (which numify to 
-1, 0, +1).  Shouldn't the enumerations and their numerical values be 
listed in the same order?


Joe Gottman


Re: Sequential bias in S04 (and Perl6 in general)

2008-01-03 Thread Joe Gottman

Dave Whipp wrote:
I was reading Synopsis 4 with regards to multi core programming. It 
seems to be infused with a bias towards non-parallel models of 
computation. Concurrently appears to be an add-on feature -- whereas 
we should have a mindset that explicit sequential constraints are the 
add-on feature.


Two statements that are missing from S04 (feel free to change the 
names) are Cforall; and a form of Cgiven that tests/executes 
multiple Cwhen clauses in arbitrary order (without needing the 
sequential Ccontinue statement).



  forall @a - $x { ... }

runs the code block on each element of @a (no defined order). If @a is 
a lazy generator then generation of values is concurrent with running 
the code block on those generated values).


  forall @a - $x : sequential { ... }

forces an additional sequential constraint on the execution, such that 
the Nth element of @a is not obtained until the code block has 
executed for the (N-1)th. Cfor is an alias for this constrained 
variant. Cfor implies this sequential constraint to avoid surprising 
legacy (perl5) programmers.


Similarly, Cmap, Cclassify, Cgrep, Creduce, ... should all 
accept this :sequential adverb to force them to iterate their lists 
sequentially -- and should otherwise iterate in arbitrary/concurrent 
order.



  given $x :all { ... }

would run the code blocks of all Cwhen statements (in the Cgiven 
block) which smart-match true against $x. The :sequential adverb 
would be used to constrain execution of the Cwhen blocks to run in 
the order they appear in the source code. (it would be good if the 
current Cgiven could be thought of as using a :first modifier, 
which runs the code block of the lexically first Cwhen clause that 
evaluates to true -- but which potentially tests multiple Cwhen 
clauses in parallel. Unfortunately the current language definition is 
much too sequential for this viewpoint)




I think a major reason for the bias toward sequential processing is 
that if code that should be processed sequentially is instead processed 
concurrently then the results will almost always be incorrect. 
Conversely, if code that should be processed concurrently is instead 
processed sequentially, the results will be correct though the program 
will take longer to run than necessary.  I don't think it's unreasonable 
to prefer always correct but slow to sometimes incorrect and fast, 
especially if it is difficult to automatically tell which cases might 
result in incorrect behavior.


  On the other hand, this being Perl, I do believe it should be easy to 
specify the concurrent case.  I think that a forall keyword (and a 
givenall keyword corresponding to given) would be a good idea.  
These would not be quite parallel to for and given because there 
would be some subtle differences arising from the concurrent 
processing.  For instance, forall probably should not be used with 
last, because last should stop subsequent iterations and the 
subsequent iterations could already have occurred when it is called.  
Similarly, givenall should not be used with continue, because the 
next case might already have been checked when continue is called. 


Joe Gottman



Re: Micro-articles on Perl 6 Operators

2007-09-18 Thread Joe Gottman

Adriano Ferreira wrote:

I salute every bit of help. I am trying to organize the production and
will hopefully provide more details soon. By now, I think that I can
handle suggestions and corrections to the articles. The next one is
here:

http://ferreira.nfshost.com/perl6/stitching6.html

  
  This one's very nice.  One question: what's the ~+ operator you 
talk about in your discussion of prefix ~ ?  I can't find any mention of 
it in Synopsis 3.


Joe Gottman



Re: Micro-articles on Perl 6 Operators

2007-09-17 Thread Joe Gottman

Adriano Ferreira wrote:

Jesse Vincent has announced the acceptance of my microgrant proposal
(http://use.perl.org/~jesse/journal/34451).  It is a plain simple
idea, whose effects are yet to be seen. Comments and feedback most
welcome.

  

snip

Join me. The drafts of the introduction and the first article are here:

http://ferreira.nfshost.com/perl6/intro.html
http://ferreira.nfshost.com/perl6/zip.html

(Yes. That has been published also in use.perl and PerlMonks. But I am
assuming I did not reach anybody that could help me out yet.)

  



  It looks very nice.  I have one suggestion: you might want to mention 
the roundrobin function in the article on the zip function since the two 
are very closely related.


Joe Gottman


Re: [svn:perl6-synopsis] r14447 - doc/trunk/design/syn

2007-09-06 Thread Joe Gottman

[EMAIL PROTECTED] wrote:

Author: larry
Date: Thu Sep  6 09:31:16 2007
New Revision: 14447

+
+C infix:andthen , proceed on success
+
+test1() andthen test2()
+
+Returns the left argument if the left argument indicates failure
+(that is, if the result is undefined).  Otherwise it
+evaluates and returns the right argument.
+
+If the right side is a block or pointy block, the result of the left
+side is bound to any arguments of the block.  If the right side is
+not a block, a block scope is assumed around the right side, and the
+result of the left side is implicitly bound to C$_ for the scope
+of the right side.  That is,
+
+test1() andthen test2()
+
+is equivalent to
+
+test1() andthen - $_ { test2() }
+
+There is no corresponding high-precedence version.
+
 =back
 


+C infix:orelse , proceed on failure
 
-$value err $default

+test1() orelse test2()
 
-Returns the left argument if it's defined, otherwise evaluates and

-returns the right argument.  In list context forces a false return
-to mean C().  See C// above for high-precedence version.
+Returns the left argument if the left argument indicates success
+(that is, if the result is defined).  Otherwise it evaluates and
+returns the right argument.
+
+If the right side is a block or pointy block, the result of the left
+side is bound to any arguments of the block.  If the right side is
+not a block, a block scope is assumed around the right side, and the
+result of the left side is implicitly bound to C$! for the scope
+of the right side.  That is,
+
+test1() orelse test2()
+
+is equivalent to
+
+test1() orelse - $! { test2() }
+
+(The low-precedence C// operator is similar, but does not set C$! or
+treat blocks specially.)
 
 =back
 

  
  Do the results of andthen and orelse really bind to ANY arguments of 
the second block?  If the second block has two parameters it makes more 
sense to me for the results to bind to the first parameter and nothing 
to bind to the second parameter.


Joe Gottman


Re: [svn:perl6-synopsis] r14376 - doc/trunk/design/syn

2007-04-17 Thread Joe Gottman

[EMAIL PROTECTED] wrote:

+
+The value of the conditional expression may be optionally bound to
+a closure parameter:
+
+iftesta() - $a { say $a }
+elsif testb() - $b { say $b }
+else  - $b { say $b }
  
I'd prefer it if the result of a test in an if or elsif were usable in 
all subsequent elsif or else statements in the same if .. elsif .. else 
clause, so you could do something like


  if testa() - $a {say $a  is true}
  elsif testb() - $b say {$a is false and $b is true}
  else  say {Neither $a nor $b is true}


Joe Gottman


Re: Y not

2007-02-20 Thread Joe Gottman

Larry Wall wrote:

Hmm, but then what corresponds to XX?  I'd be more inclined to go
the other way and say that you can transform any list infix form to
the corresponding function form:

@a ZZ @b ZZ @c - zip operator
ZZ(@a; @b; @c) - zip function

@a XX @b XX @c - cross operator
XX(@a; @b; @c) - cross function

@a X*X @b X*X @c - cross product operator
X*X(@a; @b; @c) - cross product function

@a MM @b MM @c - minmax operator
MM(@a; @b; @c) - minmax function



  
  But the X*X already has a meaning:  * under the cross metaoperator.  
Maybe you could use DD instead (for dot product).


Joe Gottman



Question about interpolating version of qw

2007-02-10 Thread Joe Gottman
Does the interpolating version of qw split a string into words before or 
after it interpolates?  So if I have

  my $foo = 'Hello World';
   my @bar = «$foo»;

does @bar equal ('Hello World') or ('Hello', 'World')?

Joe Gottman


Map on a multislice

2007-01-25 Thread Joe Gottman
When you call map on a multislice, does it do deep or shallow 
iteration?  I can see uses for both of these:


my @multislice = ([1,2], [3,4, 5]);

my @dims = map :shallow [EMAIL PROTECTED] @multislice; # Want (2, 3)
my @changed_slice = map :deep {2 * $_ + 1} @multislice; # Want ([3, 5], 
[7, 9, 11])


Obviously both should be possible, and if we have a multislice with more 
than 2 dimensions we should be able to iterate at any level.  So what is 
the default iteration level and how do we override?


Joe Gottman

Joe Gottman


Suggestion: minmax operator

2007-01-09 Thread Joe Gottman
  Since Perl6 is going to have infix min and max operators, it might be 
a good idea to have an infix minmax operator, defined by

 $a minmax $b === ($a min $b), ($a max B); #2-element list

This would be especially useful as a reduction operator:
  my ($min, $max) = [EMAIL PROTECTED];

Joe Gottman


Gather/Take and threads

2006-12-06 Thread Joe Gottman
Suppose I have a gather block that spawns several threads, each of which
calls take several times.  Obviously, the relative order of items returned
from take in different threads is indeterminate, but is it at least
guaranteed that no object returned from take is lost?

 

 

Joe Gottman

 



A suggestion for a new closure trait.

2006-08-29 Thread Joe Gottman
Since a FIRST block gets called at loop initialization time, it seems to me
that it would be useful to have a block closure trait, RESUME, that gets
called at the beginning of every loop iteration except the first. Thus, at
the beginning of each loop iteration either FIRST or RESUME but not both
would get called. Other possible names for this block include REENTER,
SUBSEQUENT, or NOTFIRST. 

RESUME would have many uses.  For example, to put commas in the right places
in a printed list:

for @list - @value {
print $value;
RESUME {print ', ';} #If this were NEXT we would print an extra comma at
the end.
LAST {print \n;}
}

RESUME could also be useful for maintaining state information, such as loop
iteration or running sum, between loop iterations:

for @data - $value {
   state $index will first {$_ = 0;} will resume {++$_;}
   state $sum will first {$_ = $value;} will resume {$_ += value;}
   ...
}


Joe Gottman 






RE: NEXT and the general loop statement

2006-08-18 Thread Joe Gottman


 -Original Message-
 From: Larry Wall [mailto:[EMAIL PROTECTED]
 Sent: Friday, August 18, 2006 11:47 AM
 To: Perl6 Language List
 Subject: Re: NEXT and the general loop statement
 
 On Fri, Aug 18, 2006 at 01:44:35AM -0600, Luke Palmer wrote:
 : On 8/17/06, Jonathan Scott Duff [EMAIL PROTECTED] wrote:
 : Depends on when it fires I guess. Your example might be equivalent to
 : this perl5ish:
 : 
 : while (1) {
 : $num = rand;
 : print $num;
 : last if $num  0.9;
 : print ,;  # NEXT
 : }
 : print \n; # LAST
 :
 : Which, incidentally, relates back to the discussion at hand.  If this
 : were the case, though, the state of the variables (in three-arg for
 : loops and side-effecty while loops) would seem to reflect the state of
 : the next iteration from the rest of the code.  It would also
 : (obviously) fire after user input for eg. a for = loop.
 :
 : So, unless the next paragraph is feasible, I think NEXT ought to be
 : equivalent to LEAVE, perhaps with the exception of exceptional
 : circumstances.
 
 I think it is equivalent to LEAVE, unless you've explicitly opted out
 with last or an exception.
 
 : But I was talking about hypotheticalization.  That is, unless I am
 : mistaken we have temp {} and let {} using UNDO blocks (which are given
 : default definitions where possible).  So perhaps we could use that
 : feature to provide a NEXT trait which actually executes only if there
 : is a next iteration, while giving the block the impression that it is
 : executing in the previous iteration.  This, of course, would not work
 : for loops whose conditions have irreversible side-effects.
 :
 : Overall, it might be feasible in some circumstances, but it may not be
 : worth it.  Its implementation (and usage caveats) are quite complex
 : for a relatively minor convenience feature.  For a user to implement
 : its effect by himself, using the extended knowledge he has of the loop
 : semantics, would probably not take more than four extra lines in the
 : worst case.
 
 It would mean that we can't use NEXT to replace Perl 5's continue
 blocks, for instance, since those are required to run before the
 while loop's condition is tested.  Which also basically means we
 couldn't rewrite loop (;;) using NEXT.  So I think NEXT should just
 be equivalent to LEAVE from the viewpoint of conditionals outside
 the loop body.  You have to use last to do better.
 

   One alternative that would work well in many cases would be to define a
REENTER block, which would be called at the beginning of any loop iteration
after the first one. This would be much easier to implement that the idea of
NEXT blocks being mutually exclusive to LAST blocks, because it depends only
on what happened in the past, not the future.  Luke's example could then be
implemented as

for @objs {
.print;
REENTER { print ,  }
LAST { print \n }
}

In a language that has both if and unless, it makes sense to have a block
that means not FIRST. I'm not sure about the name; besides REENTER, other
possible names would be SUBSEQUENT or NOTFIRST.

Joe Gottman



RE: NEXT and the general loop statement

2006-08-17 Thread Joe Gottman


 -Original Message-
 From: Luke Palmer [mailto:[EMAIL PROTECTED]
 Sent: Thursday, August 17, 2006 8:44 PM
 To: Perl6 Language List
 Subject: Re: NEXT and the general loop statement
 Wasn't NEXT supposed to do something tricky, such as being mutually
 exclusive with LAST?  I remember a debate some time ago where some
 complained but that would be hard to implement, and the solution
 being mostly correct but failing in this case.
 
 I seem to recall NEXT being created in order to do things like this:
 
 for @objs {
 .print;
 NEXT { print ,  }
 LAST { print \n }
 }
 

Is this even possible?  This would require Perl to know which iteration is
going to be the last one.  In many cases there is no way to know this:

   repeat {



RE: NEXT and the general loop statement

2006-08-17 Thread Joe Gottman


 -Original Message-
 From: Luke Palmer [mailto:[EMAIL PROTECTED]
 Sent: Thursday, August 17, 2006 8:44 PM
 To: Perl6 Language List
 
 Wasn't NEXT supposed to do something tricky, such as being mutually
 exclusive with LAST?  I remember a debate some time ago where some
 complained but that would be hard to implement, and the solution
 being mostly correct but failing in this case.
 
 I seem to recall NEXT being created in order to do things like this:
 
 for @objs {
 .print;
 NEXT { print ,  }
 LAST { print \n }
 }
 
 We also might consider using perl6's hypothetical features to
 implement NEXT correctly in all cases (except for those cases where
 the loop update condition cannot be hypotheticalized).



Is this even possible?  This would require Perl to know which iteration is
going to be the last one.  In many cases there is no way to know this:

   repeat {
  $num = rand;
  print $num;
  NEXT {print ',';}
  LAST {print \n;}
} while $num  0.9;

If rand is a true random-number generator it would take a time machine to
determine whether to call NEXT or LAST.
(Sorry for the double post.)

Joe Gottman



NEXT and the general loop statement

2006-08-16 Thread Joe Gottman
Is a NEXT clause called before or after the update portion of a general loop
statement?  For instance, consider the following code:

 

loop $n = 0; $n  5; ++$n {

NEXT {print $n;}

}

 

Is the output 01234 or 12345?

 

Joe Gottman

 

 



RE: S29 update ready

2006-07-08 Thread Joe Gottman


 -Original Message-
 From: Aaron Sherman [mailto:[EMAIL PROTECTED]
 Sent: Saturday, July 08, 2006 6:05 PM
 To: Perl6 Language List
 Subject: S29 update ready
 
 I've gathered my ducks in a row, used the feedback that I've gotten so
 far, and I think I'm ready to officially update S29. For that I need two
 things:
 
 1) I'd really like Larry to glance over the changes and $s29.bless but
 all comments are welcome
 2) I'll need commit rights to whatever repository is authoritative for
 Functions.pod these days
 
 Here is the current version (I've added chr and ord docs now):
 
 http://www.ajs.com/svn/ajs/perl6/Functions.pod
 
 If anyone has any comments at all, please send me mail or respond to the
 list. I'll try to address everything I can.
 
 This is the first big update. There will be more if this all goes well.

I have one minor comment about join.  You should specify its behavior when
it is passed an empty list.  Does it return undef or the empty string?

Joe Gottman  



S5 - Question about repetition qualifier

2006-04-25 Thread Joe Gottman
According to Synopsis 5, the repetition qualifier is now **{.} where the .
must correspond to either an Int or a Range.  This seems rather restrictive.
Why are we not allowed a junction of Ints, for instance 

m/^ a**{1|3|5} $/ ; # Match 1,3, or 5 a's.

 

This does not seem noticeably more difficult than a range.  

Also, I don't know exactly what the syntax looks like, but I can imagine
using a repetition qualifier that takes a closure of some sort, for instance
to match an odd number of repetitions

 

m/^ a**{($_ % 2 == 0)} $/; #I'm not sure about the syntax for the code.

 

Joe Gottman




RE: [svn:perl6-synopsis] r8637 - doc/trunk/design/syn

2006-04-10 Thread Joe Gottman


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Monday, April 10, 2006 10:22 PM
 To: perl6-language@perl.org
 Subject: [svn:perl6-synopsis] r8637 - doc/trunk/design/syn
 
 Author: larry
 Date: Mon Apr 10 19:21:56 2006
 New Revision: 8637
 
 Modified:
doc/trunk/design/syn/S04.pod
 
 Log:
 Bare block executes immediately; return of closure must be explicit.
 
 
 Modified: doc/trunk/design/syn/S04.pod
 
 +Although a bare block is no longer a do-once loop, it still executes
 +immediately as in Perl 5.  If you wish to return a closure from a
 +function, you must use an explicit Creturn.
 +

  
   How does the sub keyword fit in here?  Is there any difference between
the lines
return {say Hello World;};
and 
return sub {say Hello World;};
?


Joe Gottman



RE: [svn:perl6-synopsis] r8520 - doc/trunk/design/syn

2006-04-01 Thread Joe Gottman


 -Original Message-
 +You may cast CArguments to other types with a prefix sigil operator:
 +
 +$args = \3; # same as $args = \(3)
 +$$args; # same as $args as Scalar or Scalar($args)
 +@$args; # same as '$args as Array  or Array($args)
 +%$args; # same as '$args as Hash   or Hash($args)
 +$args; # same as '$args as Code   or Hash($args)


Shouldn't this last one be
  +$args; # same as '$args as Code   or Code($args)

Joe Gottman
 



Named Subroutine return values

2006-02-23 Thread Joe Gottman
According to the revised Synopsis 6, named subroutines can have one of three
forms:

 

   my RETTYPE sub NAME ( PARAMS ) TRAITS {...}# lexical only

   our RETTYPE sub NAME ( PARAMS ) TRAITS {...}# also package-scoped

sub NAME ( PARAMS ) TRAITS {...}# same as our

 

 

Note that the third possibility here does not include a return type.  Does
this imply that if we want to declare a subroutine with a return type we
have to declare it as either a my sub or an our sub?

 

Joe Gottman




Do chained comparisons short-circuit?

2006-01-18 Thread Joe Gottman
   Suppose I have code that looks like this:

my ($x, $y, $z) = (1, 2, 3);

say sorted backward if ++$x  ++$y  ++$z;

 

Will $z be incremented even though the chained comparison is known to be
false after ++$x and ++$y are compared?

 

Joe Gottman




RE: binding arguments

2005-12-24 Thread Joe Gottman


 -Original Message-
 From: Juerd [mailto:[EMAIL PROTECTED]
 Sent: Saturday, December 24, 2005 7:26 PM
 To: perl6-language@perl.org
 Subject: binding arguments
 
 Merry Christmas to you all!
 
 We use = for pairs, but also for something very different: named
 argument binding. Yes, pairs are used for that, but that introduces
 problems. The most important problem, that pairs sometimes have to be
 passed, and sometimes have to be named arguments, is fixed with a hack
 that to me, just doesn't feel right: if the pair is literal and not
 inside grouping parens, it's a named argument. Otherwise, it's a pair.
 Especially with the function of the () glyphs being different between
 with and without whitespace after the subname, this can be very
 confusing.
 
 I'd like pairs and argument binding to be two different things. With
 different syntaxes.
 
 The next thing I thought was: hey, argument *passing* is actually
 *binding* to variables in the sub, so why not use the := operator? That
 works very well, because binding as an expression makes no sense anyway,
 it being a language thing. And luckily, named arguments are also a
 language thing, so that works out:
 
 foo(
 named_arg := $value,
 other_arg := $value,
 );
 

   The only problem I'd have with this is what if there already exists a
variable with the same name as the named argument?

sub foo($named_arg) {say $named_arg;}

my $named_arg = 1;
my $value = 2;
foo($named_arg := $value); #Does this bind my $named_arg to $value?
say $named_arg; #Must print 1, not 2

To avoid this, perhaps we can use - or - instead?

foo($named_arg - $value);
foo($value - $named_arg);

Which one of these two is better depends on whether you think the parameter
or the argument being bound to it is more important.  


Joe Gottman




RE: Problem with dwimmery

2005-12-22 Thread Joe Gottman


 -Original Message-
 From: Austin Frank [mailto:[EMAIL PROTECTED]
 Sent: Thursday, December 22, 2005 10:58 AM
 To: Luke Palmer
 Cc: perl6language,
 Subject: Re: Problem with dwimmery
 Do we still have a yada yada yada?  Could it be used to differentiate
 between the two cases?
 
  while $x--  some_conditions( $x ) {...}
 
 but
 
  my $hashref = {};
 
 Thanks,


   These do two different things.  {...} indicates that foo is just being
declared and the program should die if the code is ever executed.  {} is an
empty subroutine that executes by doing absolutely nothing.

Joe Gottman



What's the latest on Iterators?

2005-11-11 Thread Joe Gottman
   The various synopses contain many mentions of Iterators.  These are used,
for instance, to implement lazy lists so the expression 1..1_000_000 does
not have to allocate a million element array.  But as far as I can tell the
term is never defined anywhere in the synopses. Is Iterator a role, and if
so what methods is it required to have?  Do functions like map and grep,
which in Perl5 return lists, return Iterators in Perl6?  Can an Iterator be
passed to a function (like map and grep again) that requires a list as an
input?  Does an array or hash have only one Iterator or can it have several
independent ones?

 

Joe Gottman  



RE: Look-ahead arguments in for loops

2005-10-01 Thread Joe Gottman


 -Original Message-
 From: Damian Conway [mailto:[EMAIL PROTECTED]
 Sent: Saturday, October 01, 2005 8:53 AM
 To: perl6-language@perl.org
 Subject: Re: Look-ahead arguments in for loops
 
 Austin Hastings wrote:
 
  All of these have the same solution:
 
  @list = ...
  for [undef, @list[0...]] ¥ @list ¥ [EMAIL PROTECTED], undef] - $last, 
  $curr,
  $next {
...
  }
 
  Which is all but illegible.
 
 Oh, no! You mean I might have to write a...subroutine!??
 
  sub contextual (@list) {
  return [undef, @list[0...]] ¥ @list ¥ [EMAIL PROTECTED], undef]
  }
 
  for contextual( create_list_here() ) - $last, $curr, $next {
  ...

   This looks useful enough to be in the core, but it needs a couple of
parameters, one to say how many copies of the list it zips up, and another
to say what the first offset is.

   sub contextual($number_of_copies, $first_offset, @list) {...} # I'm not
sure how to write it.
Then your example would be

for contextual(3, -1, create_list_here() )- $last, $first, $next {

Joe Gottman



RE: $object.meta.isa(?) redux

2005-08-10 Thread Joe Gottman


 -Original Message-
 From: Luke Palmer [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, August 10, 2005 11:53 AM
 To: TSa
 Cc: Perl6 Language List
 Subject: Re: $object.meta.isa(?) redux
 
 
 A new development in perl 6 land that will make some folks very happy.
  There is now a Set role.  Among its operations are (including
 parentheses):
 
 (+)   Union
 (*)   Intersection
 (-)   Difference
 (=)  Subset
 ()   Proper subset
 (=)  Superset
 ()   Proper superset
 (in)  Element
 (=)   Set equality
 
 I believe the unicode variants are also allowed.
 
 And now we're doing away with junctive types in favor of set types.

   Will there be an operator for symmetric difference?  I nominate (^).

Joe Gottman



RE: reduce metaoperator on an empty list

2005-05-31 Thread Joe Gottman


 -Original Message-
 From: Damian Conway [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, May 31, 2005 11:14 PM
 To: perl6-language@perl.org
 Subject: Re: reduce metaoperator on an empty list
 
 Juerd asked:
 
 
 2+ args: interpolate specified operator
 1 arg:   return that arg
 0 args:  fail (i.e. thrown or unthrown exception depending on use
 fatal)
 
  Following this logic, does join( , @foo) with [EMAIL PROTECTED] being 0 
  fail too?
 
 No. It returns empty string. You could think of Cjoin as being
 implemented:
 
  sub join (Str $sep, [EMAIL PROTECTED]) { reduce { $^a ~ $sep ~ $^b } , 
 @list }
 
 Just as Csum is probably implemented:
 
  sub sum ([EMAIL PROTECTED]) { [+] 0, @list }
 

   If this were the case, then
join '~', 'a', 'b', 'c'
 would equal '~a~b~c' instead of 'a~b~c'

Joe Gottman



RE: Declaration of my() variables using symbolic referentiation

2005-05-21 Thread Joe Gottman


 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] On Behalf Of Ingo Blechschmidt
 Sent: Saturday, May 21, 2005 7:22 AM
 To: perl6-language@perl.org
 Subject: Declaration of my() variables using symbolic referentiation
 
 Hi,
 
 am I correct in the assumption that the following is an error?
   # Not in a BEGIN block
   my $::(calc_varname()) = 42;
 
 I think so, as my() is a compile-time operation, but in this
 example, the variable name is not known until runtime, so I
 think this should be forbidden.  Correct?
 
 But:
   BEGIN {
 my $::(calc_varname()) = 42;
   }
 I think this one is ok, as the compiler can invoke
 calc_varname at compile-time, and therefore know the variable
 name at compile-time.  Correct?
 
 FWIW, I wouldn't mind BEGIN { my $::(...) } being disallowed, too
 (consistency).
 

   Even if it's legal it's fairly useless because $::(calc_varname()) goes
out of scope at the end of the BEGIN block.  You could probably write a
macro to accomplish what you want:

   macro declare_var(String $varName) {\$$varName}

Then you wouldn't even need the BEGIN block.
my declare_var(calc_varname()) = 42;

The compiler wouldn't know the variable name until runtime, but I think this
just means that this just transforms compile-time errors to runtime errors.

Joe Gottman



RE: should we change [^a-z] to -[a..z] instead of -[a-z]?

2005-04-17 Thread Joe Gottman


 -Original Message-
 From: Paul Hodges [mailto:[EMAIL PROTECTED]
 Sent: Sunday, April 17, 2005 1:30 PM
 To: Larry Wall; perl6-language@perl.org
 Subject: Re: should we change [^a-z] to -[a..z] instead of -[a-z]?
 
 
 --- Larry Wall [EMAIL PROTECTED] wrote:
 . . .
  -[a..z]
 
  should be allowed/encouraged/required.  It greatly improves the
  readability in my estimation.  The only problem with requiring .. is
  that people *will* write [a-z] out of habit, and we would probably
  have to outlaw the - form for many years before everyone would get
  used to the .. form.  So maybe we allow - but warn if not
  backslashed.
 
 In general, I think this is a great idea, but what exactly do you mean
 by warn if not backslashed? That I'd get a warning *any* time I use a
 dash in a character class? I guess I can live with that.

   On the other hand, you can use the canonical perl 5 trick of having the
dash be the first character in the class if you want to use a literal dash.

Joe Gottman.





RE: New S29 draft up

2005-03-16 Thread Joe Gottman



 -Original Message-
 From: Rod Adams [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, March 16, 2005 3:18 AM
 To: Perl6 Language List
 Subject: New S29 draft up
 
 
 I just posted a fresh copy of S29 to:
 
  http://www.rodadams.net/Perl/S29.pod
  http://www.rodadams.net/Perl/S29.html
 
 New:
 
  All defined functions have been restructured into packages.
 
  Perl6::Arrays, Perl6::Lists, and Perl6::Hashes are (mostly) written.
 
  Some Math::Basic and Math::Trig functions added.
 
  :'s have been added into signatures where they belong.
 
  various other clean ups.
 

  Isn't there also supposed to be an Arrays::kv?  Also, I'm pretty sure
Larry said the Lists::reduce should go in the core.

Let me try to define them.

multi sub kv (Array @array : [EMAIL PROTECTED]) returns List
Returns the indexes and associated values stored in @array, lazily and in
order by index. Optionally, only those of the slice defined by @indices.



multi sub reduce (Code $expression : [EMAIL PROTECTED]) returns List
{
   my $res;
   for @values - $cur {
FIRST {$res = $cur; next;}
 $res = $expression($res, $cur);
  }
  $res;
}


Joe Gottman



Closure trait for loop entry

2005-02-12 Thread Joe Gottman
   Often when I write a loop I want to run some code at loop entry time.  It
would be nice to have a closure trait for this, similar to NEXT for loop
continuation or LAST for loop termination, but there isn't one.  I don't
think either FIRST or ENTER do quite what I want.  FIRST runs only once,
which is too few times, and ENTER runs every time the loop block is entered,
which is too many.

   To demonstrate what I want, consider the following examples:

   sub use_first() 
   {
for 1..2 {
FIRST {say 'entering loop';}
say $_; 
LAST{say 'leaving loop';}
}
  }

  sub use_enter()  
   {
for 1..2 {
ENTER {say 'entering loop';}
say $_; 
LAST{say 'leaving loop';}
}
  }


The first time use_first is called it will print
entering loop
1
2
leaving loop

but subsequently it will print
1
2
leaving loop

and leave out the 'entering loop'.

When use_enter is called it will print
entering loop
1
entering loop
2
leaving loop

I want to output
entering loop
1
2
leaving loop

every time I run my loop. I suggest we create a new closure trait called
SETUP for this.  Then the code could read

for 1..2 {
SETUP {say 'entering loop';}
say $_; 
LAST{say 'leaving loop';}
}

Since SETUP can be used for initialization, it should probably be allowed
within an expression:
state $first_iteration = SETUP {true} will next {$_ = false};

Lower case 'setup' could probably also be used as a trait on a variable
state $first_iteration will setup {$_ = true} will next {$_ =
false};

Joe Gottman




Making control variables local in a loop statement

2005-01-13 Thread Joe Gottman
   In Perl5,  given code like

for (my $n = 0; $n  10; ++$n) {.}

the control variable $n will be local to the for loop.  In the equivalent
Perl6 code
   loop my $n = 0; $n  10; ++$n {.}

$n will not be local to the loop but will instead persist until the end of
enclosing block.  

   It would be nice if there were some easy way to mimic the Perl5 behavior
in Perl6.  In Perl6, the canonical way to make a variable local to a block
is by making it a parameter. I therefore suggest allowing the following
syntax:

loop 0 - $n; $n  10; ++$n {...}

This will declare $n as a control variable to the loop and initialize it to
0.  Like any parameter, it will then be local to that block (assuming the
comparison and update portions of the loop statement are injected into the
block).  One subtlety is that $n should probably be treated as if it were
declared with the is copy attribute, so that it can be modified inside the
loop (by the update portion if nothing else), but does not alias a variable
it was initialized from.  

Joe Gottman





RE: Perl 6 Summary for 2004-11-08 through 2004-11-15

2004-11-15 Thread Joe Gottman


 -Original Message-
 From: Matt Fowles [mailto:[EMAIL PROTECTED]
 Sent: Monday, November 15, 2004 11:27 PM
 To: [EMAIL PROTECTED]; Perl 6 Internals List; perl6-
 [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Perl 6 Summary for 2004-11-08 through 2004-11-15
 
 Perl 6 Summary for 2004-11-08 through 2004-11-15
matching the nth occurrences
 Sudarshan Gaikaiwari wanted to know how to match the 2nd last last
 occurrence in Perl6 rules. I think the message might have been posted
 directly to google groups, as I did not get it in my email and nobody
 replied. The example given matches the 2nd occurrence. As I am not
 sure
 what is meant by 2nd last, I will answer the question I do know.
 m:2nd/foo/ will match the second occurrence of foo. The nth
 occurrence
 can be accessed similarly.

   I believe that the OP wanted to know how to match the second-to-last
occurrence.  So if we were to do something like
m:nth(-2)/foo/ # just a guess about the syntax.
on a string containing 4 foo's, then this would match the third foo.

Joe Gottman






RE: Reverse .. operator

2004-09-03 Thread Joe Gottman


 -Original Message-
 From: Larry Wall [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 02, 2004 8:41 PM
 To: Perl6
 Subject: Re: Reverse .. operator
 
 On Thu, Sep 02, 2004 at 08:34:22PM -0400, Joe Gottman wrote:
 : Is there similar shorthand to set @foo = (5, 3, 3, 2, 1) ?  I know you
 can
 : go
 :
 : @foo = reverse (1 ..5);
 :
 : but this has the major disadvantage that it cannot be evaluated lazily;
 : reverse has to see the entire list before it can emit the first element
 of
 : the reversed list.
 
 I don't see any reason why it can't be evaluated lazily.  The .. produces
 a range object that gets shoved into the lazy list that gets bound to
 the slurp array of reverse().  If you pop that, there's no reason it
 couldn't go out and ask the end of the lazy list for its last element.
 Just have to make .. objects smart enough to deal off either end of
 the deck.

   I get it.  One way to implement this would to give the .. object a
.reverse member iterator that lazily iterates from right to left, and have
the reverse subroutine call the .reverse member on the list that was passed
to it (if this member exists).  The advantage of this is that it can be
extended for other types, or even to arrays returned from functions.  For
instance,
 
multi sub grep(Code $f, [EMAIL PROTECTED] does reverse)  returns (Array does
reverse {grep $f, @array.reverse;}) #reverse input

   multi sub map(Code $f, [EMAIL PROTECTED] does reverse) returns (Array does reverse
{map {reverse $f($_)} @array.reverse;}) #reverse input and result of each
call to $f

If it isn't possible to overload a multi sub on a .does property, we can
achieve the same effect by creating a ReversableArray class that inherits
from Array and overloading on that.

Joe Gottman





Reverse .. operator

2004-09-02 Thread Joe Gottman
In perl 6, the statement  

@foo = (1.. 5) ;

is equivalent to

@foo = (1, 2, 3, 4, 5); 

 

Is there similar shorthand to set @foo = (5, 3, 3, 2, 1) ?  I know you can
go

@foo = reverse (1 ..5);

but this has the major disadvantage that it cannot be evaluated lazily;
reverse has to see the entire list before it can emit the first element of
the reversed list.  Would

@foo = (5 .. 1 :by(-1));

do the trick?  If so, would the same trick work for

@bar = ('e' .. 'a' :by(-1)); ?

 

Joe Gottman

 





Synopsis 4: Return type of a ~~ b

2004-08-27 Thread Joe Gottman
 

I just reread the table of smart matches in Synopsis 4, and I realized
that it doesn't say what is returned by a ~~ b.  For example, the first line
of this table says

 

  $_  $xType of Match ImpliedMatching Code

==  = ==

Any Code$   scalar sub truth match if $x($_)

 

This is fine when $_ ~~ $x is called in boolean context.  But what if the
smart match operator is called in array or list context?   Does 

$_ ~~ $x 

then return the result of $x($_)?  I would expect that it does. After all,
in Perl 5, the expression 

   $string =~ /(a+)(b+)/ 

returns a list of captured substrings in list context

 

 

Joe Gottman

 





RE: This fortnight's summary

2004-08-25 Thread Joe Gottman
   None of the links for the perl6-language threads work.

Joe Gottman




Mailing list archives

2004-08-13 Thread Joe Gottman
   There's something wrong with the mailing list archives at
http://dev.perl.org/perl6/lists/.  I can get to this page OK, but when I
click on a link to the perl6-internals or perl6-language archives, I get a
This page cannot be displayed error.

 

Joe Gottman





Anonymous Named params (Was Revision of A12's lookahead notions)

2004-08-13 Thread Joe Gottman


 -Original Message-
   1d) Additional arguments may occur as adverbs *only* if there
   are explicit parens.  (Or in the absence of parens they may
   parse as arguments when a term is expected--but then they're
   not adverbs, just named arguments...)
 
   splurt():by{ +$_ }  # okay
   splurt 1,2,3 :by{ +$_ } # ILLEGAL (comma rejects the adverb)
   splurt 1,2,3 :{ +$_ }   # ILLEGAL (comma rejects the adverb)
   splurt 1,2,3,:{ +$_ }   # likely okay (as anonymous named
 param)
   splurt :{ +$_ } # likely okay (as anonymous named
 param)
   splurt { +$_ }  # okay (positional param)
   splurt 1,2,3, { +$_ }   # okay (positional param)
 


   Doesn't the concept of an anonymous named param (in the fourth and fifth
examples above) seem like an oxymoron?  If it's anonymous it can't have a
name (or at least we can't know its name).  More importantly, what is an
anonymous named param used for?  

   Also, suppose I have a hash 
%foo = {'by' = 1, 'from' = 2}; 
Would 
splurt :%foo;
have the same result as
splurt :by(1) :from(2); 

or would I need the braces in this case?


Joe Gottman




RE: if not C, then what?

2004-07-09 Thread Joe Gottman


 -Original Message-
 From: Larry Wall [mailto:[EMAIL PROTECTED]
 Sent: Friday, July 09, 2004 2:33 PM
 To: [EMAIL PROTECTED]
 Subject: Re: if not C, then what?
 
 On Fri, Jul 09, 2004 at 11:23:09AM -0700, Austin Hastings wrote:
 : Will there be a statement modifier version of Cwhen?
 :
 :   print, next when /stgh/;
 
 Yes, though in this case it's indistinguishable from Cif, since //
 defaults to $_ anyway.  However, these are different:
 
 print, next when 3;
 print, next if 3;
   
   Will given be a statement modifier also?  This would be useful for quick
topicalization:

say $_ = %hash{$_} given get_random_key();

Joe Gottman




RE: definitions of truth

2004-06-24 Thread Joe Gottman


 -Original Message-
 From: Dave Whipp [mailto:[EMAIL PROTECTED]
 Sent: Thursday, June 24, 2004 5:22 PM
 To: [EMAIL PROTECTED]
 Subject: Re: definitions of truth
 
 Larry Wall [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
  This is Perl 6.  Everything is an object, or at least pretends to be
 one.
  Everything has a .boolean method that returns 0 or 1.  All conditionals
  call the .boolean method, at least in the abstract.
 
 My reading of A12 leads me to expect this to be defined as a coercion,
 using
 the as operator, not dot:
 
   $foo as boolean
 
 What am I missing?

   Why not just use say 
?$foo 

Isn't the prefix ? operator designed specifically for this use?

Joe Gottman




Next Apocalypse

2004-06-10 Thread Joe Gottman
   Now that Apocalypse 12 is out, which one is Larry going to work on next?

 

Joe Gottman





FW: Periodic Table of the Operators

2004-05-28 Thread Joe Gottman



 -Original Message-
 From: Mark Lentczner [mailto:[EMAIL PROTECTED]
 Sent: Friday, May 28, 2004 7:18 PM
 To: [EMAIL PROTECTED]
 Subject: Re: Periodic Table of the Operators
 
 Not to beat a dead horse, but
 
 I've updated the Periodic table with almost all the changes that people
 here sent me, as well as reading a few more threads and references.
 This will be the last update for some time
   
   The zip operator is now the Yen sign (¥).

Joe Gottman




A12 - Protected Attributes and Methods

2004-04-20 Thread Joe Gottman
   Apocalypse 12 was very clear about the difference between private and
public class members, but it didn't say anything about protected ones?  How
can you define a protected member?   Do you have to do the following?
has $.foo is protected;
method bar() is protected;

   Maybe we could have another secondary sigil to mark a protected method or
attribute.  I'd suggest the semicolon, but I'm afraid it would cause havoc
with the parser.

Joe Gottman




Re: backticks

2004-04-14 Thread Joe Gottman

- Original Message - 
From: Simon Cozens [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, April 14, 2004 5:04 PM
Subject: Re: backticks


 [EMAIL PROTECTED] (Aaron Sherman) writes:
  $ find . -name \*.pl | wc -l
  330
  $ find . -name \*.pl -exec grep -hlE 'qx|`|`|readpipe' {} \; |
wc -l
  123
 
  `` gets used an awful lot

 But that's in Perl 5, which is a glue language.


   And Perl 6 isn't?  I use backticks quite a bit in Perl, and I don't see
that changing if I upgrade to Perl 6.

Joe Gottman




New functions in the core (Was Re: Dereferencing Syntax)

2004-03-26 Thread Joe Gottman

- Original Message - 
From: Luke Palmer [EMAIL PROTECTED]


 Juerd writes:
  Has this Csay already been decided?

 Doesn't matter, because most of these decisions are up for discussion.
 I think everything that was decided when Apocalypse 3 was written has
 changed at least three times  (contrast with Synposis 3 :-).


   If Larry is still adding functions to the core, maybe he can add the
outer function that Luke suggested last week.  This function would be very
useful in inner loops, so if it is possible to implement it more efficiently
in the core than as a sub in a module I think we should do so.

Joe Gottman




Some questions about operators.

2004-03-19 Thread Joe Gottman
   I just read Synopsis 3, and I have several questions.

 

 

1)   Synopsis 3 says that the difference between $x ?| $y and $x || $y
is that the later always returns a Boolean. Does this mean that $x ?| $y
short-circuits?

2)   Do all of the xor variants have the property that chained calls
return true if exactly one input parameter is true?

3)   Is there an ASCII digraph for the | operator?

4)   Do == and != participate in chained comparisons, so that $a ==
$b == $c evaluates to true if and only if all three are equal?  Is $x  $y 
$z a legal chaining?  Or  $x  $y lt $z?

5)   Would it be possible for me to create a user-defined operator that
does chaining?

 

Joe Gottman





Re: Mutating methods

2004-03-15 Thread Joe Gottman

- Original Message - 
From: Deborah Pickett [EMAIL PROTECTED]
To: Perl 6 Language [EMAIL PROTECTED]
Sent: Sunday, March 14, 2004 10:44 PM
Subject: Re: Mutating methods


 On Sat, 13 Mar 2004 05.30, John Siracusa wrote:
  The only case that seems even
  remotely onerous is this one:
 
  my My::Big::Class::Name $obj = My::Big::Class::Name.new();
  vs.
  my My::Big::Class::Name $obj .= new()

 There's also the related issue of in-place operations on some
 difficult-to-write lvalue:

 @{$coderef.(argument).{hashelem}} =
   sort @{$coderef.(argument).{hashelem}};

 Did I get the text the same both times?  What about maintaining that code?
 What about side effects on the subroutine I called there?

 Someone Damian-shaped will probably come in and point out how to prettify
that
 using given, but it still wouldn't be as short as last week's

 $coderef.(argument).{hashelem}.self:sort();


   Why not just do
@{$_} = sort @{$_} given $coderef.(argument).{hashelem};

Joe Gottman




Exegesis 7: Literal '{' in format string

2004-02-29 Thread Joe Gottman
   How do you put a literal '{' or '}' into a format string in Perl 6?  Do
you use a backslash?

Joe Gottman







Re: The Sort Problem: a definitive ruling

2004-02-19 Thread Joe Gottman

- Original Message - 
From: Damian Conway [EMAIL PROTECTED]
To: Perl 6 Language [EMAIL PROTECTED]
Sent: Thursday, February 19, 2004 8:29 PM
Subject: [perl] The Sort Problem: a definitive ruling


 Csort in Perl6 is a global multisub:

  multi sub *sort(Criterion @by: [EMAIL PROTECTED]) {...}
  multi sub *sort(Criterion $by: [EMAIL PROTECTED]) {...}
  multi sub *sort( : [EMAIL PROTECTED]) {...}

 where:

  type KeyExtractor ::= Code(Any) returns Any;

  type Comparator   ::= Code(Any, Any) returns Int;

  type Criterion::= KeyExtractor
  | Comparator
  | Pair(KeyExtractor, Comparator)
  ;
   snip

 If a key-extractor block returns number, then C =  is used to
compare
 those keys. Otherwise Ccmp is used. In either case, the keys extracted
by
 the block are cached within the call to Csort, to optimize subsequent
 comparisons against the same element. That is, a key-extractor block is
only
 ever called once for each element being sorted.



   How do you decide whether a key-extractor block returns number?  Do you
look at the signature,  or do you simply evaluate the result of the
key-extractor for each element in the unsorted list?  For example, what is
the result of the following code?

  sort {$_.key} (1= 'a', 10 = 'b', 2 ='c');

   There is nothing in the signature of the key-extractor to suggest that
all the keys are numbers, but as it turns out they all are.  Will the sort
end up being numerical or alphabetic?


Joe Gottman




Re: The Sort Problem

2004-02-15 Thread Joe Gottman

- Original Message - 
From: Damian Conway [EMAIL PROTECTED]
To: Larry Wall [EMAIL PROTECTED]
Cc: Perl 6 Language [EMAIL PROTECTED]
Sent: Sunday, February 15, 2004 5:59 PM
Subject: [perl] Re: The Sort Problem


 Here's a proposed syntax and semantics for Csort that tries to preserve
the
 (excellent) features of Uri's on the right track proposal whilst
integrating
 it into the Perl 6 design without multiplying entities (especially
colons!)
 unnecessarily.

 Suppose Csort's signature is:

  type KeyExtractor ::= Code(Any) returns Any;

  type Comparator   ::= Code(Any, Any) returns Int;

  type Criterion::= KeyExtractor
  | Comparator
  | Pair(KeyExtractor, Comparator)
  ;

  type Criteria ::= Criterion
  | Array of Criterion
  ;

  multi sub *sort(Criteria ?$by = {$^a cmp $^b}, [EMAIL PROTECTED]) {...}


   If we use this signature, won't the code
sort ('foo', 'bar', 'glarch');

attempt to use the first parameter as a Criteria?  Since sort has to be a
multi sub anyhow, why don't we do

multi sub *sort(Criteria $by : [EMAIL PROTECTED]) {...}
multi sub *sort( : [EMAIL PROTECTED]) { ...} # returns sort {$^a cmp $^b} @data

Joe Gottman




Re: Semantics of vector operations

2004-01-22 Thread Joe Gottman

- Original Message - 
From: Luke Palmer [EMAIL PROTECTED]
To: Austin Hastings [EMAIL PROTECTED]
Cc: Larry Wall [EMAIL PROTECTED]; Language List [EMAIL PROTECTED]
Sent: Thursday, January 22, 2004 4:28 PM
Subject: [perl] Re: Semantics of vector operations


 Austin Hastings writes:
  How do you handle operator precedence/associativity?
 
  That is,
 
 $a + $b + $c
 
  If you're going to vectorize, and combine, then you'll want to group. I
  think making the vectorizer a grouper as well kills two birds with one
  stone.
 
$a + $b + $c
 
  vs.
 
$a + ($b + $c)

 I have to agree with Larry here, the latter is much cleaner.

 I'm actually starting to like this proposal.  I used to shiver at the
 implementation of the old way, where people used the operator to group
 arbitrary parts of the expression.  I wouldn't even know how to parse
 that, much less interpret it when it's parsed.

 Now, we have a clear way to call a method on a list of values:

 @list .method

 And a clear way to call a list of methods on a value:

 $value. @methods

 It's turning out pretty nice.

   I just realized a potential flaw here.  Consider the code
$a = 1;

   Will this right-shift the value of $a one bit and assign the result to $a
(the current meaning)?  Or will it assign the value 1 to each element in the
array referenced by $a (as suggested by the new syntax).  Both of these are
perfectly valid operations, and I don't think its acceptable to have the
same syntax mean both.  I'm aware that using = instead of = will
eliminate the inconsistency, but not everyone has easy access to Unicode
keyboards.

Joe Gottman




Re: Comma Operator

2004-01-21 Thread Joe Gottman

- Original Message - 
From: Larry Wall [EMAIL PROTECTED]
To: Perl6 [EMAIL PROTECTED]
Sent: Wednesday, January 21, 2004 2:51 PM
Subject: [perl] Re: Comma Operator


 On Tue, Jan 20, 2004 at 08:12:28PM -0800, Jonathan Lang wrote:
 : Joe Gottman wrote:
 : About a month ago, a thread here suggested that we change the
meaning
 :  of the comma operator.  Currently, in scalar context the expression
 :  foo(), bar()
 :  means evaluate foo(), discard the result, then return the value of
 :  bar().
 :  It was suggested that this be changed to return the 2-element array
 :  (foo(), bar()).  Has Larry ruled on this yet?
 :
 : Not that I'm aware of.  For the most part, the previous discussion was
 : focusing on what to replace the comma with in the case of discard all
but
 : the last result, and my impression was that any ruling on the change
 : would likely be contingent on the presence or absence of a suitable
 : replacement.

 I'm a little frustrated because I feel like I've ruled on it several
 times, but it never seems to stick.  I guess that's because it was
 never ruled in an Apocalypse, just in email.  But I'm sure I'm on
 the record somewhere saying that I think [-1] is sufficient to pick
 out the last element of a list.  If nothing else, just a couple of
 days ago, but I'm sure I also said it more than once in ancient times.


Great, so
$x = foo(), bar();
means the same thing as
$x = ( foo(), bar() );

 Is the optimizer going to be smart enough so that given the expression
$x = (foo(), bar(), glarch())[-1];

Perl6 won't have to construct a three-element array just to return the last
element?

Joe Gottman




Comma Operator

2004-01-20 Thread Joe Gottman
   About a month ago, a thread here suggested that we change the meaning of
the comma operator.  Currently, in scalar context the expression
foo(), bar()
means evaluate foo(), discard the result, then return the value of bar().
It was suggested that this be changed to return the 2-element array (foo(),
bar()).  Has Larry ruled on this yet?

By the way, even if we do make this change, I think that in void context
the expression
foo(), bar()
should still simply evaluate its parameters in order for their side-effects.
This would allow comma expressions to remain as-is in loop statements
(formerly for statements), which is where most of them are found anyway.
For instance
loop (my ($x = 0, $y = 10); $x  $y; ++$x, --$y) {...}

Joe Gottman




Re: Roles and Mix-ins?

2004-01-06 Thread Joe Gottman

- Original Message - 
From: Luke Palmer [EMAIL PROTECTED]
To: Joe Gottman [EMAIL PROTECTED]
Cc: Perl6 [EMAIL PROTECTED]
Sent: Tuesday, January 06, 2004 9:34 PM
Subject: [perl] Re: Roles and Mix-ins?


 Joe Gottman writes:
 
  - Original Message - 
  From: Luke Palmer [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Tuesday, January 06, 2004 4:51 AM
  Subject: [perl] Re: Roles and Mix-ins?
 
 
   David Storrs writes:
   
On Sat, Dec 13, 2003 at 11:12:31AM -0800, Larry Wall wrote:
 On Sat, Dec 13, 2003 at 04:57:17AM -0700, Luke Palmer wrote:
   
 : For one, one role's methods don't silently override another's.
  Instead,
 : you get, er, role conflict and you have to disambiguate
yourself.
   
How do you disambiguate?
  
   Let's see...
  
   role Dog {
   method bark() { print Ruff! }
   }
   role Tree {
   method bark() { print Rough! }
   }
   class Trog
 does Dog does Tree {
   method bark() { .Dog::bark() }
 }
   }
  
   Perhaps something like that.  In any case, you do it by putting the
   offending method directly in the aggregating class.
  
 
 How about something like
  class Trog
 does Dog {bark=dogBark} does Tree {bark=treeBark}
 {...}
 
  Then we could have code like
my Trog $foo = Trog.new();
my Dog $spot :=  $foo;
my Tree $willow := $foo;
$spot.bark(); # calls dogBark()
$willow.bark(); #calls treeBark()
 
 This works better when Dog::bark and Tree::bark are both needed but
they
  do different things.

 Renaming methods defeats the purpose of roles.  Roles are like
 interfaces inside-out.  They guarantee a set of methods -- an interface
 -- except they provide the implementation to (in terms of other,
 required methods).  Renaming the method destroys the interface
 compatibility.

 Your renaming can be done easily enough, and more clearly (IMO) with:

 class Trog
   does Dog does Tree {
 method bark() { ... }   # Explicitly remove the provided method
 method dogBark()  { .Dog::bark() }
 method treeBark() { .Tree::bark() }
 }

   But won't explicitly removing bark() from the class also disable
Dog::bark() and Tree::bark() for the class?  Renaming would work if other
methods in Dog are directed to dogBark() when they call bark(), and other
methods in Tree are redirected to treeBark().

Joe Gottman





Re: [perl] Re: Object Order of Precedence (Was: Vocabulary)

2003-12-20 Thread Joe Gottman

- Original Message - 
From: Jonathan Lang [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, December 20, 2003 3:41 PM
Subject: [perl] Re: Object Order of Precedence (Was: Vocabulary)


 Larry Wall wrote:
  If DangerousPet doesn't define a feed method at all, then we might
  dispatch to Pet and Predator as if their methods had an implicit
  multi.

 And the Cdefault trait is the tie-breaker when several options are
 equally likely candidates (in terms of type information); OK.

   I'm a little leery about calling this trait default. The problem is
that we are already using default as a keyword (see the switch statement),
and having a trait with the same name as a keyword might confuse users
and/or the compiler.

Joe Gottman




Iterating through two arrays at once

2003-12-10 Thread Joe Gottman
   In Perl 6, how will it be possible to iterate through two arrays at the
same time?  According to Apocalypse 4,  the syntax is
for @a; @b - $a; $b {

According to the book  Perl 6 Essentials the syntax is
for zip(@a, @b) - $a, $b {

Which of these is right? (of course, this being Perl, both may be right).

  Whichever of these syntaxes is right, what happens when @a and @b are of
different sizes?  I can think of three possible behaviors, each with its
potential drawbacks:

1)  The loop executes min(+ @a, + @b) times, then finishes successfully.
2) The loop executes min(+ @a, + @b) times, then throws an exception
because the arrays were not of the same size.
3) The loop executes max(+ @a, + @b) times.  If  @a has fewer elements
than  @b, then after @a's elements are exhausted $a is set to undef, and
similarly if @b has fewer elements than @a.

   In cases 1) and 2), the problem is how to get the elements of the larger
array that were never iterated over.  Case 2) is probably better than case
1), because the exception that is thrown might contain information about
which array was larger and which elements of it have yet to be examined.  In
case 3), the problem is differentiating between an undef returned because
the arrays were of different sizes, and an undef returned because one of the
arrays contained an undef.

Joe Gottman





Re: [perl] RE: s/// in string context should return the string

2003-11-18 Thread Joe Gottman
- Original Message - 
From: Austin Hastings [EMAIL PROTECTED]
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 3:04 PM
Subject: [perl] RE: s/// in string context should return the string


 As a Bvalue where possible, so they can cascade and nest.

   Excuse me.  I know enough C++ to know the difference between an lvalue
and an rvalue, but what the heck is a BValue?

Joe Gottman




Re: [perl] Re: syntax: multi vs. method

2003-11-18 Thread Joe Gottman

- Original Message - 
From: Jonathan Lang [EMAIL PROTECTED]
 So the following three declarations cover very similar (but not quite
 identical) things:

   multi sub call ($a: $b) {...}
   submethod invoke ($a: $b) {...}
   method check ($a: $b) {...}

 All three of these use multiple dispatching.  The only distinctions are
 that invoke and check can be called using method-like syntax, whereas
 call cannot; and check pays attention to inheritence, whereas call
 and invoke do not.


   Also, I assume that invoke and check will have access to $a's private
data members and methods, while call will not.

Joe Gottman




Re: Some questions about currying

2003-10-30 Thread Joe Gottman

- Original Message - 
From: Luke Palmer [EMAIL PROTECTED]

 Joe Gottman writes:
  3)  Currying binds a function parameter to a value?  Is there any way to
  bind a function parameter to a variable?  Consider the following code:
 
  sub printNum(int $x) {print $x\n;}
  my $foo = 0;
  my $vindaloo = printNum(int).assuming(x = $foo); #currying
  ++$foo;
  $vindaloo.();
 
 This code prints 0, not 1, because the currying binds the parameter
to
  the value $foo had when the currying occurred, not the value it had when
the
  curried function was called.  It would be nice if there were some way to
  curry so that a parameter is bound to a variable reference.

 There is.  Best not to worry .assuming with details of references.  Do
 it with a scratchpad:

sub printNum($x) { print $x\n }
my $foo = 0;
my $vindaloo = { printNum($foo) };
++$foo;
$vindaloo();   # Prints 1

 There's still those issues of getting $vindaloo's signature exactly
 right for complex cases.  In any case, I don't think .bind would be hard
 to write.


  This would probably have to be a different method than assuming.
  Maybe something like printNum(int).bind(x = \$foo)

   But getting the signature of the returned code object right is a major
reason for using any kind of currying function instead of just writing a
scratchpad.  Getting the signature right is a non-trivial task, and
.assuming and .bind would have to do exactly the same work to compute the
signature.  Therefore, if we are defining one in the core I think we might
as well define the other as well.

Joe Gottman




Some questions about currying

2003-10-29 Thread Joe Gottman

   I just reread the section of A6 about currying, and I have several
questions about it.

   1)  Suppose I have a function like the following:
   sub foo($param, @param) {...}
where the parameter names differ only by their sigils.  Is it legal
for me to type
foo.assuming('$param' = 1)
in order to disambiguate the parameter names?

   2)  Often, if you are working with a code reference instead of an actual
sub, you might not know the names of all the parameters.  In this case,
would it be legal to curry by parameter position instead of parameter name?

sub setFirstToOne(block) {
block.assuming( 0 = 1); #I am assuming 0-based parameter lists
}

Another advantage of currying by position is that it might allow you to set
the first few elements of a slurpy array.

sub foo(* @params) {...}
my $bar = foo.assuming(0 = hello);
$bar.(world); # Calls foo(hello, world)

3)  Currying binds a function parameter to a value?  Is there any way to
bind a function parameter to a variable?  Consider the following code:

sub printNum(int $x) {print $x\n;}
my $foo = 0;
my $vindaloo = printNum(int).assuming(x = $foo); #currying
++$foo;
$vindaloo.();

   This code prints 0, not 1, because the currying binds the parameter to
the value $foo had when the currying occurred, not the value it had when the
curried function was called.  It would be nice if there were some way to
curry so that a parameter is bound to a variable reference.  This would
probably have to be a different method than assuming.  Maybe something like
printNum(int).bind(x = \$foo)


Joe Gottman





How to create a function that returns nothing

2003-10-14 Thread Joe Gottman
How do you declare a function that doesn't return anything? For instance, a
C++ swap function might be declared
   template class X
void swap(X x, X y);

It would be nice to declare the corresponding Perl6 function as
sub swap ($x is rw, $y is rw) returns nothing {...}
or something similar.

This would be an absolute necessity if you wanted to emulate C++, Java, or
any other strongly typed language.

Also, it could be useful for causing a compile-time error if someone types
something like
$z = swap($x, $y);


Joe Gottman





Re: Perl 6's for() signature

2003-07-31 Thread Joe Gottman

- Original Message - 
From: Hanson, Rob [EMAIL PROTECTED]
To: 'Rod Adams' [EMAIL PROTECTED]; Perl 6 Language
[EMAIL PROTECTED]
Sent: Thursday, July 31, 2003 1:29 PM
Subject: RE: Perl 6's for() signature


  Anyone but me feel the need for non-greedy
  slurpy arrays? similar to non-greedy RE matches?

 I definately like the idea of having something like that.  It probably
 wouldn't be used much, but it is nice to have the option.

 One thing though, can't you accomplish the same thing by slurping
 everything, then poping the block off of the array?

 Rob

Yes, but you lose compile-time type checking on the last parameter.  I
would prefer to have
for 1,2,3;

fail at compile-time, not run time;




Re: Short-circuiting user-defined operators

2003-04-03 Thread Joe Gottman

- Original Message -
From: Luke Palmer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 6:39 PM
Subject: Re: Short-circuiting user-defined operators


  Paul wrote:
   --- Austin Hastings [EMAIL PROTECTED] wrote:
  
  Dave Whipp wrote:
  
  Joe Gottman wrote:
  
  
   Getting deep -- sorry. :)
  
  
  Alternatively, there might be a new parameter type that indicates
  that the parameter is not evaluated immediately:
  
  sub infix:!! ($lsh, $rhs is deferred) {...}
  
  
   If the standard is pass-by-ref it wouldn't trip any side effects
unless
   you did so in your code, right? So is this necessary?
  
 
  There are two reasonable semantics for deferred parameters:
 
  1) lazy evaluation with caching, where the evaluation of the
  actual expression in the call is deferred until the sub
  actauly makes use of it and the result is then cached and
  reused as necessary.  Any side effects happen only once.
 
  2) ALGOL style pass by name, where the actual expression from the
  call is turned into a clouser called a thunk which is called
  when ever the sub access the parameter.  Note that the thunk
  may need to be an lvalue clouser to handle is rw paramenters.
  Side effects happen each time the thunk is called.  Also changes
  to the thunks environment can effect its value when called.

 I think (2) would be best.  Because of:

 while $a  $b { ... }

 That wouldn't be possible with just evaluating it once.  I like the
 interface better, too (for the writer of Cwhile), but that's just
 me.


I prefer 1).  When I posted the original thread I wanted to emulate the
effect of $a  $b or ($a) ?? $b :: $c.  The parameters in these might get
evaluated zero or one times, but not more than once.  Having a side effect
happen more than once brings back painful memories of C-style macros.

Joe Gottman




Short-circuiting user-defined operators

2003-04-01 Thread Joe Gottman
   Is there any way to write a user-defined operator so that it
short-circuits, like  and || ?  This might be function trait, for
instance,

  sub infix:!! ($lhs, $rhs) is short_circuit {...}

Alternatively, there might be a new parameter type that indicates that the
parameter is not evaluated immediately:

sub infix:!! ($lsh, $rhs is deferred) {...}

   In this case, it might be possible to make ordinary functions
short-circuit also

sub conditional(bool $condition, $trueCase is deferred, $falseCase is
deferred)
{
return ($condition) ?? $trueCase :: $falseCase;
}

   I have no idea how difficult it would be to implement either of these
concepts.   Also, if a parameter is deferred, would we need a new keyword to
say when to actually evaluate it?

Joe Gottman




Re: is static?

2003-03-15 Thread Joe Gottman

- Original Message -
From: Dave Whipp [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, March 15, 2003 1:35 PM
Subject: Re: is static?


 Uri Guttman wrote:
  talking about nested subs brought up another related idea, static (not
  on the stack) lexicals inside subs.

 Doesn't Cour give you this?


   Not really.   A variable declared with our can be accessed from
anywhere in the program, just by redeclaring it or calling it with the
package:: syntax.A variable declared with my can be accessed outside
its scope only if the user returns a reference to it.  A static variable
should be like a my variable except that it is only initialized once and
is not destroyed when it goes out of scope.

Joe Gottman




Re: A6: overloading multis on constness of parameters

2003-03-12 Thread Joe Gottman

- Original Message -
From: Damian Conway [EMAIL PROTECTED]
To: Perl6 [EMAIL PROTECTED]
Sent: Tuesday, March 11, 2003 9:35 PM
Subject: Re: A6: overloading multis on constness of parameters


 Joe Gottman wrote:

 Will it be possible in perl6 to overload multis on the const-ness of
a
  parameter, like C++ does?  For instance,
 
 multi getX(Foo $self:) returns Int {...} #const version
 multi getX(Foo $self: is rw) returns Int is rw {...} #non-const
version

 That second one would have to be:

   multi getX(Foo $self is rw:) returns Int is rw {...}


 Then we have the issue that Perl 6 objects can't really be constant,
 since Cis constant is a compile-time trait of *containers*...really just
 a don't assign to this container marker.

 However, within those limitations, I guess it's possible. After all, we
have
 to check for lvaluability of Cis rw parameters anyway.

   How would I take a get a reference to the second one?  I assume I could
get a reference to the first by

   $ref = getX(Foo);

Joe Gottman




A6: overloading multis on constness of parameters

2003-03-11 Thread Joe Gottman
   Will it be possible in perl6 to overload multis on the const-ness of a
parameter, like C++ does?  For instance,

   multi getX(Foo $self:) returns Int {...} #const version
   multi getX(Foo $self: is rw) returns Int is rw {...} #non-const version

   If getX were called on a const Foo object then the first getX would be
called, and if it were called on a non-const Foo object the second one would
be.

Joe Gottman




Re: my int( 1..31 ) $var ?

2003-01-03 Thread Joe Gottman


 - Original Message -
 From: Mr. Nobody [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, January 03, 2003 1:58 PM
 Subject: Re: my int( 1..31 ) $var ?


  --- Smylers [EMAIL PROTECTED] wrote:
   Murat Ünalan wrote:
  
print date if $var is int( 1..31 );
  
   I don't think that the type needs to be specified here, especially if
   the variable has already been declared to be of the required type, so a
   junction should be sufficient:
  
 print date if $var == any(1 .. 31);
  
   Smylers
 
  Superpositions in the core? You're kidding, right?
 
  What's wrong with if 1 = $var = 31?
 



 For one thing they're not equivalent.

 my $var = 2.5;
 print date if $var == any(1..31);
 print in interval if 1 = $var = 31;

  Speaking of which, is there a run-time test to check if a variable is of
 integral type?  Something like

 print date if ($var is int)  (1 = $var = 31);


 Joe Gottman






Re: my int( 1..31 ) $var ?

2003-01-03 Thread Joe Gottman

- Original Message -
From: Uri Guttman [EMAIL PROTECTED]
To: Joe Gottman [EMAIL PROTECTED]
Cc: Perl6 [EMAIL PROTECTED]
Sent: Friday, January 03, 2003 10:06 PM
Subject: Re: my int( 1..31 ) $var ?


  JG == Joe Gottman [EMAIL PROTECTED] writes:

   JG   Speaking of which, is there a run-time test to check if a variable
is of
   JG  integral type?  Something like

   JG  print date if ($var is int)  (1 = $var = 31);

 the old standby is:

 int( $var ) == $var


   I'm not sure if this works.

my $var = 0;  # Notice the quotation marks
print is integer if (int($var) == $var);

In the above case int($var) == $var returns true when I would want it to
return false.

Joe Gottman





Re: This week's summary

2002-11-27 Thread Joe Gottman
   There's something wrong with your links to the messages in the
documentation list.  Whenever I click on one, I get the message Unable to
find thread.  Please recheck the URL.

Joe Gottman





Re: exegesis 5 question: matching negative, multi-byte strings

2002-10-02 Thread Joe Gottman



 On 1 Oct 2002 at 18:47, [EMAIL PROTECTED] wrote:

all text up to, but not including the string union.

How about (Perl6)

  /(.*?) union {$pos -= length('union');}/

   This gets everything up to and including the first instance of 'union',
then gets rid of the bit at the end that we don't want.  The capturing
parentheses ensure that we return the part of the string we want, and we
manually reset $pos to the correct position.  This is easy to understand,
and very extensible.

Joe Gottman





Fw: perl6 operator precedence table

2002-09-26 Thread Joe Gottman



Apocalypse 4 mentions unary '?' . Since this is used to force boolean
 context, I would assume that it has the same precedence as unary '+' and
 '_' which force numeric and string context respectively.  By the way, has
 anyone come up with a use for binary '?' yet?

 Joe Gottman

 - Original Message -
 From: John Williams [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, September 26, 2002 8:03 PM
 Subject: perl6 operator precedence table


  I'm trying to write a revised operator precedence table for perl6,
  similar to the one in perlop.pod.
 
  This is what I have come up with based on Apocalypse 3 and Exegesis 3.
  Does anyone have comments?  I'm not sure if the precedence
  for : (adverb) or 'is' and 'but' are quite right.
 
 
  perl6 operator precedence
 
 leftterms and list operators (leftward) [] {} ()
quotes
 left. and unary .
 nonassoc++ --
 leftis but
 right   **
 right   ! \ and unary ~ + - * _
 left=~ !~
 left* / % x
 left+ - _
 left 
 right   named unary operators, -X
 left  = = lt gt le ge == != = eq ne cmp
 left
 left| ~
 left
 left|| ~~ //
 nonassoc..  ...
 right   ??::
 right   = := **= += -= _= *= /= %= x= = |= ~=
  = = = ||= ~~= //=
 left, =
 left;
 left:
 nonassoclist operators (rightward)
 right   not
 leftand
 leftor xor err
 
  Here is a list of changes from perl5:
  . becomes _
  - becomes .
  == etc unified with  etc, and given left associativity
  binary ^ becomes ~
  ?: becomes ??::
  added ~~ // err
  added ; with lower precedence than ,
  added unary * and _ with same precedence as unary + -
  added binary :=
  added unary . with same precedence as binary .
  ( .foo === $self.foo )
  added : (adverb operator) with low precedence(?)
  print foo: $x, $y, $z; # lower than ,
  my $fh = open $filepath : mode='rw'; # lower than =
  added 'is' and 'but' with high precedence(?)
  my $thing is constant = 3 but false; # higher than =
 
  Larry mentions that other precedence unifications are possible.  I can
see
  the following as possibilites.  Are there others?
   with 
  | with ||
with * /
 
 
  ~ John Williams
 






Questions about private variables

2002-04-05 Thread Joe Gottman


   I just read Exegesis 4, and I have a few questions about private
variables.  First, is it possible to have 2 private variables of the same
name in different functions?  For instance, what would happen in the
following code?


sub func1() {
our $varname is private \\= 1;
return $varname;
}

sub func2() {
our $varname is private \\= 2;
 return varname;
}

print func1();
print func2();


Second, in the above code, the \\= operator is used to initialize the
private variable.  This allows it to be initialized the first time the
function is called, but prevents it from being reinitialized subsequent
times as long as the variable never becomes undefined.  But what if the
variable can become undefined?  In that case, the next time you call the
function the variable will be reinitialized, whether you want it to or not.

   Both of these show that private variables in Perl6 do not quite replace
C or C++ static variables.  It would be nice if there was some way to do
something like this:

my $foo is static = 3;

so that $foo acts like a C++ static variable, i.e. its value always persists
between calls to the function containing it, and the initialization code is
performed only once.  Unfortunately, I have no idea how  this would be
implemented in Perl 6.

Joe Gottman