You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.1 KiB

set sep [string repeat - 50]
puts stderr $sep
#display pipeline in alternative color
proc pipeputs {pipeline} {
puts stdout [a+ purple bold]$pipeline[a+]
}
set data1 d1
set data2 [list a b c]
x/0.= list "
item1
[list $data1]
[list $data2]
$data2
[pwd]
"
puts stdout "7 element list built with x/0.=list \" (multiline) \" syntax"
puts stdout "x: $x"
puts stdout "len: [llength $x]"
puts stderr $sep
puts stdout "Using linelist to restrict to the intended 5 elements"
out.= = $x |> linelist
puts stdout "out.= = \$x |> linelist"
puts stdout "out: $out"
puts stdout "len: [llength $out]"
puts stderr $sep
y.= list "
{[set j aaa]}
{$j etc}
blah
"
puts stdout "y: $y"
puts stderr $sep
puts stdout "building a dict - with some impurities! (pwd)"
puts stdout "Note that the commands in the dict-building string are resolved at pipeline construction time"
puts stdout "To resolve commands at pipeline run-time, we can pass as arguments (see extrakey key), or put them in a script block in the pipeline (see runtimedir key)"
puts stdout "Some alternatives not demonstrated here are to use 'subst' or compose pipelines"
pipeset dictpipe result.= inputdict_with_args,k@keys,p@@k2/patchlevel,etc/@@k4/etc=* "
k1
{dir {[pwd]}}
k2
{patchlevel [info patchlevel]}
k3
{something etc}
k4
{
hmmm well
etc blah
dir {[pwd]}
}
" |> finald,rtkey/@@runtimedir.= {
#a very impure script block!
set origdir [pwd]
set parent [file dirname [pwd]]
cd $parent
dict set data runtimedir [pwd]
cd $origdir
set data
} |@@k4/dir> <| extrakey [pwd] anotherkey foo
puts stdout "dictpipe:"
pipeputs $dictpipe
{*}$dictpipe
puts stdout "dict: $finald"
#todo - a function to repack a nested dict into a flat structure (no linefeeds unless a leaf can't be interpreted as a dict)?
# i.e - k4 is constructed as a string - but we may want to discard the stringrep and rebuild it as a pure list/dict
puts stdout "keys: $k"
puts stdout "k2/patchlevel: $p"
puts stdout "k4/etc: $etc"
puts stdout "runtimedir: $rtkey"
puts stdout "result(k4/dir): $result"
puts stderr $sep
puts stdout "script block comment test (using multiple scripts in segment via implicit pipedata mechanism"
pipeset commentpipe normallist.= rawlist/0.= {
#a not terribly useful comment block
#comments
# etc
#blah
} {inspect -channel stderr -label inspect_no_data $data} {list \
{
data
over here
etc
}
} {
#more comments - but we need to pass the pipeline data through here - so 'set data' required at end.
set data
} |> string trim |> linelist |> .=>2 lmap v {string trim $v}
pipeputs $commentpipe
{*}$commentpipe
puts stdout "rawlist:$rawlist"
puts stdout "normallist:$normallist"
puts stderr $sep
pipeset pipe2 alt.= = $rawlist |> .=>1 lrange 0 end
puts stdout "Alternative interpretation of list data"
puts stdout "pipe2:"
pipeputs $pipe2
{*}$pipe2
puts stdout "alt: $alt"
pipeset pipe3 alt.= = $rawlist |> .=>* list
puts stdout "Or.."
puts stdout "pipe3:"
pipeputs $pipe3
{*}$pipe3
puts stdout "alt: $alt"
puts stdout -done-