Slava Pestov wrote:
> On Sun, Apr 5, 2009 at 6:10 PM, Kyle Cordes <[email protected]> wrote:
>> I am still unhappy with the obtuseness of "tuck - swap", is there a
>> better way to do that?
> 
> Yes. If you have 'a b' on the stack, then 'tuck - swap' gives you 'a-b
> b'. Another way to get this result is [ - ] keep.

Ah, much better.  It is one token longer, but more obvious (to me) what 
it does.

: change ( amount -- coins )
    { 25 10 5 1 }
    [
      [
        [ 2dup >= ] [ [ - ] keep dup , ] while
      drop ] each
    ] { } make nip ;


I now understand Dan's code (pasted below), and like it better still 
because it thinks in lists rather than per-value, and because it needs 
fewer nested quotations, a max-depth of 2 instead of 4.

: change-dan ( amount -- coins )
    { 25 10 5 1 }
    [ [ /mod swap ] map nip ] keep
    [ <repetition> ] 2map concat ;


-- 
Kyle Cordes
http://kylecordes.com

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

Reply via email to