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 2: Shuffling
Post Body

The last post, which introduces stack languages from the beginning, can be found here.


It helps to be able to refer to a concept multiple times without repeating the phrase that generated it. Additionally, the concepts on the stack might not match with the stack effect of a word we want to use. This kind of problem can be solved with "stack shuffling" words. Here are a few:

copy ( a   >> a a   ) copies the top item.
over ( b a >> b a b ) copies the next item.
swap ( b a >> a b   ) switches the two.
drop ( a   >>       ) removes the top item.

(I've stopped including the "…" in stack comments, since anything below the items we're discussing is in a very real sense irrelevant.)

Some example uses would be copy * to square a number (like in 2 copy *), 0 swap - to negate a number, 1 swap / to get its reciprocal, and so on. Notice how these phrases, despite requiring additional context to be complete, are in a way meaningful in themselves as their overall stack effects.

Using these few words gives us a lot of shuffling power. I encourage you to follow through these examples to see why the phrases have these effects:

swap drop ( b a >> a       ) drops the next item.
swap over ( b a >> a b a   ) tucks the top item under the next.
over swap ( b a >> b b a   ) copies the next item under the top.
over over ( b a >> b a b a ) copies the two in order.

Even so, these words do not allow us to effectively work with more than two items at a time. We can do a lot more if we have a second stack, parallel to the main one, for temporarily holding values. Let's call the word that moves an item from the main stack to the other save and the inverse load. An example use case is

save swap load swap ( c b a >> b a c )

which rotates the third item forward and works like

…    ( c b a )
save ( c b   ) ( a )
swap ( b c   ) ( a )
load ( b c a )
swap ( b a c )

More examples are

swap save swap load ( b a c >> c b a   ) rotates it back.
save over load swap ( c b a >> c b a c ) copies the third item to the top.

Let's call these sequences dig, dip, and 3rd, in case we ever need them. But it might be clear that shuffling 4 or more items at a time can get out of hand. Fortunately, there are better ways to do it, and I'll lay the groundwork for that next.

To recap, we introduced these shuffle words: copy over swap drop save load dig dip 3rd.


My plan was to include quotation in this post, but I decided it would be better to provide a better discussion of shuffling. A revised plan is:

  • Part 3: metaconversational effects (beyond the stack(s)), syntactic words, definition, quotation
  • Part 4: combinator words
  • Part 5: conversation mechanics, pronouns and other utilities

I'd appreciate some feedback on the length of these posts, since I think this is a good length but I'm unsure. And the content, of course.

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