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.
See the rest of the series here. Licensed under CC BY 4.0.
In Reverse Polish, we have a system that lets us define new words and new syntax as we speak by thinking of words in terms of their syntactic effects. Here are some traditional approaches to get a similar effect; they're programming languages because as far as I know there aren't human languages that do it.
Forth (or at least most traditional Forths)
In Forth, you generally define the meaning (semantic effect) of words directly rather than as a syntactic effect. Unless you want one with a syntactic effect, in which case you have to also mention that the word is immediate
. There are no quotes; instead, whenever a word is defined, its meaning is incrementally compiled at the end of the working list of definitions, and defining words like :
switch from interpreted mode to compiled mode temporarily. ;
works essentially the same as ]
in RPL.
The whole system involves a built-in distinction between two modes of interpretation (interpreted/compiled), two kinds of words (normal/immediate), and definitions can't occur inside other definitions without causing problems. There is a word constant
that works in interpreted mode like RPL as
, however.
Factor
The documentation summarizes:
The parser reads successive tokens from the input; if the token identifies a number or an ordinary word, it is added to an accumulator vector. Otherwise if the token identifies a parsing word, the parsing word is executed immediately.
Terminology and implementation aside, this is quite a lot like the RPL approach, except there is still a fundamental distinction made between normal and "parsing" words. Additionally, everything in a source file isn't compiled until the whole file is parsed, so parsing words can't be defined and then used immediately.
It also mentions something I left implicit: the words for numbers don't have to be defined individually, since their meaning can be determined from their form in a consistent way. Essentially all Forths do this, since numbers are useful.
Lisp (or at least most Lisps)
Lisp isn't even a stack language, but it has a way to extend its syntax called "macros". Macros are essentially procedures that take code and transform it somehow to be further processed. This is a lot like RPL's syntactic words, except that macro expansion is done after the whole expression is parsed. There are also reader macros, but they're different from both macros and regular functions. The way syntax works is generally different from these mechanisms anyway.
Hopefully this puts RPL in context as a simplification of these sorts of concepts. It was designed with simplicity and communication in mind, rather than implementation constraints.
Anyway, that's all for the stack language series, for now at least. Thanks for reading!
Subreddit
Post Details
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/minlangs/co...