Try using make and , instead of passing an accumulator around on the stack.

Slava

On Sun, Apr 5, 2009 at 4:21 PM, Kyle Cordes <[email protected]> wrote:
> I'm trying to get my head around writing (good?) Factor code. Could
> someone point me in the right direction on the snippet below? Even after
> a few rounds of cleanup, I haven't been able to make it very
> intention-revealing, mostly (maybe?) because of juggling three values on
> the stack.
>
>
> USING: kernel sequences math ;
> IN: coins
>
> <PRIVATE
>
> : make-change-with-coin ( coins cents coin -- coins cents )
> [ 2dup >= ]
>   [ tuck - swap tuck [ prefix ] 2dip ] while
> drop ;
>
> PRIVATE>
>
> : change ( cents -- coins )
> { } swap
> { 25 10 5 1 } [ make-change-with-coin ] each
> drop ;
>
>
>
> ( scratchpad ) 99 change .
> { 1 1 1 1 10 10 25 25 25 }
>
> --
> Kyle Cordes
> http://kylecordes.com
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to