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.

5
Introduction to stack languages, appendix 3.B: Defining words in depth
Post Body

See the rest of the series here. Licensed under CC BY 4.0.


When we want to introduce new concepts in the language we're speaking, it helps to be able to be precise. To illustrate, we can define a word that enquotes the top item of the stack entirely in Reverse Polish:

[ as A [ A ] ] to quote

and a word that links two quotes together:

[ to q to r [ r q ] ] to ;

Things can get interesting very fast:

[ to q [ [ to repeat q repeat ] copy . ] ] to infinitely

so for example [ no ] infinitely . means "no" infinitely many times; it sends a strong message. We can also define the syntactic effect of words with on, so that for example

[ next-word first-letter quote ; ] on letter

lets us say letter a to refer to the letter "a".

To allow all this to happen, the precise syntactic effect of defining words is a little subtle. Let's start with to. Its full syntactic effect is to

  1. take the following word and define it in such a way that its meaning can change while referring to the same definition, and
  2. append an effect that sets this meaning (and removes that from the stack, as usual).

When to appears in normal speech, these two effects occur simultaneously, but in a quote, this means that while the effect of the word will be determined later, all following occurrences will refer to the same term. However, using defining words will overshadow previous definitions, so later occurrences of the word will follow the new definition.

as does almost the same thing, except it effectively quotes the items it receives before setting that to the effect, i.e. 3 as δΈ‰ means the same thing as 3 quote to δΈ‰.

To illustrate, the following examples all mean 2:

2 as A A
2 [ as A ] . A
[ as two ] to set-two   2 set-two   two
2 [ as A A ] 3 as A .
3 [ as A   ] 2 as A . A

What makes on more subtle is that, even though it works the same way, we have to account for how it can change the interpretation of all following words if it appears inside a quote. Let's quickly introduce the word ', which gives the syntactic meaning of the next word. Then

'     [ on syntax-form syntax-form ] .

just adds two numbers since it means [ ] ., but

' [   [ on syntax-form syntax-form ] .

means [ [ ] . if we allow . to apply, but then nothing evokes the quote in the first place, so we aren't left with any clear interpretation. Though its syntactic effect has the same basic form as the other two, it is very different in practice. It's generally a good idea to be cautious of using on in quotes because of this, but we can still consider to as a special case of on if we want; that is, to f means the same thing as as q [ [ q ] ; ] on f.

Anyway, that's all for defining words. If you have any questions, please ask below, and please share these posts if you like them.

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