Re: Not-so-smart matching (was Re: How to make a new operator.)

2012-03-25 Thread Damian Conway
yary suggested: > In a situation like this, I reach for a thesaurus The standout from that list for me is: 'consonance'. Second favorite is: 'gibe' or 'jibe'. But the underlying operation is .ACCEPTS(), so perhaps the operation should be referred to as "acceptance" or "acceptibility". Damian

Re: Not-so-smart matching (was Re: How to make a new operator.)

2012-03-25 Thread yary
I also like "agreement", "conformance"... In a situation like this, I reach for a thesaurus- very useful when looking for just the right name for a variable/method name/way to describe a concept. Here's a grab bag to start with: accord, agree, conformance, conformation, conformity, congruence, con

Re: Floating-point equality (was Re: How to make a new operator.)

2012-03-25 Thread Moritz Lenz
On 03/25/2012 06:55 AM, Moritz Lenz wrote: > I don't know if the majority of the perl6-language posters have realized > it yet, but both Perl 6 and the its implementations are quite mature > these days. Mature enough that such proposals should be prototyped as > modules, and thoroughly tested on lo

Re: How to make a new operator.

2012-03-24 Thread Damian Conway
> At least in #perl6 I've never seen anybody try to write an auto-deduced > sequence, and fail because of floating-point errors. Except for Martin's 1, sqrt(2), 2...8 But, yes, the widespread use of Rats rather than Nums means only the edgiest of edge-cases fails. And as you get an explicit Failu

Re: Floating-point equality (was Re: How to make a new operator.)

2012-03-24 Thread Moritz Lenz
On 03/25/2012 05:59 AM, David Green wrote: > On 2012-March-23, at 12:01 am, Damian Conway wrote: >> [...] we ought to allow for the inevitable loss of significant digits within >> the two preliminary division ops, and therefore compare the results with an >> suitably larger epsilon. >> That wou

Re: How to make a new operator.

2012-03-24 Thread Moritz Lenz
On 03/23/2012 09:14 AM, Damian Conway wrote: >> it means we cannot do the same fuzziness for the endpoint, > > Except that we will be encouraging people to use: * >= $END > as their standard endpoint pattern, which will provide > most of the necessary fuzz. and which will still surprise those p

Not-so-smart matching (was Re: How to make a new operator.)

2012-03-24 Thread David Green
On 2012-March-21, at 6:38 pm, Daniel Carrera wrote: > The idea of smart-matching a function just doesn't quite fit with my brain. I > can memorize the fact that smart-matching 7 and &foo means evaluating foo(7) > and seeing if the value is true, but I can't say I "understand" it. Maybe it just n

Floating-point equality (was Re: How to make a new operator.)

2012-03-24 Thread David Green
On 2012-March-23, at 12:01 am, Damian Conway wrote: > [...] we ought to allow for the inevitable loss of significant digits within > the two preliminary division ops, and therefore compare the results with an > suitably larger epsilon. > That would not only be computational more justifiable, I su

Re: How to make a new operator.

2012-03-24 Thread Jonathan Lang
On Mar 24, 2012, at 6:36 PM, Stefan O'Rear wrote: > On Sat, Mar 24, 2012 at 06:16:58PM -0700, Jonathan Lang wrote: >> IMHO: if we're going to take loss of precision into account, we should do so >> explicitly. I'm a bit rusty, so forgive me if I misuse the terminology: if >> a number has an eps

Re: How to make a new operator.

2012-03-24 Thread Stefan O'Rear
On Sat, Mar 24, 2012 at 06:16:58PM -0700, Jonathan Lang wrote: > IMHO: if we're going to take loss of precision into account, we should do so > explicitly. I'm a bit rusty, so forgive me if I misuse the terminology: if a > number has an epsilon, the epsilon should be attached to it as a trait so

Re: How to make a new operator.

2012-03-24 Thread Jonathan Lang
On Mar 24, 2012, at 5:26 PM, Damian Conway wrote: >> Actually, that one works fine in both niecza and rakudo, since those are >> Rats. > > Oh, that's good to hear. > > It doesn't change my underlying argument however. Any operations > performed on genuine floats are going to lose precision, an

Re: How to make a new operator.

2012-03-24 Thread Damian Conway
> Actually, that one works fine in both niecza and rakudo, since those are Rats. Oh, that's good to hear. It doesn't change my underlying argument however. Any operations performed on genuine floats are going to lose precision, and if we're using such operations to infer relationships (such as eq

Re: How to make a new operator.

2012-03-24 Thread Larry Wall
On Fri, Mar 23, 2012 at 07:14:51PM +1100, Damian Conway wrote: : For example: : : 1, 1.0001, 1.0002 ... * : : won't deduce a correct arithmetic sequence either (on most hardware). Actually, that one works fine in both niecza and rakudo, since those are Rats. Larry

Re: How to make a new operator.

2012-03-23 Thread Patrick R. Michaud
On Thu, Mar 22, 2012 at 11:07:08AM -0500, Bruce Gray wrote: > Well, it works in Niecza. It does not (yet) work in Rakudo: > 15:25 perl6: my @squares := 0, (-> *@a { @a.elems ** 2 }) > ... *; say ~@squares[^11]; > 15:25 ..niecza v15-4-g1f35f89: OUTPUT<<0 1 4 9 16 25 36 49 > 64 81 100NL

Re: How to make a new operator.

2012-03-23 Thread Damian Conway
> But unless we twist smartmatching semantics for that purpose, No! Please, no. ;-) > it means we cannot do the same fuzziness for the endpoint, Except that we will be encouraging people to use: * >= $END as their standard endpoint pattern, which will provide most of the necessary fuzz. > S

Re: How to make a new operator.

2012-03-22 Thread Moritz Lenz
On 03/23/2012 05:30 AM, Patrick R. Michaud wrote: > On Fri, Mar 23, 2012 at 03:03:09PM +1300, Martin D Kealey wrote: >> Question: do we support >> >> 1, 2i, -4 ... 256 > > I think this ought to work, but for some reason Rakudo on my system > hangs whenever I try it. The problem was that inf

Re: How to make a new operator.

2012-03-22 Thread Moritz Lenz
On 03/23/2012 07:01 AM, Damian Conway wrote: > Patrick correctly observed: > >> On Rakudo on my system, sqrt(2) indeed produces a Num, >> but since floating point arithmetic doesn't result in >> sqrt(2) / 1 == 2 / sqrt(2), no geometric sequence is deduced >> and the sequence fails with "unable to

Re: How to make a new operator.

2012-03-22 Thread Damian Conway
Patrick correctly observed: > On Rakudo on my system, sqrt(2) indeed produces a Num, > but since floating point arithmetic doesn't result in > sqrt(2) / 1 == 2 / sqrt(2), no geometric sequence is deduced > and the sequence fails with "unable to deduce sequence". Although, arguably, that might be

Re: How to make a new operator.

2012-03-22 Thread Patrick R. Michaud
On Fri, Mar 23, 2012 at 03:03:09PM +1300, Martin D Kealey wrote: > On Thu, 22 Mar 2012, Carl Mäsak wrote: > > Jonathan Lang (>>), Daniel (>): > > >>    1, 2, 4 ... 100 # same as 1,2,4,8,16,32,64 > > > > > > That last one doesn't work on Rakudo :-( > > > > And it never will. Note that 100 is not a p

Re: How to make a new operator.

2012-03-22 Thread Martin D Kealey
On Thu, 22 Mar 2012, Carl Mäsak wrote: > Jonathan Lang (>>), Daniel (>): > >>    1, 2, 4 ... 100 # same as 1,2,4,8,16,32,64 > > > > That last one doesn't work on Rakudo :-( > > And it never will. Note that 100 is not a power of 2, and that the goal > needs to match exactly. This is because smartmat

Re: How to make a new operator.

2012-03-22 Thread Moritz Lenz
Am 22.03.2012 17:07, schrieb Bruce Gray: I have run into the same need for something like :index, while playing with RosettaCode tasks like "Continued_fraction". If you want the index, don't use series. It's easy enough to access the array elements yourself. You can do something like my @a :

Re: How to make a new operator.

2012-03-22 Thread Jon Lang
On Thu, Mar 22, 2012 at 9:07 AM, Bruce Gray wrote: > On Mar 21, 2012, at 11:49 PM, Jonathan Lang wrote: > > What I want to know is whether there's a way to define a step function >> that's based in part or in whole on the current term's index. For example, >> how would I use infix:<...> to gene

Re: How to make a new operator.

2012-03-22 Thread Bruce Gray
On Mar 21, 2012, at 11:49 PM, Jonathan Lang wrote: What I want to know is whether there's a way to define a step function that's based in part or in whole on the current term's index. For example, how would I use infix:<...> to generate the perfect squares between 0 and 100? Namely, '0,

Re: How to make a new operator.

2012-03-22 Thread Carl Mäsak
Daniel (>): > Related questions:  What types of sequences can Perl 6 recognize? As covered by Jonathan Lang earlier in this thread (though it was perhaps easy to miss), Perl 6 auto-detects arithmetic sequences (same additive difference each time) and geometric sequences (same multiplicative factor

Re: How to make a new operator.

2012-03-22 Thread Daniel Carrera
On 22 March 2012 12:06, Moritz Lenz wrote: > >> But that's a bit of a problem if I *don't* want a value higher than 100. > > Then exclude it: 2, 4, 8 ...^ * > 100 Ok... I looked up what you did. I see how it works. Thanks. Related questions: What types of sequences can Perl 6 recognize? --

Re: How to make a new operator.

2012-03-22 Thread Moritz Lenz
On 03/22/2012 11:51 AM, Daniel Carrera wrote: > On 22 March 2012 11:02, Carl Mäsak wrote: 1, 2, 4 ... 100 # same as 1,2,4,8,16,32,64 >>> >>> That last one doesn't work on Rakudo :-( >> >> And it never will. Note that 100 is not a power of 2, and that the >> goal needs to match exactly. T

Re: How to make a new operator.

2012-03-22 Thread Daniel Carrera
On 22 March 2012 11:02, Carl Mäsak wrote: >>>    1, 2, 4 ... 100 # same as 1,2,4,8,16,32,64 >> >> That last one doesn't work on Rakudo :-( > > And it never will. Note that 100 is not a power of 2, and that the > goal needs to match exactly. This is because smartmatching is used, ... > If you're wo

Re: How to make a new operator.

2012-03-22 Thread Carl Mäsak
Jonathan Lang (>>), Daniel (>): >> So: >> >>    1, 3 ... 13 # same as 1,3,5,7,9,11,13 >>    1 ... 10 # same as 1,2,3,4,5,6,7,8,9,10 >>    1, 2, 4 ... 100 # same as 1,2,4,8,16,32,64 > > That last one doesn't work on Rakudo :-( And it never will. Note that 100 is not a power of 2, and that the goal

Re: How to make a new operator.

2012-03-22 Thread Daniel Carrera
On 22 March 2012 04:59, Jonathan Lang wrote: > My understanding is if you want to count by threes, starting at 2 and ending > at 14, you should be able to write: > >   2, 5 ... 14 That certainly looks very intuitive, and it is similar to what I would write in an email. The only annoyance is that

Re: How to make a new operator.

2012-03-21 Thread Jonathan Lang
What I want to know is whether there's a way to define a step function that's based in part or in whole on the current term's index. For example, how would I use infix:<...> to generate the perfect squares between 0 and 100? Namely, '0,1,4,9,16,25,36,49,64,81,100'. For example, is Perl 6 set

Re: How to make a new operator.

2012-03-21 Thread Jonathan Lang
My understanding is if you want to count by threes, starting at 2 and ending at 14, you should be able to write: 2, 5 ... 14 That is, the list-building operator looks at the previous two or three terms preceding it to determine where to start and what "step function" to use, and then looks

Re: How to make a new operator.

2012-03-21 Thread Daniel Carrera
On 22 March 2012 01:13, Solomon Foster wrote: > It actually smartmatches whatever is on the right hand side against > the sequence, and stops when the smartmatch returns True.  It just > "happens" that you smartmatch an anonymous function, it executes the > function and returns its result. I see.

Re: How to make a new operator.

2012-03-21 Thread Solomon Foster
On Wed, Mar 21, 2012 at 7:52 PM, Daniel Carrera wrote: >> * >= $b --- this determines where the sequence ends:  when the current value >> is greater or equal to $b. > > So...  after the "..." you have an anonymous function that has to > return 'True' for the sequence to end? Seems strange, but it

Re: How to make a new operator.

2012-03-21 Thread Daniel Carrera
On 22 March 2012 00:08, Brandon Allbery wrote: > * + $c --- the next value is the current value plus $c.  ("*" means > "Whatever", and generally refers to the current value of something.  In this > case, we're specifying how to make a new value given a current value.  You > can think of it as a w

Re: How to make a new operator.

2012-03-21 Thread Damian Conway
> Ok, so infix:<...> isn't what I wish for either... Can you help me > understand Damian's example? Breaking down that example: $a, # Start at $a *+$c # Generate next number via: sub($prev_num} { $prev_num + $c } ... # Repeat until... * >=$b # ...this sub matches:

Re: How to make a new operator.

2012-03-21 Thread Daniel Carrera
On 21 March 2012 22:50, Carl Mäsak wrote: > It would also produce an infinite list, because by the rules you need > the RHS of infix:<...> to match exactly, and 10 is not in the infinite > list 2, 5, 8, 11, 14... Which is why you'd need to write something > like * >= 10. Ok, so infix:<...> isn't

Re: How to make a new operator.

2012-03-21 Thread Damian Conway
> Interesting... but it doesn't seem to work in Rakudo Star (2012.02): > >> @(2,5..10) You need three dots, not two. Damian

Re: How to make a new operator.

2012-03-21 Thread Carl Mäsak
Damian (>>), Daniel (>): >> Perl 6 already has:  0,$c...* >> >> e.g. 0,3...* > 0, 3, 6, 9, 12 > > Interesting... but it doesn't seem to work in Rakudo Star (2012.02): > >> @(2,5..10) > 2 5 6 7 8 9 10 > > :-( Keep in mind that infix:<..> will listify to the kind of one-step-at-a-time range

Re: How to make a new operator.

2012-03-21 Thread Daniel Carrera
On 21 March 2012 22:09, Damian Conway wrote: >> Is it possible to create a new range operator ':' such that: > > Do you need to? Hmm... maybe not... >> a:b:c is a range from 'a' to 'b' by steps of 'c'. > > Perl 6 already has: $a,*+$c...* >=$b > > E.g. 2, 5 ...^ *>=15  > 2,5,8,11,14 That lo

Re: How to make a new operator.

2012-03-21 Thread Carl Mäsak
Daniel (>>), Damian (>): >> : is the same as 0..Inf > > Perl 6 already has: ^Inf > 0,1,2,3,4,5, Hah, Damian made an off-by-one error! Oh wait... // Carl

Re: How to make a new operator.

2012-03-21 Thread Damian Conway
> Is it possible to create a new range operator ':' such that: Do you need to? > a:b:c is a range from 'a' to 'b' by steps of 'c'. Perl 6 already has: $a,*+$c...* >=$b E.g. 2, 5 ...^ *>=15 > 2,5,8,11,14 > :b is the same as 0..b Perl 6 already has ^$b e,g, ^100 > 0..99 > a: is th

Re: How to make a new operator.

2012-03-21 Thread Daniel Carrera
Hi Moritz >> a:b is the same as a..b  (this is the easy part) >> >> a:b:c is a range from 'a' to 'b' by steps of 'c'. For example, 2:15:3 >> == 2,5,8,11,14 > > That can be done by giving the new infix:<:> operator list associativity > (niecza already supports this) Can you explain or give me a li

Re: How to make a new operator.

2012-03-21 Thread Moritz Lenz
On 03/21/2012 09:07 PM, Daniel Carrera wrote: > Hello, > > Is it possible to create a new range operator ':' such that: > > a:b is the same as a..b (this is the easy part) > > a:b:c is a range from 'a' to 'b' by steps of 'c'. For example, 2:15:3 > == 2,5,8,11,14 That can be done by giving th

How to make a new operator.

2012-03-21 Thread Daniel Carrera
Hello, Is it possible to create a new range operator ':' such that: a:b is the same as a..b (this is the easy part) a:b:c is a range from 'a' to 'b' by steps of 'c'. For example, 2:15:3 == 2,5,8,11,14 :b is the same as 0..b a: is the same as a..Inf ::c is the same as 0:Inf:c : is the same a