Groups | Search | Server Info | Login | Register
Groups > comp.lang.logo > #144
| Newsgroups | comp.lang.logo |
|---|---|
| Date | 2022-09-20 09:13 -0700 |
| Message-ID | <7e92166b-79b3-4d7c-aacc-99a80644954bn@googlegroups.com> (permalink) |
| Subject | PARSE |
| From | "Mr. Spelunx" <mrspelunx@gmail.com> |
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.
Back to comp.lang.logo | Previous | Next | Find similar
PARSE "Mr. Spelunx" <mrspelunx@gmail.com> - 2022-09-20 09:13 -0700
csiph-web