Hi to all!
While writing my little factor programs, I often find a situation in
which I have an object,
I test it and if test is ok then some action is performed on it, else it
is simply dropped.

Ex.: (obj on top of stack)
dup test-condition [ do something with obj ] [ drop ] if

I think this would be better expressed this way: (always with obj on top
of stack)
[ do-test ] [ do-action-on-obj ] when-drop

To achieve this, I wrote this word:

: when-drop ( obj question-quot: ( obj -- ? ) true-quot: ( obj -- ) -- )
    -rot dupd call swapd [ call ] [ 2drop ] if ; inline

But documentation claims that swapd and dupd are deprecated, and suggest
to use lexical variables.
So I rewrote this way:

:: when-drop ( obj question-quot: ( ..obj -- ? ) true-quot: ( ..obj -- )
-- )
    obj dup question-quot call [ true-quot call ] [ drop ] if ; inline


Is this useless/redundant or do you think this can be interesting?

thank you all,
michele pes


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to