Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Introduction to stack languages, part 3: Self-defined syntax
Post Body

This post will probably introduce the most new information in the series, so it's worth first reading about the basics (part 1) and stack shuffling (part 2) to get familiar with the concepts. Also, per a reader suggestion, I'm naming the language described here "Reverse Polish" (RPL), even though it's heavily English-based in vocabulary.

(License: This might be relevant since I'm introducing some slightly novel content. The content of this series and Reverse Polish are released under a Creative Commons Attribution 4.0 International license, which basically means you can do whatever with appropriate credit.)


The effect of a word on a developing phrase is its syntactic effect. This is subtly different from the semantic effects we've been discussing so far, but wasn't relevant until now because all the syntactic effects were to simply append a context-independent semantic effect to the overall effect of the phrase. That is, if we said copy in a phrase, the effect of duplicating the top item is added to the overall effect.

We're talking about phrases in general now because of quotation. A quote is written [ … ], such as [ 3 ] (which has effect >> [ 3 ]) and we can say it to evoke its meaning (which has whatever effect the quote has). Quotes can also appear inside each other. An example phrase is

[ 4 2 - ] copy ( [ 4 2 - ] [ 4 2 - ] )
say            ( [ 4 2 - ] 2         )
swap say       ( 2 2                 )

All this might seem magical, but it's driven by the syntactic meaning of the words [ and ]; that's right, they're words. Without getting into too much detail, the syntactic effect of [ is to change how words are interpreted by applying their syntactic effects to a different quote from the main one, and ] inserts this quote into the main one. I'll reserve an in-depth explanation to an appendix, but it suffices to say that these words work how you would expect them to, and this is all possible because of syntactic effects.

Now we can introduce words for introducing words, specifically on, to, and as. (They are also syntactic words, but they're even more mechanically sophisticated than [ and ], so that again gets its own appendix.) Each of them takes the top item from the stack, "reads" the next name in the phrase, and…

  • as defines the name to add the item to the stack.
  • to defines the name to have the item as its semantic effect.
  • on defines the name to have the item as its syntactic effect.

as is extremely useful for defining temporary names for things, or just new names for values, like 2 as twain. It can be chained to name multiple items at once, like 1 0 as zero as one. And it works inside quotes.

I'll illustrate how to works by defining all the single-stack shuffling words from part 2, plus some bonuses:

[ as A        A A   ] to copy
[ as A as B   B A B ] to over
[ as A as B   A B   ] to swap
[ as A              ] to drop
[ as A as B as C   B A C   ] to dig
[ as A as B as C   A C B   ] to dip
[ as A as B as C   C B A C ] to 3rd
[ copy * ] to square
[ copy copy * * ] to cube
[ 0 swap - ] to negate
[ 1 swap / ] to reciprocal

As a side note, to also works within quotes (like as), but on is a little more…nuanced. (Long story short, using on in a quote can lead to a run-in with causality.)

As you can see, these few words and concepts give us a lot of power to extend the language from within.


If you're liking the series, I wouldn't mind if you shared it with others who might be interested. I'm probably going to continue writing it regardless of readership since it's fun. The current plan is

  • Appendix 3.A, complete mechanics of quotation words
  • Appendix 3.B, complete mechanics of defining words
  • Appendix 3.C, comparison to historical approaches (i.e. in concatenative programming languages)
  • Part 4: aggregates and combinators
  • Part 5: conversation mechanics and pronouns
  • Part 6: saying unquoted things

The appendices may be released out of order relative to the main sections. Thank you for reading, and please leave your comments!

Author
Account Strength
90%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,207
Link Karma
718
Comment Karma
3,489
Profile updated: 1 day ago
Posts updated: 7 months ago
/r/sika (en) [es fr ja]

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 years ago