Your version doesn't preserve any of the lines that are read:

    : readln-skipcomments ( -- )
        [ { [ string? ] [ first CHAR: # = not ] [ ] } 1&& ] [ readln ] do
while ;

If you want the last line (the one where predicate is false and breaks out
of the loop), you could put an object on the stack to test against, like
this:

    : readln-skipcomments ( -- line )
        f [ dup { [ string? ] [ first CHAR: # = not ] [ ] } 1&& ] [ drop
readln ] do while ;

The "do" will drop the ``f``, and then read a line.  The predicate will run
and leave a boolean whether to continue or not.





On Fri, Jan 2, 2015 at 2:36 PM, Mark Green <m...@antelope.nildram.co.uk>
wrote:

> Hi,
>
> Sorry to post yet again! I've been trying to write something to read lines
> from a file while ignoring comments, and have gotten this far:
>
> : readln-skipcomments ( -- line )
>     [ { [ string? ] [ first CHAR: # = not ] [ ] } 1&& ] [ readln ] do
> while ;
>
> The problem is that it seems that while consumes the result of running
> pred, so this ends up not returning anything. If I put a dup into the last
> entry in the 1&&, to leave an extra copy on the stack in case of success,
> then I get a deep error complaining that the stack effect of the inputs of
> 1&&'s internal ifs are unbalanced. If I put the dup after the 1&& in the
> while I get an error that pred is unbalanced. If I put it in the looped
> quotation I get the error that the loop is not balanced by pred. Is there
> any way I can do this?
>
> Mark
>
>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming! The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is
> your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to