Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PARSE

16 views
Skip to first unread message

Mr. Spelunx

unread,
Sep 20, 2022, 12:13:13 PM9/20/22
to
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.
0 new messages