2015-09-23 5:46 GMT+02:00 HP Wei <hpwe...@gmail.com>:
> My original issue was to construct the string “cmd1 -a A -b B” and “cmd2 -c
> C”
> in a flexible way so that I can choose to supply (or not supply) those
> argument A, B, C.
> And find a clean way to put everything together into { … } for run-pipeline.

Maybe with some helper words:

: render-command ( cmd args -- string )
    [ dup array? [ " " join ] when ] map " " join " " glue ;

: make-pipeline ( seq -- seq' )
    [ first2 render-command ] map ;

:: special-pipeline ( a-arg b-arg -- pipeline )
    a-arg "def-a" or :> real-a
    b-arg "def-b" or :> real-b
    { { "ls" { } } { "grep" { { "-a" real-a } { "-b" real-b } "--verbose" } } }
    make-pipeline ;

Or simpler:

: special-pipeline ( a-arg b-arg -- pipeline )
    [ "def-a" or ] [ "def-b" or ] bi* "grep -a %s -b %s" sprintf
    "ls" swap 2array ;

IN: scratchpad f f special-pipeline
{ "ls" "grep -a def-a -b def-b" }

Factor doesn't have words with variable number of arguments, so you
supply f instead and then the default is picked.


-- 
mvh/best regards Björn Lindqvist

------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to