2014-02-09 14:41 GMT+01:00 Jean-Marc Lugrin <[email protected]>:
> Hi,
> I need to split a string at fixed locations (some of the locations may
> eventully be calculated, like with a lookup of '/', but at first
> approximation fixed locations are ok).
>
> I came with this example string and quotatiom:
>
> "NAXIS = 3 / number of data axes
> "
> [ 0 swap 8 swap subseq ] [ 10 swap 30 swap subseq ] [ 33 swap 80 swap
> subseq ] tri [ [ 32 = ] trim ] tri@
Some more variants for you to consider:
Using fry:
: subseqs ( indices seq -- subseqs )
'[ first2 _ subseq [ blank? ] trim ] map ;
Using with:
: subseqs ( seq indices -- subseqs )
[ first2 rot subseq [ blank? ] trim ] with map ;
Also Jon's idea of finding higher-level splitting words to work with
is really good. E.g.
IN: "NAXIS = 3 / number of data axes "
IN: "/=" split [ [ blank? ] trim ] map .
{ "NAXIS" "3" "number of data axes" }
--
mvh/best regards Björn Lindqvist
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk