Hi,
you can get rid of most of the repetition by defining a word that operates
on lists instead of using tri/tri@, for example:

: subseqs ( seq indices -- subseqs )
swap [ subseq ] curry { } assoc>map ;

"NAXIS   =                    3 / number of data
axes                            "
{ { 0 8 } { 10 30 } { 33 80 } } subseqs

Also, [ 32 = ] trim is maybe more readable written as [ CHAR: space = ]
trim, or if you also want to trim tabs and \n\r, the library defines [
blank? ] trim

So for example, you can use:
"NAXIS   =                    3 / number of data
axes                            "
{ { 0 8 } { 10 30 } { 33 80 } } subseqs [ [ blank? ] trim ] map first3

Note that the question you are asking if farily low level, so you might
find better methods to extract the info you want (for example split-harvest
from splitting.extras could be useful in your case)

Cheers,
Jon


On Sun, Feb 9, 2014 at 2:41 PM, Jean-Marc Lugrin <hb9...@lugrin.ch> wrote:

> 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@
>
> This works, does the split and trim, but I am not too happy with the
> multiple swaps. I would liek to keep stack manipulation to the minimum for
> clarity.
> Any recommendation ?
> hb9duj
>
>
>
> ------------------------------------------------------------------------------
> 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
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
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
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to