Re: skippable arguments in for loops

2005-10-16 Thread Nicholas Clark
On Thu, Sep 29, 2005 at 09:21:40AM -0700, Dave Whipp wrote:
 Luke Palmer wrote:
 
 Joked?  Every other language that has pattern matching signatures that
 I know of (that is, ML family and Prolog) uses _.  Why should we break
 that?  IMO, it's immediately obvious what it means.
 
 Something tells me that in signature unification, undef means this
 has to be undef, much like 1 means this has to be 1.
 
 In Perl6 we currently have at least tw oways to say don't care: In a 
 regex, we say /./ to match anything; in a type signature, we use Any 
 to mean that we don't care what the type is. I don't think we need 
 another way to say don't care. In fact, we could unify things:
 
   rules: /Any/ matches anything (/./ is shorthand synonym)

Is that strictly correct? /./ doesn't match an empty string.

Or did I miss some context earlier in the thread?

Nicholas Clark


Re: skippable arguments in for loops

2005-09-29 Thread Dave Whipp

Luke Palmer wrote:


Joked?  Every other language that has pattern matching signatures that
I know of (that is, ML family and Prolog) uses _.  Why should we break
that?  IMO, it's immediately obvious what it means.

Something tells me that in signature unification, undef means this
has to be undef, much like 1 means this has to be 1.


In Perl6 we currently have at least tw oways to say don't care: In a 
regex, we say /./ to match anything; in a type signature, we use Any 
to mean that we don't care what the type is. I don't think we need 
another way to say don't care. In fact, we could unify things:


  rules: /Any/ matches anything (/./ is shorthand synonym)
  binding: ($a, Any, $b) := (1,2,3);

I'll admit that Any doesn't immediately shout skip, but it would 
really be the fact that there's no variable associated with it that 
means skip, If we'd wanted to skip an integer, we could say:


  ($a, Int, $b) := (1,2,3);

Why would Perl need to add _ as a synonym for Any? It's only a 
couple of characters shorter! The argument for /./ being a synonym in 
rexen is easier to make: it's common, it's legacy, and it's 4 chars shorter.


Re: skippable arguments in for loops

2005-09-23 Thread Carl Mäsak
I'm not sure we've reached consensus here, so I will try to summarize
what everyone said so far in order to clear my own head a bit. :)
Sorry in advance if i horribly misrepresent anyone's opinions.

Luke: Thinks the _ syntax is no joke, since every language with
pattern matching abilities has it. Further, using undef won't work
because it means this has to be undef in signature unification.

Dks: Replies to Luke. Thinks that undef is more perl5ish, and that
_ can disappear too easily, and is too Huffmanized. Doesn't think
_ is obvious, but is sure we will end up using it if this feature is
added.

TSa: Prefers to rely on lazy evaluation, and says both tounge-in-cheek
and philosophically that if I don't want to care about some elements,
I should do so, and let Perl6 optimize. Proposes several ways of not
giving a name to a variable.

Yuval Kogman: Replies to David. Seems to repeat Luke's point about
value binding in signatures. Shows an example of value binding in
action. Argues for the _ or __ syntax. Thinks that making this
feature easy encourages reuse of calling code, not only callee code.

So, in summary, it's not obvious that this feature is needed at all
because things can be optimized away. Also, neither the undef nor
the _ syntax have 100% support, and undef seems to have problems
related to signature unification.

Hm. For the time being I will assume that this functionality is not
sufficiently wanted to deserve its own syntax. But I must admit I'm
actually starting to like _ in subroutine signatures... not sure if
it works well with positionals and the like, however.

// Carl


Re: skippable arguments in for loops

2005-09-23 Thread TSa

HaloO Carl,

you wrote:

TSa: Prefers to rely on lazy evaluation, and says both tounge-in-cheek
and philosophically that if I don't want to care about some elements,
I should do so, and let Perl6 optimize. Proposes several ways of not
giving a name to a variable.


This hits home. And I did at no point impute carelessness on your part
---unless of course if you don't want to, err? ... care!
Sorry, couldn't resist ;)



Hm. For the time being I will assume that this functionality is not
sufficiently wanted to deserve its own syntax. But I must admit I'm
actually starting to like _ in subroutine signatures... not sure if
it works well with positionals and the like, however.


And could easily give a type markup with sigils and get $_, _, @_ and %_ 
ignored. I here $Yoda speak funny that is :)

--
$TSa.greeting := HaloO; # mind the echo!


Re: skippable arguments in for loops

2005-09-22 Thread Luke Palmer
On 9/22/05, Carl Mäsak [EMAIL PROTECTED] wrote:
 FWIW, to me it looks fairly intuitive. undef here means don't alias
 the element, just throw it away... gaal joked about using _ instead
 of undef. :)

Joked?  Every other language that has pattern matching signatures that
I know of (that is, ML family and Prolog) uses _.  Why should we break
that?  IMO, it's immediately obvious what it means.

Something tells me that in signature unification, undef means this
has to be undef, much like 1 means this has to be 1.

Luke


Re: skippable arguments in for loops

2005-09-22 Thread David Storrs


On Sep 22, 2005, at 3:08 AM, Luke Palmer wrote:


On 9/22/05, Carl Mäsak [EMAIL PROTECTED] wrote:


FWIW, to me it looks fairly intuitive. undef here means don't alias
the element, just throw it away... gaal joked about using _ instead
of undef. :)



Joked?  Every other language that has pattern matching signatures that
I know of (that is, ML family and Prolog) uses _.  Why should we break
that?


Because the way Carl has it is more consistent with Perl 5, from  
whence most of our users will be coming?  Because 'undef' has a nice  
visual weight, while '_' can all too easily disappear?  Because  
throwing away values is something that we probably shouldn't make too  
easy?



IMO, it's immediately obvious what it means.


Not IMO.  _ in this context is content-free for me.

But, whatever.  I'm sure it will end up being _ if this feature is  
added.


--Dks

Re: skippable arguments in for loops

2005-09-22 Thread TSa

HaloO,

Carl Mäsak wrote:

But what if I don't care about the elements 1,4,7? Would the following
be a sane syntax?

my @a = 1..9;
for @a - undef, $x, $y { say $x }


I think that, if the concept of lazy list evaluation is running
deep in Perl 6 than the obvious solution to me is:

  for @a - $x, $y, $z { say $y }

and $x and $z are never evaluated. Other ways that come to my mind
are:

  for @a -  $,$y,$ { say $y }
  for @a -  (,$y,) { say $y }
  for @a -   ,$y,  { say $y }  # same? unparseable?

All the above depend on really lazy lists that somehow hook onto
what they are susposed to contain in a very lightweight, shallow
fashion. And it must be possible to iterate lists in several
modes. Here this would be (:skip,:fetch,:skip) or whatever the
syntax could be.

Or in a non-native-attempt-to-sound-funny-with-deep-philosophical-meaning
way I would say: If Carl doesn't want to care about the first and last
item of the three element list, he should do so! And Perl6 cares for his
carelessness not beeing punished with a performance penalty. :)

Here's a lengthy version that also comes to my mind:

  for @a - @three is shape(Void,Item,Void)  { say @three[1] }

if this is not how the shape trait works s/shape/tuple/.
Actually, it could as well just be @three:(Void,Item,Void).
Hmm, or with typing the topic:

  for @a - $_:(Void,Item,Void) { say }
--
$TSa.greeting := HaloO; # mind the echo!



Re: skippable arguments in for loops

2005-09-22 Thread Yuval Kogman
On Thu, Sep 22, 2005 at 07:23:06 -0400, David Storrs wrote:
 
 On Sep 22, 2005, at 3:08 AM, Luke Palmer wrote:
 
 On 9/22/05, Carl Mäsak [EMAIL PROTECTED] wrote:
 FWIW, to me it looks fairly intuitive. undef here means don't alias
 the element, just throw it away... gaal joked about using _ instead
 of undef. :)
 Joked?  Every other language that has pattern matching signatures that
 I know of (that is, ML family and Prolog) uses _.  Why should we break
 that?
 

 Because the way Carl has it is more consistent with Perl 5, from
 whence most of our users will be coming?

But not with MMD pattern matching stuff, since you are now allowed
to declare that a body behaves a certain way when receiving certain
values.. For example

multi factorial (0) { 1 }
multi factorial ($n) { $n * factorial($n -1) }

I find this approach much more intuitive than special casing the
behavior of certain values when they are used inside prototypes.

 Because 'undef' has a nice  visual weight, while '_' can all too
 easily disappear?

sub foo ($x, _, $y) { # i feel this has a big enough weigh
sub foo ($x, __, $y) { # even better

 Because  throwing away values is something that we probably
 shouldn't make too  easy?

It should be made very easy - this encourages reuse of calling code,
not only callee code.

-- 
 ()  Yuval Kogman [EMAIL PROTECTED] 0xEBD27418  perl hacker 
 /\  kung foo master: *shu*rik*en*sh*u*rik*en*s*hur*i*ke*n*: neeyah



pgp4rntfFfYIk.pgp
Description: PGP signature