Multiple line text input within a compiling word 
Author Message
 Multiple line text input within a compiling word

Is there an _obvious_ Standard way to input multiple lines of
text? That is, I would like to define a Standard word

        : multi"   \ put everything after space, up to
                        \ a trailing " , across cr/lf's,
                        \ in a buffer or string in some Standard place.

                YOUR CODE HERE  ;

There is no reason except custom why the stop character has to
be a " .  That is,  the word should operate like the phrase

        char " word

except the latter reads up to a cr/lf and gives no Standard
way to find out what was the last character read (except by
playing with TIB and >IN --supposedly obsolescent words, and
ones that by their very nature lead to environmental dependen-
cies).

I can do what I want on the systems I work with--that is not the
point. I am trying to discover a Standard, completely portable
method that will work within a word being compiled, as in my
FORmula TRANslator (so I can finish the port to ANS Forth with
as few environmental dependencies as possible):

        : f"       multi"  buffer swap $!  fortran ; immediate
        : test   f" A=B+C*D
                       -ACOSH(U/PI)"  ;

see test


Thanks for any help.

--
Julian V. Noble



Tue, 19 Jan 1999 03:00:00 GMT  
 Multiple line text input within a compiling word

COMMENT


Quote:
> Is there an _obvious_ Standard way to input multiple lines of
> text?

Good question, with a simple answer: No.  (For the reasons you
give in a later paragraph.)  So let's look for a unobvious way.

Let's posit string catenation S+ as an aid.  Let's also agree
that the set of lines will be terminated by " at the end of line.

I'm looking forward to the discussion.

Wil Baden Costa Mesa, California

[THEN]

: MULTI"                               ( -- s u )
      0 0                                     ( s u)


      WHILE S+                                ( s u)
            REFILL 0= ABORT" (Premature EOF) "
      REPEAT                                  ( s u s2 u2)
      1-
      S+                                      ( s u)
      REFILL DROP
      POSTPONE SLITERAL
; IMMEDIATE

: TEST MULTI" This is
 a test
 of multi-line input."
      TYPE
;



Tue, 19 Jan 1999 03:00:00 GMT  
 Multiple line text input within a compiling word


Quote:
>There is no reason except custom why the stop character has to
>be a " .  That is,  the word should operate like the phrase
>    char " word
>except the latter reads up to a cr/lf and gives no Standard

I think "allowed to read" would be a better wording.
IMHO the standard does not require WORD to stop at cr/lf.

Quote:
>way to find out what was the last character read (except by
>playing with TIB and >IN --supposedly obsolescent words, and
>ones that by their very nature lead to environmental dependen-
>cies).

Andras


Wed, 20 Jan 1999 03:00:00 GMT  
 Multiple line text input within a compiling word

0 [IF]

W.Baden writes Re: Multiple line text input within a compiling word

[ .. ]

Quote:
> I'm looking forward to the discussion.

Key to MULTI" is the use of REFILL. Once you have that, all definitions
will look pretty much the same.


enable the use of MULTI" from the terminal. Two: it would be nice if the
delimiter were passed in as a parameter. Not being able to use the delimiter
character in text is a problem I encounter very often.

The code Wil showed may have problems with empty strings and strings that
are followed by other Forth text (on the same line).

In the alternative below I used $+ instead of S+ . The use of REPEATED instead
of REPEAT THEN is self-explanatory.

[THEN]

\ Should be beheaded.
: (LINES)                                     ( delimiter -- s u )
      LOCALS| delimiter |      
      S" "                                    ( s u)
      BEGIN
         delimiter PARSE DUP
      WHILE

      WHILE
         $+                                   ( s u)
         REFILL 0= ABORT" (Premature EOF) "
      REPEATED                                ( s u s2 u2)
      $+ ;

: LINES  \ execution:   ( delimiter -- s u )  
         \ compilation: ( delimiter -- )
        (LINES)

: LINES" \ execution:   ( delimiter -- s u )  
         \ compilation: ( delimiter -- )
        [CHAR] "  POSTPONE LINES ; IMMEDIATE

LINES" This is
 an interactive test
 of multi-line input." CR TYPE
'_' LINES This is
 the second part of that
 interpreted test
 of multi-line input._    
CR TYPE

: TEST LINES" This is
 a compiled test
 of multi-line input."  ( end)
 CR TYPE
 [ '_' ] LINES This is
 the second part of that
 compiled test
 of multi-line input._ CR TYPE
 LINES" " 2DROP
 LINES" ..." TYPE ; TEST

\ -marcel



Wed, 20 Jan 1999 03:00:00 GMT  
 Multiple line text input within a compiling word

: COMMENT POSTPONE [ELSE] ; IMMEDIATE

COMMENT


Quote:
> There is no reason except custom why the stop character has to
> be a " .  That is,  the word should operate like the phrase

>     char " word

> except the latter reads up to a cr/lf and gives no Standard
> way to find out what was the last character read (except by
> playing with TIB and >IN --supposedly obsolescent words, and
> ones that by their very nature lead to environmental dependen-
> cies).

(>IN is not obsolescent.)

I was too hasty in accepting the claim above, because that's
what I thought as well.

Let's write a version of PARSE that tells us whether it found
the delimiter or read up to end-of-buffer.  This should work for
source in blocks also.

If it didn't find the delimiter then you must use REFILL before
picking up the next piece.

[THEN]

: PARSE?                      ( char -- s u flag )

            PARSE                         ( s u)
      R> OVER + SOURCE NIP = NOT          ( s u flag )
;

( You may use <> or your definition of NOT .)



Thu, 21 Jan 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Replacing text within a line

2. Compile-a-line model & state-smart words

3. NeedHelp : find a string within lines of text.

4. Reading more than one line of input from a text file

5. Multiple text lines in browse list

6. How to replace multiple-line text

7. Text widget --screen lines vs. text lines

8. Multiple text-lines in buttons

9. How to replace one or two words with one word with one line of awk code

10. find a key word and delete 5 lines before it and 5 lines after this

11. (postpone babble: using postpone in interpret-mode to compile compile-only words)

12. Centering Text Vertically Within Same Text Field

 

 
Powered by phpBB® Forum Software