Re: [Factor-talk] spreadsheets
> With the era of Lotus-123 officially ending, I wondered whether > spreadsheets in general are still necessary. Other people responding to this post have asked why the OP referenced Lotus 1-2-3's era as ending. I suspect the comment is in response to IBM end-of-lifeing Lotus 1-2-3. http://www.zdnet.com/goodbye-lotus-1-2-3-715385/ > Can any Factor users think of a computation more easily handled by a > spreadsheet than by a text editor and the Listener? My minor response is to point out that there are a range of functions available in spreadsheets that are not yet available in Factor. For example, until I implemented my own functions, there were no time-value of money functions within Factor. There are plenty of functions, e.g. Excel's MIRR, that are not available in Factor (yet). My major response focuses on the style of user interaction afforded by spreadsheets. Spreadsheets allow users to "stage" data (enter data piecemeal), reshape the data, apply a calculation, incrementally add another calculation, etc. In my mind, it is the incremental construction of calculation, combined with the use spatial reasoning instead of sequential reasoning, that is the major benefit of spreadsheets. Additionally, in a spreadsheet one's data is stable: intermediate calculations display their results on the screen without any fear of "losing" them. Contrast this with a listener, where one's data is being constantly "consumed". The intermediate calculations are impermanent (without taking intermediate actions such as duplicating references or serialisation to a file). Moreover, the inputs (data from a file), intermediate results and outputs are placed in separate locations (text editor vs display in a listener) unless the user again takes action to write the results back to a file --- but this results in additional processing and cognitive overhead that spreadsheets do not require. So, I see spreadsheets as being a "great" prototyping environment for reasoning about business data. My major problem with spreadsheets is the lack of capacity to abstract from the spatial layout of the cells. This results in any serious spreadsheet containing massive code duplication. Moreover, testing a spreadsheet is difficult (without leaping out of the spreadsheet paradigm and using an associated programming language, e.g. VBA). I note that a company called Resolver Systems (based in the UK) attempted to introduce a new paradigm for spreadsheets, whereby spreadsheet calculations were re-interpreted into Python code, and then that Python code was deployable outside the spreadsheet paradigm entirely (I think). My understanding is that Resolver has also been discontinued due to poor sales. http://www.python.org/about/success/resolver/ Looking at the user interface and code samples shown at the above link, I think that Resolver Systems were identifying the right problem --- lack of abstraction within spreadsheets, inability to intermix procedural logic with functional calculation --- with the wrong solution. The main problem with spreadsheets calculations is their lack of abstraction. Data input specification and calculation code is intermixed. Take this as a typical example: =AJ7+AK7*$AJ$26 The purpose of this code is to estimate the cost of hot water in a shower. There are lots of problems with code in this style: 1. The data inputs are cryptic, not semantically labelled. (This is state of affairs is encouraged by Excel's user interface.) 2. The code is inherently bound to the cells from which *these* values are obtained. This impedes, for example, arbitrary creation of test suites (without designing the application for such testing up-front, which detracts from the great benefit of spreadsheets mentioned above: piecemeal experimentation). 3. The code cannot be called from other locations. If this code is reused, it is reused through copy-n-paste. The problem with the Python-based implementation of Resolver is that, as far as I can tell, didn't really address any of these issues. (One would have had to *design* code to be reused; which, again, defeats the purpose of incrementality and experimentation.) Now, as a thought experiment, imagine what would happen if one implemented a spreadsheet program within Factor's development environment. One could conceive of spreadsheet code as being Factor quotations, with intercell references being treated as localised "datastacks". Here is the equivalent stack of cell references: AJ7 AK7 $AJ$26 And the code that operates on said cell references: [ * + ] Now, the locality of the cell references is discrete from the computation. There are several benefits: 1. This particular computation is callable from elsewhere in the spreadsheet. Let's say this computation lives at cell AL7. Another cell could call it like this: [ arbitrary-code ... AL7 ... arbitrary-code ] Here, the reference to AL7 is the reference to the function denoted by AL7, not AL7's value or local stack references. The fu
Re: [Factor-talk] Serialisation with a JSON representation
My thanks for Chris and John. John's suggestion to use the `from-slots' word to provide automatic generic deserialisation of json is great. I've been experimenting with serialization using different methods and different encodings. This thread on github has been raised: https://github.com/slavapestov/factor/issues/913 Here are some additional observations: 1. `json>' seems more resistant to schema evolution than the `deserialize'. I saved out my data structure to disk, then changed the shape of my tuple within the Factor image. My tuple did have four slots; I placed a new slot of type string in position three; giving the new tuple five slots. On loading the data using `deserialize', the data that was previously in slot three was again placed in slot 3, which means the data structure is now corrupted. Whereas on re-running the experiment using json, data was restored to the correct slots, leaving the new slot with an empty string, and correctly restoring the data to its correct locations. 2. In terms of deserialization speed, using a simple vector containing tuples, using deserialize in binary mode is fastest. Using json deserialization (including converting the hashtable to tuples) is about 10% slower. Surprisingly, deserialize in utf8 mode is slower than json deserialization, running about 20% slower than deserialize using binary encoding. Loryn Jenkins -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Serialisation with a JSON representation
Hi I've pasted a snippet of code that serialises an object (a vector containing a tuple) to JSON format, then loads it back into memory. http://paste.factorcode.org/paste?id=3028 When loading JSON representation into memory instantiates a hashtable, which I then convert into a tuple using the word hashtable>cd My questions: 1. I'm using first4 to retrieve the members of the tuple from the JSON representation, placing them on the stack, so they can form an input to boa. How would I retrieve an *arbitrary* number of slots onto the stack? (i.e. For objects have e.g. 10, 15 or 50... slots.) 2. What I'm doing seems pretty kack-handed. What generic understanding of reflection and/or core words have I not yet discovered, which would contribute to implementing a more generic function? 3. Is there a Factor library providing a more direct serialisation format than JSON? Loryn Jenkins -- See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Cookbook and Learning
Graham What type of tutorials would you find useful? Loryn Jenkins On Mon, Jun 17, 2013 at 10:34 PM, graham telfer wrote: > The lack of tutorials for Factor is a major bugbear. I have found The > Rosetta Code site very useful because you can compare Factor code with a > language you already know for many different problems. > > Chapter 4 of Thinking Forth is also useful because it has a lot of good > advice about factoring code. > > > -- > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Idiomatic use of sequences for iterative functions?
Thank you, John. That's what I was looking for. I must say: currying an entire sequence is pretty wild! It's a non-obvious solution. >> "I'm not sure that is undesirable here...?" No, it's not undesirable, except for the fact that 30-40% of that code exists for the sake of the side-effect. Of course, computation by calculation is shorter again ... USING: arrays math math.ranges math.primes.factors sequences ; IN: lamps : ( -- seq ) 100 [1,b] >array ; : calc-switching ( -- lamps ) [ divisors length even? ] map ; (But then, that wasn't my purpose. I was trying to figure out how to get a nested iteration done with sequences instead of always falling back to recursion.) Thanks, again. Loryn Jenkins On Tue, Apr 23, 2013 at 12:44 AM, John Benediktsson wrote: > Something like this would be simpler: > > http://paste.factorcode.org/paste?id=2914#1329 > > You don't need a symbol to pass the variable around, and even though it is > "side-effecting", I'm not sure that is undesirable here...? > > > On Mon, Apr 22, 2013 at 7:17 AM, Loryn Jenkins wrote: > >> Hi >> >> In "Factor Philosophy", slava writes: "Imperative programming and indexed >> loops are almost always not the most idiomatic solution." >> >> I've implemented this puzzle ( >> http://mindyourdecisions.com/blog/2013/04/22/100-light-bulbs-puzzle/ ) >> using a side-effecting function: >> http://paste.factorcode.org/paste?id=2914 >> >> The words do-switching and toggle-switches implement the equivalent of a >> nested loop. >> >> Without using recursion, counted for loops or side-effecting functions, >> what is an idiomatic way of implementing this nested iteration? >> >> Loryn Jenkins >> >> >> -- >> Precog is a next-generation analytics platform capable of advanced >> analytics on semi-structured data. The platform includes APIs for building >> apps and a phenomenal toolset for data science. Developers can use >> our toolset for easy data analysis & visualization. Get a free account! >> http://www2.precog.com/precogplatform/slashdotnewsletter >> ___ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> >> > > > -- > Precog is a next-generation analytics platform capable of advanced > analytics on semi-structured data. The platform includes APIs for building > apps and a phenomenal toolset for data science. Developers can use > our toolset for easy data analysis & visualization. Get a free account! > http://www2.precog.com/precogplatform/slashdotnewsletter > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > -- Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Idiomatic use of sequences for iterative functions?
Hi In "Factor Philosophy", slava writes: "Imperative programming and indexed loops are almost always not the most idiomatic solution." I've implemented this puzzle ( http://mindyourdecisions.com/blog/2013/04/22/100-light-bulbs-puzzle/ ) using a side-effecting function: http://paste.factorcode.org/paste?id=2914 The words do-switching and toggle-switches implement the equivalent of a nested loop. Without using recursion, counted for loops or side-effecting functions, what is an idiomatic way of implementing this nested iteration? Loryn Jenkins -- Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] stack contents during operation of sequence combinator
I won't address what the stack effect guarantees. But in order to see the stack during sequence combinator, why don't you throw a break into the quotation. That'll show you the state of the stack. Like this: https://www.evernote.com/shard/s302/sh/d370a2ff-b243-47e4-88bf-dafdb45cdd52/b8d4add4c18c3e1451d4497d892ad83d Loryn Jenkins On Mon, Apr 15, 2013 at 12:27 PM, mr w wrote: > Anyone know what the stack looks like during the execution of a > sequence combinator? > > For example, the quot passed to map expects ... > > quot, a quotation with stack effect ( ... elt -- ... newelt ) > > Are there any guarantees on the "..." in "... elt"? > > Does "seq quot map" remain on the stack while quot is applied to each > element? > > > -- > Precog is a next-generation analytics platform capable of advanced > analytics on semi-structured data. The platform includes APIs for building > apps and a phenomenal toolset for data science. Developers can use > our toolset for easy data analysis & visualization. Get a free account! > http://www2.precog.com/precogplatform/slashdotnewsletter > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] filter-index
Sorry: that was supposed to be: USING: kernel sequences.extras fry ; : filter-index' ( ... seq quot: ( ... elt i -- ... ? ) -- ... seq' ) '[ [ nip @ ] filter-index ] call ; inline On Mon, Apr 15, 2013 at 12:35 PM, Loryn Jenkins wrote: > Thank you. Anyway: You get my point about wrapping filter-index such that > you can get a word that throws away the element? > > USING: kernel sequences.extras fry ; > : filter-index' > '[ [ nip @ ] filter-index ] call ; inline > > > On Mon, Apr 15, 2013 at 12:24 PM, mr w wrote: > >> On Sun, Apr 14, 2013 at 9:43 PM, Loryn Jenkins wrote: >> > I'm not sure about filter-index - I don't see any documentation about >> that >> > word. >> >> http://docs.factorcode.org/content/word-filter-index,sequences.extras.html >> >> >> -- >> Precog is a next-generation analytics platform capable of advanced >> analytics on semi-structured data. The platform includes APIs for building >> apps and a phenomenal toolset for data science. Developers can use >> our toolset for easy data analysis & visualization. Get a free account! >> http://www2.precog.com/precogplatform/slashdotnewsletter >> ___ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> > > -- Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] filter-index
Thank you. Anyway: You get my point about wrapping filter-index such that you can get a word that throws away the element? USING: kernel sequences.extras fry ; : filter-index' '[ [ nip @ ] filter-index ] call ; inline On Mon, Apr 15, 2013 at 12:24 PM, mr w wrote: > On Sun, Apr 14, 2013 at 9:43 PM, Loryn Jenkins wrote: > > I'm not sure about filter-index - I don't see any documentation about > that > > word. > > http://docs.factorcode.org/content/word-filter-index,sequences.extras.html > > > -- > Precog is a next-generation analytics platform capable of advanced > analytics on semi-structured data. The platform includes APIs for building > apps and a phenomenal toolset for data science. Developers can use > our toolset for easy data analysis & visualization. Get a free account! > http://www2.precog.com/precogplatform/slashdotnewsletter > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] filter-index
I'm not sure about filter-index - I don't see any documentation about that word. But here's a version of map-index that fulfils your request: USING: kernel sequences fry ; : map-index' ( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq ) '[ [ nip @ ] map-index ] call ; inline Loryn Jenkins On Mon, Apr 15, 2013 at 11:12 AM, mr w wrote: > Is there a version of filter-index that only puts the index on the > stack, without the corresponding element? > > > -- > Precog is a next-generation analytics platform capable of advanced > analytics on semi-structured data. The platform includes APIs for building > apps and a phenomenal toolset for data science. Developers can use > our toolset for easy data analysis & visualization. Get a free account! > http://www2.precog.com/precogplatform/slashdotnewsletter > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > -- Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Request for assistance in understanding the working of cartesian-product
Thank you for the invitation and orientation. — Sent from Mailbox for iPhone On Tue, Apr 2, 2013 at 8:41 AM, John Benediktsson wrote: > Ideally it could be both elegant and fast. > Part of the reason the make version is faster is likely due to the use of > an accumulator that avoids creation of intermediate arrays (e.g., "map > concat" creates a first array ("map") then creates a second array to hold > all the values when flattening the first array ("concat"). > I think trying the simplest construct that solves the problem is a good > first approach (thus the "cartesian-product cartesian-product"), but if you > want more speed, you could create an accumulator and do it all in one loop: > : 2cartesian-map ( ... seq1 seq2 seq3 quot: ( ... elt1 elt2 elt3 -- ... > newelt ) -- ... newseq ) > V{ } clone [ > [ push ] curry compose [ > [ with with each ] 2curry with each > ] 3curry each > ] keep ; inline > : 2cartesian-product ( ... seq1 seq2 seq3 -- ... newseq ) > [ { } 3sequence ] 2cartesian-map ; > This is much faster on a simple benchmark: > ! your version > Running time: 2.062021414 seconds > ! this new version > Running time: 1.218346195 seconds > It could even be faster if you preallocate the vector knowing that the > output will be "len(seq1) * len(seq2) * len(seq3)" in size. Also, as an > API, you might consider returning an array, which is particularly nice if > the vector size is preallocated because "{ } like" is a fast operation in > that case (no resizing of the underlying array necessary). > If you'd like to make contributions, we'd welcome them. Generally we are > flexible about putting things in $factor/extra/, it should have some tests, > but we are flexible on style and performance. It's a nice way to > experiment with new ideas or iterate on solutions before we add them to the > more "standard library" in basis/ or core/. > Best, > John. > On Mon, Apr 1, 2013 at 1:43 PM, Loryn Jenkins wrote: >> And by "why is the ugly code faster", what I mean to ask is: If the code >> were submitted for inclusion into the Factor libraries: >> A. Would the elegant code by chosen over the ugly code, regardless of >> performance? >> B. Would the evaluator want to optimise the elegant code before approving >> it? >> >> What's the culture of elegance vs performance? (Saith I: Given that I >> notice both the extreme level of abstraction and elegance of the existing >> code base! :-) ) >> >> Loryn Jenkins >> >> >> On Tue, Apr 2, 2013 at 7:33 AM, Loryn Jenkins wrote: >> >>> Hmm, thanks. I must've been tired! >>> >>> Firstly, John: How did you perceive such an elegant solution? Is this >>> simply "experience", or were you looking at the problem in a certain light? >>> >>> Secondly, why is it the drop-dead ugly version outperforms the elegant >>> version by so much (~ 2.7 times). >>> >>> Relative timings: >>> gc [ 100,000 [ { 1 2 3 4 5 6 7 8 9 10 } dup dup 2cartesian-product drop >>> ] times ] time >>> -->32.070791587 >>> >>> gc [ 100,000 [ { 1 2 3 4 5 6 7 8 9 10 } dup dup 2-cartesian-product drop >>> ] times ] time >>> --> 11.547108682 >>> >>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>> cartesian-product cartesian-product concat >>> [ first2 swap '[ _ prefix ] map ] map concat ; >>> >>> : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) >>> cartesian-product cartesian-product concat >>> [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ swap >>> prefix ] dip swap , , ] each >>> ] V{ } make ; >>> >>> Loryn Jenkins >>> >>> >>> On Tue, Apr 2, 2013 at 1:27 AM, John Benediktsson wrote: >>> >>>> Just call "concat" again; >>>> >>>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>>> cartesian-product cartesian-product concat >>>> [ first2 swap '[ _ prefix ] map ] map concat ; >>>> >>>> >>>> IN: scratchpad { 1 2 } { 3 4 } { 5 6 } 2cartesian-product . >>>> { >>>> { 1 3 5 } >>>> { 1 3 6 } >>>> { 1 4 5 } >>>> { 1 4 6 } >>>> { 2 3 5 } >>>> { 2 3 6 } >>>> { 2 4 5 } >>>> { 2 4 6 } >>>> } >>>> >>>> >>>> >>>>
Re: [Factor-talk] Request for assistance in understanding the working of cartesian-product
And by "why is the ugly code faster", what I mean to ask is: If the code were submitted for inclusion into the Factor libraries: A. Would the elegant code by chosen over the ugly code, regardless of performance? B. Would the evaluator want to optimise the elegant code before approving it? What's the culture of elegance vs performance? (Saith I: Given that I notice both the extreme level of abstraction and elegance of the existing code base! :-) ) Loryn Jenkins On Tue, Apr 2, 2013 at 7:33 AM, Loryn Jenkins wrote: > Hmm, thanks. I must've been tired! > > Firstly, John: How did you perceive such an elegant solution? Is this > simply "experience", or were you looking at the problem in a certain light? > > Secondly, why is it the drop-dead ugly version outperforms the elegant > version by so much (~ 2.7 times). > > Relative timings: > gc [ 100,000 [ { 1 2 3 4 5 6 7 8 9 10 } dup dup 2cartesian-product drop ] > times ] time > -->32.070791587 > > gc [ 100,000 [ { 1 2 3 4 5 6 7 8 9 10 } dup dup 2-cartesian-product drop > ] times ] time > --> 11.547108682 > > : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) > cartesian-product cartesian-product concat > [ first2 swap '[ _ prefix ] map ] map concat ; > > : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) > cartesian-product cartesian-product concat > [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ swap > prefix ] dip swap , , ] each > ] V{ } make ; > > Loryn Jenkins > > > On Tue, Apr 2, 2013 at 1:27 AM, John Benediktsson wrote: > >> Just call "concat" again; >> >> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >> cartesian-product cartesian-product concat >> [ first2 swap '[ _ prefix ] map ] map concat ; >> >> >> IN: scratchpad { 1 2 } { 3 4 } { 5 6 } 2cartesian-product . >> { >> { 1 3 5 } >> { 1 3 6 } >> { 1 4 5 } >> { 1 4 6 } >> { 2 3 5 } >> { 2 3 6 } >> { 2 4 5 } >> { 2 4 6 } >> } >> >> >> >> >> >> On Mon, Apr 1, 2013 at 7:25 AM, Loryn Jenkins wrote: >> >>> Thank you! >>> >>> That's certainly cleaner. >>> >>> Just needed to flatten the output. I think I've seen a single word >>> that'll do that for me, but I can't remember what it is just now. unzip and >>> union will have to do for this morning. >>> >>> Thanks for your help both, Rupert and John. >>> >>> USING: USING: kernel sequences vectors assocs sets >>> >>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>> cartesian-product cartesian-product concat >>> [ first2 swap '[ _ prefix ] map ] map unzip union ; >>> >>> >>> Good night! >>> >>> >>> On Tue, Apr 2, 2013 at 1:07 AM, John Benediktsson wrote: >>> >>>> Or, alternatively doing the concat first: >>>> >>>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>>> cartesian-product cartesian-product concat >>>> [ first2 swap '[ _ prefix ] map ] map ; >>>> >>>> >>>> >>>> On Mon, Apr 1, 2013 at 7:06 AM, John Benediktsson wrote: >>>> >>>>> Instead of using make, you can do this which looks cleaner: >>>>> >>>>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>>>> cartesian-product cartesian-product [ >>>>> [ first2 swap '[ _ prefix ] map ] map >>>>> ] map concat ; >>>>> >>>>> >>>>> >>>>> On Mon, Apr 1, 2013 at 6:59 AM, Loryn Jenkins wrote: >>>>> >>>>>> Thanks, Rupert. >>>>>> >>>>>> I followed your suggestion, and managed to get it working. :-) >>>>>> >>>>>> USING: kernel sequences vectors make >>>>>> >>>>>> : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) >>>>>> cartesian-product cartesian-product concat >>>>>> [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ >>>>>> swap prefix ] dip swap , , ] each >>>>>> ] V{ } make ; >>>>>> >>>>>> Loryn Jenkins >>>>>> >>>>>> >>>>>> On Mon, Apr 1, 2013 at 11:17 PM, Rupert Swarbrick < >>>>>> rswarbr...@gmail.com> wrote: >>>>>> >>>&g
Re: [Factor-talk] Request for assistance in understanding the working of cartesian-product
Hmm, thanks. I must've been tired! Firstly, John: How did you perceive such an elegant solution? Is this simply "experience", or were you looking at the problem in a certain light? Secondly, why is it the drop-dead ugly version outperforms the elegant version by so much (~ 2.7 times). Relative timings: gc [ 100,000 [ { 1 2 3 4 5 6 7 8 9 10 } dup dup 2cartesian-product drop ] times ] time -->32.070791587 gc [ 100,000 [ { 1 2 3 4 5 6 7 8 9 10 } dup dup 2-cartesian-product drop ] times ] time --> 11.547108682 : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) cartesian-product cartesian-product concat [ first2 swap '[ _ prefix ] map ] map concat ; : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) cartesian-product cartesian-product concat [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ swap prefix ] dip swap , , ] each ] V{ } make ; Loryn Jenkins On Tue, Apr 2, 2013 at 1:27 AM, John Benediktsson wrote: > Just call "concat" again; > > : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) > cartesian-product cartesian-product concat > [ first2 swap '[ _ prefix ] map ] map concat ; > > > IN: scratchpad { 1 2 } { 3 4 } { 5 6 } 2cartesian-product . > { > { 1 3 5 } > { 1 3 6 } > { 1 4 5 } > { 1 4 6 } > { 2 3 5 } > { 2 3 6 } > { 2 4 5 } > { 2 4 6 } > } > > > > > > On Mon, Apr 1, 2013 at 7:25 AM, Loryn Jenkins wrote: > >> Thank you! >> >> That's certainly cleaner. >> >> Just needed to flatten the output. I think I've seen a single word >> that'll do that for me, but I can't remember what it is just now. unzip and >> union will have to do for this morning. >> >> Thanks for your help both, Rupert and John. >> >> USING: USING: kernel sequences vectors assocs sets >> >> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >> cartesian-product cartesian-product concat >> [ first2 swap '[ _ prefix ] map ] map unzip union ; >> >> >> Good night! >> >> >> On Tue, Apr 2, 2013 at 1:07 AM, John Benediktsson wrote: >> >>> Or, alternatively doing the concat first: >>> >>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>> cartesian-product cartesian-product concat >>> [ first2 swap '[ _ prefix ] map ] map ; >>> >>> >>> >>> On Mon, Apr 1, 2013 at 7:06 AM, John Benediktsson wrote: >>> >>>> Instead of using make, you can do this which looks cleaner: >>>> >>>> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >>>> cartesian-product cartesian-product [ >>>> [ first2 swap '[ _ prefix ] map ] map >>>> ] map concat ; >>>> >>>> >>>> >>>> On Mon, Apr 1, 2013 at 6:59 AM, Loryn Jenkins wrote: >>>> >>>>> Thanks, Rupert. >>>>> >>>>> I followed your suggestion, and managed to get it working. :-) >>>>> >>>>> USING: kernel sequences vectors make >>>>> >>>>> : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) >>>>> cartesian-product cartesian-product concat >>>>> [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ swap >>>>> prefix ] dip swap , , ] each >>>>> ] V{ } make ; >>>>> >>>>> Loryn Jenkins >>>>> >>>>> >>>>> On Mon, Apr 1, 2013 at 11:17 PM, Rupert Swarbrick < >>>>> rswarbr...@gmail.com> wrote: >>>>> >>>>>> Loryn Jenkins writes: >>>>>> > Hi >>>>>> > >>>>>> > I'm attempting to adapt the code for cartesian-product into >>>>>> > 2cartesian-product, in order to produce the cartesian product of 3 >>>>>> > sequences. >>>>>> >>>>>> I'm afraid I haven't got time to properly look at your code, but don't >>>>>> forget that the cartesian product is associative. That is: >>>>>> >>>>>> (A × B) × C = A × (B × C) >>>>>> >>>>>> and either of these two makes sense for the cartesian product of three >>>>>> sets. In your case, this means that >>>>>> >>>>>> { 1 2 } { 3 4 } { 5 6 } cartesian-product cartesian-product >>>>>> >>>>>> will almost do what you want (it's the right hand side of
Re: [Factor-talk] Request for assistance in understanding the working of cartesian-product
Thank you! That's certainly cleaner. Just needed to flatten the output. I think I've seen a single word that'll do that for me, but I can't remember what it is just now. unzip and union will have to do for this morning. Thanks for your help both, Rupert and John. USING: USING: kernel sequences vectors assocs sets : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) cartesian-product cartesian-product concat [ first2 swap '[ _ prefix ] map ] map unzip union ; Good night! On Tue, Apr 2, 2013 at 1:07 AM, John Benediktsson wrote: > Or, alternatively doing the concat first: > > : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) > cartesian-product cartesian-product concat > [ first2 swap '[ _ prefix ] map ] map ; > > > > On Mon, Apr 1, 2013 at 7:06 AM, John Benediktsson wrote: > >> Instead of using make, you can do this which looks cleaner: >> >> : 2cartesian-product ( seq1 seq2 seq3 -- newseq ) >> cartesian-product cartesian-product [ >> [ first2 swap '[ _ prefix ] map ] map >> ] map concat ; >> >> >> >> On Mon, Apr 1, 2013 at 6:59 AM, Loryn Jenkins wrote: >> >>> Thanks, Rupert. >>> >>> I followed your suggestion, and managed to get it working. :-) >>> >>> USING: kernel sequences vectors make >>> >>> : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) >>> cartesian-product cartesian-product concat >>> [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ swap >>> prefix ] dip swap , , ] each >>> ] V{ } make ; >>> >>> Loryn Jenkins >>> >>> >>> On Mon, Apr 1, 2013 at 11:17 PM, Rupert Swarbrick >>> wrote: >>> >>>> Loryn Jenkins writes: >>>> > Hi >>>> > >>>> > I'm attempting to adapt the code for cartesian-product into >>>> > 2cartesian-product, in order to produce the cartesian product of 3 >>>> > sequences. >>>> >>>> I'm afraid I haven't got time to properly look at your code, but don't >>>> forget that the cartesian product is associative. That is: >>>> >>>> (A × B) × C = A × (B × C) >>>> >>>> and either of these two makes sense for the cartesian product of three >>>> sets. In your case, this means that >>>> >>>> { 1 2 } { 3 4 } { 5 6 } cartesian-product cartesian-product >>>> >>>> will almost do what you want (it's the right hand side of the equation >>>> above). But the nesting won't be quite right, since you'll have elements >>>> that look like { 1 { 3 5 } }, so you can fix that with something like >>>> >>>> [ first2 first2 ] map >>>> >>>> I think (untested). >>>> >>>> Rupert >>>> >>>> >>>> -- >>>> Own the Future-Intel® Level Up Game Demo Contest 2013 >>>> Rise to greatness in Intel's independent game demo contest. >>>> Compete for recognition, cash, and the chance to get your game >>>> on Steam. $5K grand prize plus 10 genre and skill prizes. >>>> Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d >>>> ___ >>>> Factor-talk mailing list >>>> Factor-talk@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/factor-talk >>>> >>>> >>> >>> >>> -- >>> Own the Future-Intel® Level Up Game Demo Contest 2013 >>> Rise to greatness in Intel's independent game demo contest. >>> Compete for recognition, cash, and the chance to get your game >>> on Steam. $5K grand prize plus 10 genre and skill prizes. >>> Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d >>> ___ >>> Factor-talk mailing list >>> Factor-talk@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/factor-talk >>> >>> >> > > > -- > Own the Future-Intel® Level Up Game Demo Contest 2013 > Rise to greatness in Intel's independent game demo contest. > Compete for recognition, cash, and the chance to get your game > on Steam. $5K grand prize plus 10 genre and skill prizes. > Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > -- Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Request for assistance in understanding the working of cartesian-product
Thanks, Rupert. I followed your suggestion, and managed to get it working. :-) USING: kernel sequences vectors make : 2-cartesian-product ( seq1 seq2 seq3 -- newseq ) cartesian-product cartesian-product concat [ [ first2 first2 [ >vector ] bi@ [ over ] dip swap prefix [ swap prefix ] dip swap , , ] each ] V{ } make ; Loryn Jenkins On Mon, Apr 1, 2013 at 11:17 PM, Rupert Swarbrick wrote: > Loryn Jenkins writes: > > Hi > > > > I'm attempting to adapt the code for cartesian-product into > > 2cartesian-product, in order to produce the cartesian product of 3 > > sequences. > > I'm afraid I haven't got time to properly look at your code, but don't > forget that the cartesian product is associative. That is: > > (A × B) × C = A × (B × C) > > and either of these two makes sense for the cartesian product of three > sets. In your case, this means that > > { 1 2 } { 3 4 } { 5 6 } cartesian-product cartesian-product > > will almost do what you want (it's the right hand side of the equation > above). But the nesting won't be quite right, since you'll have elements > that look like { 1 { 3 5 } }, so you can fix that with something like > > [ first2 first2 ] map > > I think (untested). > > Rupert > > > -- > Own the Future-Intel® Level Up Game Demo Contest 2013 > Rise to greatness in Intel's independent game demo contest. > Compete for recognition, cash, and the chance to get your game > on Steam. $5K grand prize plus 10 genre and skill prizes. > Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > -- Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Request for assistance in understanding the working of cartesian-product
Hi I'm attempting to adapt the code for cartesian-product into 2cartesian-product, in order to produce the cartesian product of 3 sequences. This is the deepest I've gotten into currying and composing, and I'm not quite sure I grok exactly how these words are working. If you could shine a light on a concept I'm missing, I'd appreciate it. I've pasted the code here: http://paste.factorcode.org/paste?id=2888 The output of my debugging session is here: https://www.evernote.com/pub/lorynjenkins/factorn-cartesian-product The debugging session was initialised with: 1 10 [a,b] [ ] map dup dup 2cartesian-product Loryn Jenkins -- Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Speedup to math.functions round
Apologies. This version contains amended run data. Hi I just noticed that math.functions round can be sped up. Compare the version from math.functions vs the comparison version. : round ( x -- y ) dup sgn 2 / + truncate ; inline : round2 ( x -- y ) dup sgn 0.5 * + truncate ; inline Testing = warm up execution of each statement, followed by 3 executions of gc [ 1 [ 42.3 round drop ] times ] time gc [ 1 [ 42.3 round2 drop ] times ] time round results = { 0.004365148 0.004394427 0.004361589 } average = 0.0044 round2 results = { 0.001903133 0.001894752 0.001913334 } average = 0.0019 averaged results show 2.32 times speedup on Mac OS X 10.8.3 2 GHz Intel Core 2 Duo Loryn Jenkins -- Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Speedup to math.functions round
Hi I just noticed that math.functions round can be sped up. Compare the version from math.functions vs the comparison version. : round ( x -- y ) dup sgn 2 / + truncate ; inline : round2 ( x -- y ) dup sgn 0.5 * + truncate ; inline Testing = warm up execution of each statement, followed by 3 executions of gc [ 1 [ 42.3 round drop ] times ] time gc [ 1 [ 42.3 round2 drop ] times ] time round results = { 0.004365148 0.004394427 0.001917139 } average = 0.0036 round2 results = { 0.001903133 0.001894752 0.001913334 } average = 0.0019 averaged results show 1.89 times speedup on Mac OS X 10.8.3 2 GHz Intel Core 2 Duo Loryn Jenkins -- Own the Future-Intel® Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] using PREDICATEs
Based on Joe's confirmation that predicate types aren't intended to be directly instantiated, I would've expected a compile error: "Illegal constructor: cannot construct predicate classes." Or somesuch. Thanks for the suggestion regarding the better square constructor. Best regards, Loryn Jenkins On 09/03/2013, at 1:38 AM, John Benediktsson wrote: > What do you think it should do instead? > > Perhaps set both slots on rectangle and then throw an error if the predicate > is invalid? > > Although a better square constructor would only take one length: > > : ( n -- square ) dup ; inline > > > > > > On Fri, Mar 8, 2013 at 12:26 AM, Loryn Jenkins wrote: >> I was playing around with predicates today. >> >> It seems that when I attempt to run a default constructor directly on a >> predicate type, I get a macro expansion error. >> >> I quickly grepped through the codebase in basis and extras, and couldn't >> find an instance where a constructor was used off a predicate class. >> >> Can I assume that predicate types are not intended to be instantiated >> directly? Or am I assuming that erroneously? >> >> >> >> TUPLE: rectangle width height ; >> PREDICATE: square < rectangle [ width>> ] [ height>> ] bi = ; >> C: rectangle >> C: square >> >> 3 3 >> --> 12 >> >> 3 3 >> --> The word cannot be executed because it failed to compile >> >> Macro expansion of “boa” threw an error >> >> The error was: >> Assertion failed >> got0 >> expect 1 >> >> [Traceback] >> >> -- >> Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester >> Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the >> endpoint security space. For insight on selecting the right partner to >> tackle endpoint security challenges, access the full report. >> http://p.sf.net/sfu/symantec-dev2dev >> ___ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk > > -- > Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester > Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the > endpoint security space. For insight on selecting the right partner to > tackle endpoint security challenges, access the full report. > http://p.sf.net/sfu/symantec-dev2dev > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk -- Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] using PREDICATEs
I was playing around with predicates today. It seems that when I attempt to run a default constructor directly on a predicate type, I get a macro expansion error. I quickly grepped through the codebase in basis and extras, and couldn't find an instance where a constructor was used off a predicate class. Can I assume that predicate types are not intended to be instantiated directly? Or am I assuming that erroneously? TUPLE: rectangle width height ; PREDICATE: square < rectangle [ width>> ] [ height>> ] bi = ; C: rectangle C: square 3 3 --> 12 3 3 --> The word cannot be executed because it failed to compile Macro expansion of “boa” threw an error The error was: Assertion failed got0 expect 1 [Traceback] -- Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] UNIX signal #8 (SIGFPE) when using iota
Hi I've got a bunch of very similar words, several of which work, and some fail. Each failure throws a UNIX signal #8 (SIGFPE). I'm struggling to see the difference between the words that work, and those that fail. Code is on the paste bin: http://paste.factorcode.org/paste?id=2863 -- Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk