Re: reduce metaoperator on an empty list

2005-06-17 Thread TSa (Thomas Sandlaß)
Damian Conway wrote: Let's assume that op is overloaded for two completely unrelated types A and B, which are both defining their respective identity elements but !(A.identval =:= B.identval). How should the &op multi method object pick the correct one *without* looking at $value's type? Your

Re: reduce metaoperator on an empty list

2005-06-16 Thread Edward Cherlin
On Thursday 09 June 2005 12:21, John Macdonald wrote: > On Thu, Jun 09, 2005 at 06:41:55PM +0200, "TSa (Thomas Sandla �" wrote: > > Edward Cherlin wrote: > > >That means that we have to straighten out the functions > > > that can return either a Boolean or an item of the > > > argument type. Compar

Re: reduce metaoperator on an empty list

2005-06-09 Thread Sam Vilain
TSa (Thomas Sandlaß) wrote: I'm not sure but Perl6 could do better or at least trickier ;) Let's assume that < > <= >= when chained return an accumulated boolean and the least or greatest value where the condition was true. E.g. 0 < 2 < 3 returns 0 but true 1 < 2 < 1 returns 1 but false

Re: reduce metaoperator on an empty list

2005-06-09 Thread Damian Conway
Edward Cherlin wrote: You haven't convinced me, but rather than flog a dead horse, I'll just suggest that we both reserve the right to say "I told you so" when there are several years' worth of Perl 6 code out there, and we see how common our respective examples are. No need to wait. There is

Re: reduce metaoperator on an empty list

2005-06-09 Thread Damian Conway
TSa (Thomas Sandlaß) wrote: Let's assume that op is overloaded for two completely unrelated types A and B, which are both defining their respective identity elements but !(A.identval =:= B.identval). How should the &op multi method object pick the correct one *without* looking at $value's type?

Re: reduce metaoperator on an empty list

2005-06-09 Thread John Macdonald
On Thu, Jun 09, 2005 at 06:41:55PM +0200, "TSa (Thomas Sandlaß)" wrote: > Edward Cherlin wrote: > >That means that we have to straighten out the functions that can > >return either a Boolean or an item of the argument type. > >Comparison functions < > <= >= = != should return only Booleans, > >

Re: reduce metaoperator on an empty list

2005-06-09 Thread TSa (Thomas Sandlaß)
HaloO Larry, you wrote: : Might I add that it should read : : $var = (&op.does(identval) ?? : &op.identval($value) :: undef) op $value; : : The rational is, that &op is subject to MMD, so the .identval method : should be dispatched as well. Actually &op.identity($value) r

Re: reduce metaoperator on an empty list

2005-06-09 Thread TSa (Thomas Sandlaß)
Edward Cherlin wrote: That means that we have to straighten out the functions that can return either a Boolean or an item of the argument type. Comparison functions < > <= >= = != should return only Booleans, I'm not sure but Perl6 could do better or at least trickier ;) Let's assume that < >

Re: reduce metaoperator on an empty list

2005-06-09 Thread Edward Cherlin
On Tuesday 07 June 2005 22:35, Sam Vilain wrote: > Let's look at the type of one of the many `reduce' variants in > Haskell; > >foldr1 :: (a -> a -> a) -> [a] -> a > > This is the Perl6ish; > >sub reduce( ::Code{( ::(someType), ::(someType) ) returns > ::(someType)} $func, Array of ::(someT

Re: reduce metaoperator on an empty list

2005-06-08 Thread Edward Cherlin
On Tuesday 07 June 2005 08:08, Larry Wall wrote: > Okay, I've made up my mind.  The "err" option is not tenable > because it can cloak real exceptions, and having multiple > versions of reduce is simply multiplying entities without > adding much power.  So let's allow an optional "identvalue" > tra

Re: reduce metaoperator on an empty list

2005-06-08 Thread Edward Cherlin
On Wednesday 01 June 2005 17:18, Deborah Pickett wrote: > You haven't convinced me, but rather than flog a dead horse, > I'll just suggest that we both reserve the right to say "I > told you so" when there are several years' worth of Perl 6 > code out there, and we see how common our respective exa

Re: reduce metaoperator on an empty list

2005-06-08 Thread Larry Wall
On Tue, Jun 07, 2005 at 10:52:55PM +, Luke Palmer wrote: : Okay, I was referring more to the implementation. How do we tell apart: : : 3 < 4 <= 5 == 5 : : From : : 3 lt 4 >= 5 != 5 : : ? As long as the actual arguments aren't allowed to be lazy/thunky/iteratey, they can just be ev

Re: reduce metaoperator on an empty list

2005-06-08 Thread Larry Wall
On Wed, Jun 08, 2005 at 11:40:49AM +0200, "TSa (Thomas Sandlaß)" wrote: : Damian Conway wrote: : >So, to clarify again, if $var is undefined, then the assignment: : > : >$var op= $value; : > : >is equivalent to: : > : >$var = (&op.does(identval) ?? &op.identval() :: undef) op $value; : > :

Re: reduce metaoperator on an empty list

2005-06-08 Thread TSa (Thomas Sandlaß)
Damian Conway wrote: So, to clarify again, if $var is undefined, then the assignment: $var op= $value; is equivalent to: $var = (&op.does(identval) ?? &op.identval() :: undef) op $value; Correct? Might I add that it should read $var = (&op.does(identval) ?? &op.

Re: reduce metaoperator on an empty list

2005-06-08 Thread Damian Conway
Larry wrote: Okay, I've made up my mind. The "err" option is not tenable because it can cloak real exceptions, and having multiple versions of reduce is simply multiplying entities without adding much power. So let's allow an optional "identvalue" trait on operators. If it's there, reduce can

Re: reduce metaoperator on an empty list

2005-06-07 Thread Ph. Marek
On Tuesday 07 June 2005 23:41, Luke Palmer wrote: > On 6/7/05, Larry Wall <[EMAIL PROTECTED]> wrote: > > Okay, I've made up my mind. The "err" option is not tenable because > > it can cloak real exceptions, and having multiple versions of reduce is > > simply multiplying entities without adding mu

Re: reduce metaoperator on an empty list

2005-06-07 Thread Sam Vilain
Luke Palmer wrote: < and > still don't make sense as reduce operators. Observe the table: # of args | Return (type) 0 | -Inf 1 | Num (the argument) 2 | bool ... | bool Let's look at the type of one of the many `reduce' vari

Re: reduce metaoperator on an empty list

2005-06-07 Thread Luke Palmer
On 6/7/05, Larry Wall <[EMAIL PROTECTED]> wrote: > On Tue, Jun 07, 2005 at 09:41:49PM +, Luke Palmer wrote: > : < and > still don't make sense as reduce operators. > > Yeah, I keep confusing them with min and max. > > : That reminds me, how are <, >, etc. defined anyway? How can we tell > :

Re: reduce metaoperator on an empty list

2005-06-07 Thread Larry Wall
On Tue, Jun 07, 2005 at 09:41:49PM +, Luke Palmer wrote: : < and > still don't make sense as reduce operators. Yeah, I keep confusing them with min and max. : That reminds me, how are <, >, etc. defined anyway? How can we tell : them to be list-associative with each other? Because they're a

Re: reduce metaoperator on an empty list

2005-06-07 Thread Luke Palmer
On 6/7/05, Larry Wall <[EMAIL PROTECTED]> wrote: > Okay, I've made up my mind. The "err" option is not tenable because > it can cloak real exceptions, and having multiple versions of reduce is > simply multiplying entities without adding much power. So let's allow > an optional "identvalue" trait

Re: reduce metaoperator on an empty list

2005-06-07 Thread Larry Wall
Okay, I've made up my mind. The "err" option is not tenable because it can cloak real exceptions, and having multiple versions of reduce is simply multiplying entities without adding much power. So let's allow an optional "identvalue" trait on operators. If it's there, reduce can use it. If it'

Re: reduce metaoperator on an empty list

2005-06-06 Thread Rob Kinyon
On 6/6/05, Sam Vilain <[EMAIL PROTECTED]> wrote: > Roger Hale wrote: > > This is why I would rather the o -> [o] circumfixion left [o] an infix, > > not prefix operator. I would rather be explicit about my identity: > > $product = 1 [*] @array; > > Hmm. Not all operators *have* an identity.

Re: reduce metaoperator on an empty list

2005-06-06 Thread TSa (Thomas Sandlaß)
HaloO Roger, I'm answering here to your other mail as well. In my example I was intensionally changing from last to first and positive and negative numbers! This is a sublety of distance preserving, direction aware counting in multiples of arbitrary unity---or some such ;) you wrote: This is why

Re: reduce metaoperator on an empty list

2005-06-06 Thread Sam Vilain
Damian Conway wrote: What you want is: $product = ([*] @values err 0); Or: $factorial = ([*] 1..$n err 1); The "err" operator bind only to the point on the instruction it is attached to, ie it's not a shortcut for eval(), right? I'm just seeing some edge cases here for custom defined o

Re: reduce metaoperator on an empty list

2005-06-06 Thread Sam Vilain
Roger Hale wrote: This is why I would rather the o -> [o] circumfixion left [o] an infix, not prefix operator. I would rather be explicit about my identity: $product = 1 [*] @array; Hmm. Not all operators *have* an identity. You'd have to write, in that case; @array[0] [ƒ] @[EMAI

Re: reduce metaoperator on an empty list

2005-06-06 Thread Roger Hale
Damian Conway wrote: Deborah Pickett wrote: You are going to see empty lists more often than you think in expressions like $product = [*] @array; and having to write that as $product = [*] 1, @array; just to protect against a common case doesn't exactly flaunt Perl's DWIMmery to me. I *h

Re: reduce metaoperator on an empty list

2005-06-01 Thread Deborah Pickett
On Wed, 1 Jun 2005 19.37, Damian Conway wrote: > Deborah Pickett wrote: > > Someone please convince me otherwise. > So what you want is not an identity value as default (which isn't even > possible for many operators, as Luke pointed out), but a predictable > failure value as default, so you can in

Re: reduce metaoperator on an empty list

2005-06-01 Thread Rob Kinyon
> > $ordered = [<] @array; This is asking "Is @array ordered?" In the case of a 0-element or 1-element array, the answer is "It is not disordered", which means $ordered is true. $ordered = ! [!<] @array; Rob

Re: reduce metaoperator on an empty list

2005-06-01 Thread Dave Whipp
Luke Palmer wrote: For something like: $ordered = [<] @array; If @array is empty, is $ordered supposed to be true or false? It certainly shouldn't be anything but those two, because < is a boolean operator. I have no problem with 3-state logic systems (true, false, undef) if this is w

Re: reduce metaoperator on an empty list

2005-06-01 Thread Michele Dondi
On Wed, 1 Jun 2005, Luke Palmer wrote: I read that (mathematically) as "for all i, for all j such that j-i=1, a_i Yep, it sure is. Now tell Perl to read it that way for any operator. Should _I_?!? ;-) I wonder what a logic-oriented programming language a' la prolog would say in this case.

Re: reduce metaoperator on an empty list

2005-06-01 Thread BÁRTHÁZI András
Hi, You have to either supply an initial value or refactor your logic not to allow an empty @array (as in the first case). If you want it some other way, there are far too many special cases we have to work with, some of which are just mathematically impossible. I think `fail`ing is the best b

Re: reduce metaoperator on an empty list

2005-06-01 Thread Luke Palmer
On 6/1/05, Michele Dondi <[EMAIL PROTECTED]> wrote: > On Wed, 1 Jun 2005, Luke Palmer wrote: > > >$ordered = [<] @array; > > > > If @array is empty, is $ordered supposed to be true or false? It > > certainly shouldn't be anything but those two, because < is a boolean > > operator. > > I rea

Re: reduce metaoperator on an empty list

2005-06-01 Thread Michele Dondi
On Wed, 1 Jun 2005, Luke Palmer wrote: $ordered = [<] @array; If @array is empty, is $ordered supposed to be true or false? It certainly shouldn't be anything but those two, because < is a boolean operator. I read that (mathematically) as "for all i, for all j such that j-i=1, a_i Why sh

Re: reduce metaoperator on an empty list

2005-06-01 Thread Damian Conway
Deborah Pickett wrote: You are going to see empty lists more often than you think in expressions like $product = [*] @array; and having to write that as $product = [*] 1, @array; just to protect against a common case doesn't exactly flaunt Perl's DWIMmery to me. I *have* to write 1 there,

Re: reduce metaoperator on an empty list

2005-06-01 Thread Luke Palmer
On 6/1/05, Deborah Pickett <[EMAIL PROTECTED]> wrote: > I'm still in the camp of those wanting each operator to know its own identity > value (perhaps in terms of a trait). The identity of multiplication (say) is > always 1, after all, and it doesn't change depending on when you do > multiplicatio

Re: reduce metaoperator on an empty list

2005-06-01 Thread Deborah Pickett
On Wed, 1 Jun 2005 13.19, Joe Gottman wrote: > > 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

Re: reduce metaoperator on an empty list

2005-05-31 Thread Damian Conway
Joe Gottman pointed out: No. It returns empty string. You could think of C as being implemented: sub join (Str $sep, [EMAIL PROTECTED]) { reduce { $^a ~ $sep ~ $^b } "", @list } > If this were the case, then join '~', 'a', 'b', 'c' would equal '~a~b~c' instead of 'a~b~c'

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 specif

Re: reduce metaoperator on an empty list

2005-05-31 Thread Damian Conway
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

Re: reduce metaoperator on an empty list

2005-05-31 Thread Juerd
Damian Conway skribis 2005-06-01 10:44 (+1000): > 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? I dislik

Re: reduce metaoperator on an empty list

2005-05-31 Thread Rod Adams
Dave Whipp wrote: Damian Conway wrote: And what you'd need to write would be: $sum = (try{ [+] @values } err 0); The "err ..." idiom seems too useful to have it break in this case. Afterall, the purpose of "err 0" is to tell the stupid computer that I know what to do with the empty-

Re: reduce metaoperator on an empty list

2005-05-31 Thread Damian Conway
Dave Whipp wrote: Damian Conway wrote: And what you'd need to write would be: $sum = (try{ [+] @values } err 0); The "err ..." idiom seems too useful to have it break in this case. Afterall, the purpose of "err 0" is to tell the stupid computer that I know what to do with the empty-

Re: reduce metaoperator on an empty list

2005-05-31 Thread Dave Whipp
Damian Conway wrote: And what you'd need to write would be: $sum = (try{ [+] @values } err 0); The "err ..." idiom seems too useful to have it break in this case. Afterall, the purpose of "err 0" is to tell the stupid computer that I know what to do with the empty-array scenario. Feel

Re: reduce metaoperator on an empty list

2005-05-31 Thread Damian Conway
Dave Whipp wrote: Damian Conway wrote: 0 args: fail (i.e. thrown or unthrown exception depending on use fatal) ... $sum = ([+] @values err 0); $prod = ([*] @values err 1); $prob = ([*] @probs err 0); Just wanted to check, if I've said "use fatal": will that "err 0" D

Re: reduce metaoperator on an empty list

2005-05-31 Thread Dave Whipp
Damian Conway wrote: 0 args: fail (i.e. thrown or unthrown exception depending on use fatal) ... $sum = ([+] @values err 0); $prod = ([*] @values err 1); $prob = ([*] @probs err 0); Just wanted to check, if I've said "use fatal": will that "err 0" DWIM, or will the fatal

Re: reduce metaoperator on an empty list

2005-05-31 Thread Damian Conway
All this discussion of "identity" defaults for reductions has been very interesting and enlightening. But it seems to me that the simplest "correct" behaviour for reductions is: 2+ args: interpolate specified operator 1 arg: return that arg 0 args: fail (i.e. thrown or unthrown e

Re: reduce metaoperator on an empty list

2005-05-31 Thread Larry Wall
On Mon, May 23, 2005 at 08:54:19PM +, [EMAIL PROTECTED] wrote: : : There are actuall two usefull definition for %. The first which Ada calls 'mod' always returns a value 0<=X

Re: reduce metaoperator on an empty list

2005-05-24 Thread John Macdonald
On Fri, May 20, 2005 at 10:14:26PM +, [EMAIL PROTECTED] wrote: > > > Mark A. Biggar wrote: > > > Well the identity of % is +inf (also right side only). > > > > I read $n % any( $n..Inf ) == $n. The point is there's no > > unique right identity and thus (Num,%) disqualifies for a > > Monoid. B

Re: mod/div (was: reduce metaoperator on an empty list)

2005-05-23 Thread Mark Reed
I would really like to see ($x div $y) be (floor($x/$y)) and ($x mod $y) be ($x - $x div $y). If the divisor is positive the modulus should be positive, no matter what the sign of the dividend. Avoids lots of special case code across 0 boundaries. On 2005-05-23 18:49, "TSa (Thomas Sandlaß)" <[

mod/div (was: reduce metaoperator on an empty list)

2005-05-23 Thread TSa (Thomas Sandlaß)
[EMAIL PROTECTED] wrote: There are actuall two usefull definition for %. The first which Ada calls 'mod' always returns a value 0<=XSigned integer division and remainder are defined by the relation: A = (A/B)*B + (A rem B) where (A rem B) has the sign of A and an absolute value less than

Re: reduce metaoperator on an empty list

2005-05-23 Thread mark . a . biggar
There are actuall two usefull definition for %. The first which Ada calls 'mod' always returns a value 0<=X HaloO Mark, > > please don't regard the following as obtrusive. > > you wrote: > > If as usual the definition of a right identity value e is that a op e = a > > for > all a, > > then o

Re: reduce metaoperator on an empty list

2005-05-23 Thread TSa (Thomas Sandlaß)
HaloO Mark, please don't regard the following as obtrusive. you wrote: If as usual the definition of a right identity value e is that a op e = a for all a, then only +inf works. Besdies you example should have been; Or actually $n % any( abs($n)+1 .. Inf ) to really exclude 0 from the junct

Re: reduce metaoperator on an empty list

2005-05-21 Thread Edward Cherlin
On Friday 20 May 2005 08:11, "TSa (Thomas Sandlaß)" wrote: > John Macdonald wrote: > > ... (and there may be additional > > operator attributes that make sense there too, although none > > come immediately to mind). > > Well, I wonder why people neglect the fact that the > neutral/identity element

Re: reduce metaoperator on an empty list

2005-05-21 Thread Edward Cherlin
On Friday 20 May 2005 07:18, John Macdonald wrote: > Is there a built-in operator that doesn't have a meaningful > identity value? Certainly. > I first thought of exponentiation, but it has > an identity value of 1 - you just have to realize that since > it is a right associative operator, th

Re: reduce metaoperator on an empty list

2005-05-21 Thread Edward Cherlin
On Thursday 19 May 2005 20:42, Andrew Rodland wrote: > 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/

Re: reduce metaoperator on an empty list

2005-05-20 Thread Matt Fowles
Mark~ On 5/20/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Mark A. Biggar wrote: > > > Well the identity of % is +inf (also right side only). > > > > I read $n % any( $n..Inf ) == $n. The point is there's no > > unique right identity and thus (Num,%) disqualifies for a > > Monoid. BTW,

Re: reduce metaoperator on an empty list

2005-05-20 Thread mark . a . biggar
> Mark A. Biggar wrote: > > Well the identity of % is +inf (also right side only). > > I read $n % any( $n..Inf ) == $n. The point is there's no > unique right identity and thus (Num,%) disqualifies for a > Monoid. BTW, the above is a nice example where a junction > needn't be preserved :) If as

Re: [unclassified] Re: reduce metaoperator on an empty list

2005-05-20 Thread Edward Cherlin
On Thursday 19 May 2005 19:51, 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 http://www.jsoftware.com/books/help/dictionary/in

Re: reduce metaoperator on an empty list

2005-05-20 Thread TSa (Thomas Sandlaß)
Mark A. Biggar wrote: Well the identity of % is +inf (also right side only). I read $n % any( $n..Inf ) == $n. The point is there's no unique right identity and thus (Num,%) disqualifies for a Monoid. BTW, the above is a nice example where a junction needn't be preserved :) E.g. if XSorry, is it t

Re: reduce metaoperator on an empty list

2005-05-20 Thread Mark A. Biggar
John Macdonald wrote: Is there a built-in operator that doesn't have a meaningful identity value? I first thought of exponentiation, but it has an identity value of 1 - you just have to realize that since it is a right associative operator, the identity has to be applied from the right. Well the i

Re: reduce metaoperator on an empty list

2005-05-20 Thread TSa (Thomas Sandlaß)
John Macdonald wrote: ... (and there may be additional operator attributes that make sense there too, although none come immediately to mind). Well, I wonder why people neglect the fact that the neutral/identity element is not a property of the operator alone?! Besides the associativity and commuta

Re: reduce metaoperator on an empty list

2005-05-20 Thread John Macdonald
On Fri, May 20, 2005 at 06:09:55AM -0700, Randal L. Schwartz wrote: > > "Mark" == Mark A Biggar <[EMAIL PROTECTED]> writes: > > Mark> The usual definition of reduce in most languages that support it, is > Mark> that reduce over the empty list produces the Identity value for the > Mark> operati

Re: reduce metaoperator on an empty list

2005-05-20 Thread Randal L. Schwartz
> "Randal" == Randal L Schwartz writes: Randal> For example, if I wanted the identity hash (where all values are 1, Randal> but keys are original list elements), I could do: Randal> my %hash = @somelist.inject({}, { $^a{$^b} = 1; $^a }); And yes, I know I can spell this as: my %hash = ({},

Re: reduce metaoperator on an empty list

2005-05-20 Thread Randal L. Schwartz
> "Mark" == Mark A Biggar <[EMAIL PROTECTED]> writes: Mark> The usual definition of reduce in most languages that support it, is Mark> that reduce over the empty list produces the Identity value for the Mark> operation. In Smalltalk, the equivalent of "reduce" is "inject:into:", so a "sum" re

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: 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: 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: 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: 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

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

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

Re: reduce metaoperator on an empty list

2005-05-18 Thread Stuart Cook
On 5/19/05, Brad Bowman <[EMAIL PROTECTED]> wrote: > Can't the appropriate identity just be prepended? > > > > my @a; > > > [+] @a; # 0? exception? > [+] (0, @a); > > > > [*] @a; # 1? exception? > [*] (1, @a); > > > > [<] @a; # false? > [<] (-Inf, @a); # ??? Wow, that's actually pretty elegant

Re: reduce metaoperator on an empty list

2005-05-18 Thread Brad Bowman
> Another alternative is to give the user the option of specifying such > a unit when using the reduction meta-operator, but this seems to work > against the whole point of [+] (which is brevity). If you want to > specify your own unit, use '&reduce'. Can't the appropriate identity just be prepen

Re: reduce metaoperator on an empty list

2005-05-18 Thread Mark A. Biggar
Stuart Cook 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, depending on whether or not people think (2) is actually a good idea. The u

Re: reduce metaoperator on an empty list

2005-05-18 Thread Rod Adams
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, depending on whether o

Re: reduce metaoperator on an empty list

2005-05-18 Thread Rob Kinyon
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, > > depending on whether or not p

Re: reduce metaoperator on an empty list

2005-05-18 Thread Stuart Cook
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, depending on whether or not people think (2) is actually a good idea. The usual none(@Larry

Re: reduce metaoperator on an empty list

2005-05-18 Thread Stuart Cook
On 5/19/05, Matt Fowles <[EMAIL PROTECTED]> wrote: > All~ > > What does the reduce metaoperator do with an empty list? > /me puts on his lambda hat In Haskell, there is a distinction between foldl and foldl1 (similar remarks apply to foldr/foldr1[1]): The former (foldl) re

Re: reduce metaoperator on an empty list

2005-05-18 Thread Mark A. Biggar
Matt Fowles wrote: All~ What does the reduce metaoperator do with an empty list? my @a; [+] @a; # 0? exception? [*] @a; # 1? exception? [<] @a; # false? [||] @a; # false? [&&] @a; # true? Also if it magically supplies some correct like the above, how does it know what that value is

Re: reduce metaoperator on an empty list

2005-05-18 Thread Rod Adams
Matt Fowles wrote: All~ What does the reduce metaoperator do with an empty list? my @a; [+] @a; # 0? exception? [*] @a; # 1? exception? [<] @a; # false? [||] @a; # false? [&&] @a; # true? Also if it magically supplies some correct like the above, how does it know what that value is?

reduce metaoperator on an empty list

2005-05-18 Thread Matt Fowles
All~ What does the reduce metaoperator do with an empty list? my @a; [+] @a; # 0? exception? [*] @a; # 1? exception? [<] @a; # false? [||] @a; # false? [&&] @a; # true? Also if it magically supplies some correct like the above, how does it know what that value is? Thanks, Matt --

Re: reduce metaoperator

2005-05-07 Thread Larry Wall
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 th

Re: reduce metaoperator

2005-05-07 Thread Larry Wall
On Sat, May 07, 2005 at 05:11:19PM +1000, Stuart Cook wrote: : On 5/7/05, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: : > It might not be a problem -- I'm thinking we may end up tokenizing : > most or all of the meta operators, so that [+] would be considered : > its own token, and then the "long

Re: reduce metaoperator

2005-05-07 Thread Stuart Cook
On 5/7/05, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: > It might not be a problem -- I'm thinking we may end up tokenizing > most or all of the meta operators, so that [+] would be considered > its own token, and then the "longest matching token" rule > would be sufficient to disambiguate the te

Re: reduce metaoperator

2005-05-06 Thread Patrick R. Michaud
On Fri, May 06, 2005 at 12:23:49PM +1000, Stuart Cook wrote: > On 5/6/05, Stuart Cook <[EMAIL PROTECTED]> wrote: > > (snip) As long as each meta-operator > > explicitly knows what type of regular operator it accepts (and > > produces), there shouldn't be any problems with ambiguity. > > > > Havin

Re: reduce metaoperator

2005-05-05 Thread Stuart Cook
On 5/6/05, Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]> wrote: > I find this table very interesting, in that it shows the fundamental > difference between reduce and the existing meta-ops. Yep, that was basically the whole point of the table. > The existing meta-operators alter the semantics of t

Re: reduce metaoperator

2005-05-05 Thread Stuart Cook
On 5/6/05, Stuart Cook <[EMAIL PROTECTED]> wrote: (B> (snip) As long as each meta-operator (B> explicitly knows what type of regular operator it accepts (and (B> produces), there shouldn't be any problems with ambiguity. (B> (B (BHaving posted that, I immediately thought of some problems: (

Re: reduce metaoperator

2005-05-05 Thread Brent 'Dax' Royal-Gordon
On 5/5/05, Stuart Cook <[EMAIL PROTECTED]> wrote: > +-+---+-++ > | Meta-op | is| operates on | to produce | > +-+---+-++ > | [ ] | circumfix | infix | prefix | > +-+---+

Re: reduce metaoperator

2005-05-05 Thread Stuart Cook
If I understand correctly, so far we have the following meta-operators: [ ] circumfix meta-operator on infix operator which produces a prefix operator >> << circumfix meta-operator on infix operator which produces an infix operator = postfix meta-operator on infix operator which produces an infi

Re: reduce metaoperator

2005-05-05 Thread John Williams
On Thu, 5 May 2005, John Williams wrote: > or even > > @x -= @y; Doh! That should be C< $x -= $y; > of course.

Re: Semi-related question: reduce metaoperator

2005-05-05 Thread Larry Wall
On Thu, May 05, 2005 at 03:03:22PM -0400, Rob Kinyon wrote: : Can I put an operator in a variable and then use it in the [] : reduce meta-operator? Something like: : : $op = '+'; : $x = [$op] @x; Nope. That would be parsed as a list of one element, followed by a syntax error. You'll have to

Semi-related question: reduce metaoperator

2005-05-05 Thread Rob Kinyon
Can I put an operator in a variable and then use it in the [] reduce meta-operator? Something like: $op = '+'; $x = [$op] @x; Rob

Re: reduce metaoperator

2005-05-05 Thread John Williams
On Thu, 5 May 2005, David Wheeler wrote: > > I can see how to ask for a binary (hence infix) operator, but how > > do I ask > > for a prefix or postfix operator specifically, which +<< and >>+ do? > > Maybe there are Operator::Prefix, etc, roles defined so you can ask > > for > > them? > > Ask for

Re: reduce metaoperator

2005-05-05 Thread David Wheeler
On May 5, 2005, at 11:28 , John Williams wrote: How does [+] know you mean reduce &infix:<+>, @array; instead of reduce &prefix:<+>, @array; which is nonsense, but the [+] is in a prefix position. Because [] applies only to infix operators, as I understand it. With the hyper metaoperator, the

Re: reduce metaoperator

2005-05-05 Thread John Williams
On Wed, 4 May 2005, Larry Wall wrote: > It would be nice to have an easy-to-access "What's this?" interface > that could be stitched into your favorite editor to identify what's > under the cursor, or at least a command like: > > p6explain '[+]' That would make me extremely happy. > :$sum

Re: reduce metaoperator

2005-05-05 Thread Leopold Toetsch
Larry Wall <[EMAIL PROTECTED]> wrote: > It would be nice to have an easy-to-access "What's this?" interface > that could be stitched into your favorite editor to identify what's > under the cursor, or at least a command like: > p6explain '[+]' s:p5/nice to have/absolutely necessary/ unless $

Re: reduce metaoperator

2005-05-05 Thread Larry Wall
On Wed, May 04, 2005 at 11:58:59PM -0600, Luke Palmer wrote: : On 5/4/05, Larry Wall <[EMAIL PROTECTED]> wrote: : > [<] could mean "monotonically increasing". : : Not unless we make boolean operators magic. There are arguments for : doing that, but I don't really want to think about how that woul

Re: reduce metaoperator

2005-05-04 Thread Damian Conway
Luke Palmer wrote: On 5/4/05, Larry Wall <[EMAIL PROTECTED]> wrote: [<] could mean "monotonically increasing". Not unless we make boolean operators magic. There are arguments for doing that, but I don't really want to think about how that would be done at the moment. Reduce over a straight-up (or

  1   2   >