• PARSE

    From Mr. Spelunx@21:1/5 to All on Tue Sep 20 09:13:12 2022
    In Apple Logo (version 1, not Logo II), there is no PARSE primitive. In other Logos, PARSE inputs a word containing spaces and outputs a list, based on that Logo's definition of a word. As far as I know, most Logos delimit words in a list with a Space (
    ASCII 32).

    I thought it would be interesting to write a PARSE procedure for Apple Logo. Here it is:

    TO PARSE :STRING
    OUTPUT PARSER :STRING " []
    END

    TO PARSER :STRING :W :L
    IF EMPTYP :STRING [MAKE "L LPUT :W :L OUTPUT :L]
    IF EQUALP ASCII FIRST :STRING 32
    [MAKE "L LPUT :W :L MAKE "W " MAKE "STRING BUTFIRST :STRING]
    MAKE "W WORD :W FIRST :STRING
    OUTPUT PARSER BUTFIRST :STRING :W :L
    END

    To test this out, I made long word (STRING) that included spaces. To prevent the interpreter from treating spaces as delimiters, they have backslashed (Control-Q on any machine before a IIe).

    ?MAKE "AWAY "A\ WAY\ TO\ JOURNEY.\ A\ WHALER\ JOE.\ AWEIGH\ THE\ ANCHOR.\ AWAY\ WE\ GO.



    To confirm AWAY is a *word* and not a list:

    ?PRINT WORDP :AWAY
    TRUE



    Now to test:

    ?PRINT PARSE :AWAY
    A WAY TO JOURNEY. A WHALER JOE. AWEIGH THE ANCHOR. AWAY WE GO.



    Here's another test: Let's grab each word and print them in a stack.

    TO STACKWORDS :L
    IF EMPTYP :L [STOP]
    PRINT FIRST :L
    STACKWORDS BUTFIRST :L
    END


    ?STACKWORDS PARSE :AWAY
    A
    WAY
    TO
    JOURNEY.
    A
    WHALER
    JOE.
    AWEIGH
    THE
    ANCHOR.
    AWAY
    WE
    GO.


    As a final note, I was hoping somebody would be interested in refining my PARSE procedure or make it more efficient.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)