On Tue, Nov 18, 2008 at 4:41 PM, Mayson Lancaster <[EMAIL PROTECTED]> wrote: > As a Factor newcomer, I'm having some difficulty figuring out how to express > myself idiomatically. > Here's an example, my first crack at a word to return the sum of a sequence > of numbers on the stack. > USING: kernel assocs namespaces math sequences prettyprint ; > IN: mayson > SYMBOL: mysum > : sequence-sum ( seq -- sum ) > 0 mysum set > mysum get [ + mysum set ] curry each mysum get ; > It seems to work, but two things look wrong to me: the (semi-)global > variable, and the necessity of using a curry.
Your version doesn't do the right thing; it merely outputs the last element of a sequence: ( scratchpad ) { 1 2 3 } sequence-sum . 3 ( scratchpad ) { 4 7 -2 } sequence-sum . -2 See if you can figure out why :-) > Are there any reasonably Factorial ways to clean this up? Take a look at some of the code in basis and extra for examples of Factor code. These in particular are quite nice: basis/tools/hexdump basis/base64 basis/smtp extra/roman extra/rot13 extra/time-server Remember that some of these have docs (eg, "smtp" about), and if you see a library word in there you don't understand, you can look up its help in the listener, \ pad-left help Once you feel more adventurous, you can take a look at the web framework ("furnace" about) and the optimizing compiler (basis/compiler/). Both are examples of non-trivial applications written in Factor using a variety of stack idioms. Have fun, Slava ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk