Hi,

I did a quick hack for this:

MACRO: cond-case ( assoc -- )
        [ dup callable? not
                [
                        [ first '[ dup @ ] ]
                        [ second '[ drop @ ] ] bi 2array
                ]
                [ '[ drop @ ] ] if
        ] map '[ _  cond ] ;

I guess someone can do a better code by coding a more specific cond.

my 2 cents...

At Tue, 19 Apr 2011 20:49:51 +0100,
"Tadhg O'Meara" <tome...@gmail.com> wrote:
> 
> I'm looking for a word that's like cond but doesn't need all the dups
> and drops for the simple case where you want to check various
> properties of the object on the stack and call an appropriate
> quotation. So instead of
> 
> {
>     { [ dup 0 > ] [ drop "positive" ] }
>     { [ dup 0 < ] [ drop "negative" ] }
>     [ drop "zero" ]
> } cond
> 
> I could use
> 
> {
>     { [ 0 > ] [ "positive" ] }
>     { [ 0 < ] [ "negative" ] }
>     [ "zero" ]
> } cond-case
> 
> I tried to write a cond-case word that adds the necessary dups and
> drops to a cond assoc but this results in a error.
> 
> USING: arrays combinators kernel quotations sequences ;
> 
> : cond-case ( assoc -- )
>         [ dup callable? not
>                 [
>                         [ first [ dup ] prepose ]
>                         [ second [ drop ] prepose ] bi 2array
>                 ]
>                 [ [ drop ] prepose ] if
>         ] map cond ;
> 
> Error: Cannot apply “cond” to a run-time computed value
> It also says cond is a macro.
> 
> Any ideas?
> 
> Thanks,
> Tadhg
> 
> ------------------------------------------------------------------------------
> Benefiting from Server Virtualization: Beyond Initial Workload 
> Consolidation -- Increasing the use of server virtualization is a top
> priority.Virtualization can reduce costs, simplify management, and improve 
> application availability and disaster protection. Learn more about boosting 
> the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

-- 
Martial Boniou
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to