[Factor-talk] Quotations and generics

2014-12-05 Thread Andrea Ferretti
Hi, I am trying to implement monoids in factor. A monoid is a set with a binary associative operation (and, depending on the defintiion, a neutral element for it). Typical examples are numbers (with either addition or multiplication) or sequences (with concatenation). Other examples can be

Re: [Factor-talk] Quotations and generics

2014-12-05 Thread John Benediktsson
You could use the stack-checker to infer the effect of the quotation and then dispatch like this: ``` M: quotation |+| dup infer in length { { 1 [ [ bi |+| ] 2curry ] } { 2 [ [ 2bi |+| ] 2curry ] } { 3 [ [ 3bi |+| ] 2curry ] } } case ; ``` But you might start

Re: [Factor-talk] Quotations and generics

2014-12-05 Thread John Benediktsson
And more generally, using the ``generalizations`` vocabulary: M: quotation |+| dup infer in length [ nbi |+| ] 3curry ; On Fri, Dec 5, 2014 at 7:22 AM, John Benediktsson mrj...@gmail.com wrote: You could use the stack-checker to infer the effect of the quotation and then dispatch like

Re: [Factor-talk] Quotations and generics

2014-12-05 Thread Andrea Ferretti
Wow, you and Factor never stop to surprise me! :-) 2014-12-05 16:23 GMT+01:00 John Benediktsson mrj...@gmail.com: And more generally, using the ``generalizations`` vocabulary: M: quotation |+| dup infer in length [ nbi |+| ] 3curry ; On Fri, Dec 5, 2014 at 7:22 AM, John Benediktsson

Re: [Factor-talk] Quotations and generics

2014-12-05 Thread John Benediktsson
Those solutions don't check to make sure both quotations have the same effect, or at least the same number of effect inputs, you might want to add some of that for production-type code :-) On Fri, Dec 5, 2014 at 7:37 AM, Andrea Ferretti ferrettiand...@gmail.com wrote: Wow, you and Factor never

Re: [Factor-talk] Quotations and generics

2014-12-05 Thread Andrea Ferretti
Ehr... in fact, I was not :-P In fact, the implementation of |+| that comes from this is composition, which is of course another natural operation. I did not hitnk of it 2014-12-05 18:55 GMT+01:00 Björn Lindqvist bjou...@gmail.com: I wonder, are you aware that quotations are just a type of