Junctive and Higher order Types

2005-05-19 Thread Sam Vilain
Hi all, While trying to convert Haskell statements like this to Perl 6: data Cxt = CxtVoid -- ^ Context that isn't expecting any values | CxtItem !Type -- ^ Context expecting a value of the specified type | CxtSlurpy !Type -- ^ Context expecting multiple values of the

Re: reduce metaoperator on an empty list

2005-05-19 Thread Andrew Rodland
On Thursday 19 May 2005 10:51 pm, Sam Vilain wrote: > Edward Cherlin wrote: > > Here is the last answer from Ken Iverson, who invented reduce in > > the 1950s, and died recently. > > file:///usr/share/j504/system/extras/help/dictionary/intro28.htm > >[snip] > > Thanks for bringing in a little h

Re: [S29] uniq

2005-05-19 Thread Sam Vilain
Mark Overmeer wrote: 'uniq' differs from 'sort' because there is no order relationship between the elements. A quick algorithm for finding the unique elements in perl5 is sub uniq(@) { my %h = map { ($_ => 1) } @elements; keys %h; } ...and an even quicker one is: use Set::Object;

Re: [S29] uniq

2005-05-19 Thread Damian Conway
Luke wrote: I wondered what uniq's default comparator should be, =:=? &infix:<~~> Woah there. ~~ is a good comparator and all, but it's not the right one here. ~~ compares an object and a pattern to see if they match. That makes it the right choice for when and grep. But we're trying to remov

Re: Complex Arithmetic

2005-05-19 Thread Sam Vilain
Edward Cherlin wrote: There was a discussion of the principal value of square root on this list some time back, making the point that for positive [...] It turns out that the domain and range and the location of the cut lines have to be worked out separately for different functions. Mathemat

Re: reduce metaoperator on an empty list

2005-05-19 Thread Sam Vilain
Stuart Cook wrote: In Haskell, there is a distinction between foldl and foldl1 (similar remarks apply to foldr/foldr1[1]): The former (foldl) requires you to give an explicit 'left unit'[2], which is implicitly added to the left of the list being reduced. This means that folding an empty list will

Re: Argument Type Checking

2005-05-19 Thread Luke Palmer
On 5/19/05, Joshua Gatcomb <[EMAIL PROTECTED]> wrote: > All: > I was hoping the following would give me an outright error > > sub foo (Int $bar) { > say $bar; > } > foo('hello'); Fortunately you are right. > I seem to recall, probably incorrectly, that one of the differences > with int, Int,

Re: reduce metaoperator on an empty list

2005-05-19 Thread Sam Vilain
Edward Cherlin wrote: Here is the last answer from Ken Iverson, who invented reduce in the 1950s, and died recently. file:///usr/share/j504/system/extras/help/dictionary/intro28.htm [snip] Thanks for bringing in a little history to the discussion. Those links are all local to your system; do yo

Re: How do I... create a new meta operator?

2005-05-19 Thread Luke Palmer
On 5/19/05, Ingo Blechschmidt <[EMAIL PROTECTED]> wrote: > Hi, > > quoting A12: > > infix_postfix_meta_operator:<=> $x += 2; > > postfix_prefix_meta_operator:{'»'} @array »++ > > prefix_postfix_meta_operator:{'«'} -« @magnitudes > > infix_circumfix_meta_operator:{'»','«

Re: [S29] uniq

2005-05-19 Thread Luke Palmer
On 5/19/05, Damian Conway <[EMAIL PROTECTED]> wrote: > Ingo Blechschmidt wrote: > > I wondered what uniq's default comparator should be, =:=? > > &infix:<~~> Woah there. ~~ is a good comparator and all, but it's not the right one here. ~~ compares an object and a pattern to see if they match.

Re: [S29] uniq

2005-05-19 Thread Rod Adams
Damian Conway wrote: BTW, I am *sorely* tempted to suggest the following implementation instead: which would produce: uniq ; # uniq { lc } ; # 'a'|'A', 'b', 'C'|'c', 'd' uniq { abs $^value } 42, 23, -23, 23, 42;# 42, 23|-23 But I'd

Re: How do I... invoke a method reference

2005-05-19 Thread C. Scott Ananian
On Thu, 19 May 2005, Juerd wrote: Ingo Blechschmidt skribis 2005-05-19 22:45 (+0200): class Foo { method bar() { 42 } method baz() { &bar } } my $ref = Foo.baz; My guess: Foo.$ref $object.$ref Just like in Perl 5. I think Ingo was trying to explicitly specify the normally-implic

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Damian Conway wrote: > BTW, I am *sorely* tempted to suggest the following implementation > instead: [...] > which would produce: > > uniq ; # > > uniq { lc } ; # 'a'|'A', 'b', > 'C'|'c', 'd' > > uniq { abs $^value } 42, 23, -23,

Re: [S29] uniq

2005-05-19 Thread Damian Conway
Ingo Blechschmidt wrote: Is it intentional that there's no uniq in the current S29[1] draft? See [2] for Damian saying that uniq is probably in. It still probably is. I wondered what uniq's default comparator should be, =:=? &infix:<~~> Should it be possible to give an own comparator block, simil

Re: How do I... invoke a method reference

2005-05-19 Thread Juerd
Ingo Blechschmidt skribis 2005-05-19 22:45 (+0200): > class Foo { > method bar() { 42 } > method baz() { &bar } > } > my $ref = Foo.baz; My guess: Foo.$ref $object.$ref Just like in Perl 5. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_ju

Re: (1,(2,3),4)[2]

2005-05-19 Thread Juerd
"TSa (Thomas Sandlaß)" skribis 2005-05-19 21:06 (+0200): > >The above is more commonly written as > > > >my @b = ([1,2,[3,4]); > Assuming you meant @b = ([1,2,[3,4]]) what do the parens accomplish > here? Thanks for the correction. That is indeed what I meant. The parens do absolutely nothin

How do I... invoke a method reference

2005-05-19 Thread Ingo Blechschmidt
Hi, class Foo { method bar() { 42 } method baz() { &bar } } my $ref = Foo.baz; $ref(); # Don't think this will work # (Error: No invocant specified or somesuch) $ref(Foo.new); # But will this work? How do I specify multiple invocants (when dealing wit

How do I... create a new meta operator?

2005-05-19 Thread Ingo Blechschmidt
Hi, quoting A12: > infix_postfix_meta_operator:<=> $x += 2; > postfix_prefix_meta_operator:{'Â'} @array Â++ > prefix_postfix_meta_operator:{'Â'} -Â @magnitudes > infix_circumfix_meta_operator:{'Â','Â'} @a Â+Â @b so will the following work? # Silly example sub in

Re: [S29] uniq

2005-05-19 Thread Adriano Ferreira
On 5/19/05, Ingo Blechschmidt <[EMAIL PROTECTED]> wrote: > I read this as that uniq should behave like Unix's uniq(1), i.e. > removing only successive duplicates, e.g.: > uniq [3,3,3,4,3] => [3,4,3] # what I meant > uniq [3,3,3,4,3] => [3,4] # what you meant That has been discussed

Re: [S29] uniq

2005-05-19 Thread Juerd
Ingo Blechschmidt skribis 2005-05-19 21:07 (+0200): > I read this as that uniq should behave like Unix's uniq(1), i.e. > removing only successive duplicates, e.g.: > uniq [3,3,3,4,3] => [3,4,3] # what I meant > uniq [3,3,3,4,3] => [3,4] # what you meant Which leads to lots of |so

Re: hyperoperators and multi-dimensional datastructures

2005-05-19 Thread Uri Guttman
> "LP" == Luke Palmer <[EMAIL PROTECTED]> writes: LP> On 5/18/05, Anthony Heading <[EMAIL PROTECTED]> wrote: >> Is there a way to target hyperoperators at different axes of a >> multi-dimensional array? This is an attractive feature of >> various APL-like languages, viz. e.g. in J:

Argument Type Checking

2005-05-19 Thread Joshua Gatcomb
All: I was hoping the following would give me an outright error sub foo (Int $bar) { say $bar; } foo('hello'); I seem to recall, probably incorrectly, that one of the differences with int, Int, and no type declaration at all is that one would happily autoconvert for you, 1 would autoconvert b

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Adriano Ferreira wrote: > quoting Damian's original mail[1]: >> uniq - remove duplicates without reordering > ^^ > > Would not that mean the original order of the first ocurrence is > preserved? This is what Ruby Array#uniq does: > > [4,1

Re: (1,(2,3),4)[2]

2005-05-19 Thread TSa (Thomas Sandlaß)
Juerd wrote: Parens and square brackets are very different things. I know. The parens relevant here are the ones for precedence overrides. And Comma is pretty low, so it almost always needs parens around it to form lists. In particular it is below = and friends. The above is more commonly written

Re: [S29] uniq

2005-05-19 Thread Adriano Ferreira
The former implementation can be shortened: sub uniq { my %h; return grep { ! $h{$_}++ } @_; } But realize that none of the proposed solutions (which are based on hashes for computing the return) is amenable to the extension Ingo called for with comparator blocks. Adriano.

Re: [S29] uniq

2005-05-19 Thread Adriano Ferreira
quoting Damian's original mail[1]: > uniq - remove duplicates without reordering ^^ Would not that mean the original order of the first ocurrence is preserved? This is what Ruby Array#uniq does: [4,1,2,4,2,3,5].uniq => [ 4, 1, 2, 3, 5] The b

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Mark Overmeer wrote: > * Ingo Blechschmidt ([EMAIL PROTECTED]) [050519 16:52]: >> Should it be possible to give an own comparator block, similar as >> with grep? E.g. >> uniq ; # >> >> uniq:{ abs $^a == abs $^b } 42, 23, -23, 23, 42 >> # 42, 23, 42 > > 'uniq' d

Re: Syntax for specifying role parameters

2005-05-19 Thread Miroslav Silovic
[EMAIL PROTECTED] wrote: I don't think that a role has a long and a short name. This is because they aren't subject to MMD. I think of them more as beeing expanded like C++ templates even though the actual mechanism will be much more sophisticated. Actually I think of them as F-bounds as well ;) Uh

Re: [S29] uniq

2005-05-19 Thread Mark Overmeer
* Ingo Blechschmidt ([EMAIL PROTECTED]) [050519 16:52]: > Should it be possible to give an own comparator block, similar as with > grep? E.g. > uniq ; # > > uniq:{ abs $^a == abs $^b } 42, 23, -23, 23, 42 > # 42, 23, 42 'uniq' differs from 'sort' because there is no

s/.../{ $junction }/

2005-05-19 Thread Ingo Blechschmidt
Hi, while writing a preliminary p6explain, I wondered if the following should work: my $text = "aBc"; $text ~~ s/B/{ "C"|"D" }/; say $text.values; # aCc aDc This would be extremely handy for p6explain, as I'm currently parsing a datafile which looks like... + Standard mathematical inf

Re: Syntax for specifying role parameters

2005-05-19 Thread TSa (Thomas Sandlaß)
Miroslav Silovic wrote: Uhm, but C++ templates are subject to (compile-time) MMD, once you specialise them. In other words, role Something[Int $num] {...} role Something[String $num] {...} Hmm, C++ has no free floating templates. They always template a class/struct or a function. The Perl6 equiva

Re: hyperoperators and multi-dimensional datastructures

2005-05-19 Thread Luke Palmer
On 5/18/05, Anthony Heading <[EMAIL PROTECTED]> wrote: > Is there a way to target hyperoperators at different axes of a > multi-dimensional array? This is an attractive feature of > various APL-like languages, viz. e.g. in J: > > a =. 2 5 $ i. 7 - a simple 2-by-5 array > a > 0 1 2 3

Re: Complex Arithmetic

2005-05-19 Thread Luke Palmer
On 5/19/05, Edward Cherlin <[EMAIL PROTECTED]> wrote: > It turns out that the domain and range and the location of the > cut lines have to be worked out separately for different > functions. Mathematical practice is not entirely consistent in > making these decisions, but in programming, there seem

Re: ./method

2005-05-19 Thread Carl Franks
On 5/19/05, Martin Kuehl <[EMAIL PROTECTED]> wrote: > I have tried, but I can't make myself like it. I'm afraid I have to agree. When I saw it used in code after this discussion (I think it must have been somewhere in pugs t/ or ext/) my reaction was "yuck". (for what it's worth) Carl

Re: [S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, Rod Adams wrote: >>I wondered what uniq's default comparator should be, =:=? > I'd have gone with ~~ Even better. :) --Ingo -- Linux, the choice of a GNU | Row, row, row your bits, gently down the generation on a dual AMD | stream... Athlon!|

Re: Syntax for specifying role parameters

2005-05-19 Thread TSa (Thomas Sandlaß)
Ingo Blechschmidt wrote: I meant: The colon should still act as the delimiter between the params which account to the long name of the role and those which don't, but otherwise the syntax should be the same as the standard subroutine signature syntax, allowing optional params, etc. I don't think th

Re: [S29] uniq

2005-05-19 Thread Rod Adams
Ingo Blechschmidt wrote: Hi, three quick questions: Since Aaron is still getting up to speed, I'll take a stab at these. Is it intentional that there's no uniq in the current S29[1] draft? See [2] for Damian saying that uniq is probably in. Just hasn't been entered. I wondered what uniq's def

[S29] uniq

2005-05-19 Thread Ingo Blechschmidt
Hi, three quick questions: Is it intentional that there's no uniq in the current S29[1] draft? See [2] for Damian saying that uniq is probably in. I wondered what uniq's default comparator should be, =:=? Should it be possible to give an own comparator block, similar as with grep? E.g. uniq ;

Re: reduce metaoperator on an empty list

2005-05-19 Thread C. Scott Ananian
On Wed, 18 May 2005, Rob Kinyon wrote: On 5/18/05, Stuart Cook <[EMAIL PROTECTED]> wrote: To summarise what I think everyone is saying, []-reducing an empty list yields either: 1) undef (which may or may not contain an exception), or 2) some unit/identity value that is a trait of the operator, depe

Re: Syntax for specifying role parameters

2005-05-19 Thread Ingo Blechschmidt
Hi, "TSa (Thomas SandlaÃ)" wrote: > you wrote: >> I wondered if it would be useful/good/nice if the syntax for >> specifying role parameters would be the same as the standard >> subroutine signature syntax (minus the colon, which >> separates the parameters which do account to the long name >> of

Re: Syntax for specifying role parameters

2005-05-19 Thread TSa (Thomas Sandlaß)
HaloO Ingo, you wrote: I wondered if it would be useful/good/nice if the syntax for specifying role parameters would be the same as the standard subroutine signature syntax (minus the colon, which separates the parameters which do account to the long name of the role from the ones which don't).

Re: ./method

2005-05-19 Thread Martin Kuehl
On 5/15/05, Juerd <[EMAIL PROTECTED]> wrote: > A few days ago, when typing ./pugs,... You can guess the rest :) > > I suggest > > ./method > > to mean $?SELF.method, and > > ../method > > to mean $?SELF.SUPER::method, or however that's normally written. > > This syntax doesn't clash w

Syntax for specifying role parameters

2005-05-19 Thread Ingo Blechschmidt
Hi, I wondered if it would be useful/good/nice if the syntax for specifying role parameters would be the same as the standard subroutine signature syntax (minus the colon, which separates the parameters which do account to the long name of the role from the ones which don't). E.g.: rol

Re: reduce metaoperator on an empty list

2005-05-19 Thread TSa (Thomas Sandlaß)
Michele Dondi wrote: On Wed, 18 May 2005, Rob Kinyon wrote: 1) undef (which may or may not contain an exception), or 2) some unit/identity value that is a trait of the operator, I think that the unit/identity/neutral value is a trait of the operator *and* the type of the values which are expected f

Re: reduce metaoperator on an empty list

2005-05-19 Thread Edward Cherlin
On Wednesday 18 May 2005 17:57, Matt Fowles wrote: > All~ > > What does the reduce metaoperator do with an empty list? Here is the last answer from Ken Iverson, who invented reduce in the 1950s, and died recently. file:///usr/share/j504/system/extras/help/dictionary/intro28.htm Identity Functions

Complex Arithmetic

2005-05-19 Thread Edward Cherlin
There was a discussion of the principal value of square root on this list some time back, making the point that for positive real numbers the positive square root is the value of the standard function. In the complex plane it is desirable to define the principal value at every point so as to pr

Re: reduce metaoperator on an empty list

2005-05-19 Thread Michele Dondi
On Wed, 18 May 2005, Rob Kinyon wrote: 1) undef (which may or may not contain an exception), or 2) some unit/identity value that is a trait of the operator, depending on whether or not people think (2) is actually a good idea. I would think that the Principle of Least Surprise points to (1), I don'

Re: reduce metaoperator on an empty list

2005-05-19 Thread Michele Dondi
On Wed, 18 May 2005, Matt Fowles wrote: All~ What does the reduce metaoperator do with an empty list? Interesting. Mathematically an empty sum is zero and an empty product is one. Maybe each operator {c,s}hould have an associated method returning its neutral element for [] to use it on empty list

Re: reduce metaoperator

2005-05-19 Thread Edward Cherlin
On Sat, May 07, 2005 at 01>00>08PM -0700, Larry Wall wrote: > On the other hand, since we've distinguished hyperops on > infixes from hyperops on unaries, maybe an infix hyperop in > unary position just does the thing to itself: > > @squares = Â*Â @list; > > which gives us a sum-of-squares tha

hyperoperators and multi-dimensional datastructures

2005-05-19 Thread Anthony Heading
Is there a way to target hyperoperators at different axes of a multi-dimensional array? This is an attractive feature of various APL-like languages, viz. e.g. in J: a =. 2 5 $ i. 7 - a simple 2-by-5 array a 0 1 2 3 4 - like this 5 6 0 1 2 +/"1 a - sum reduc