Inverted syntax: Difference between revisions

Added Quackery.
(Added Quackery.)
Line 1,064:
<syntaxhighlight lang="python">with open("file.txt") as f:
something(f)</syntaxhighlight>
 
=={{header|Quackery}}==
 
A Quackery program consists of numbers, words, and nests, collectively referred to as items. A nest is a sequence of zero or more items. Items are evaluated sequentially.
 
Some words can alter this sequential behaviour. <code>if</code> for example, causes the item following it to be skipped if the number on the top of data stack (henceforth just "the stack") is zero (i.e. false.)
 
So, given that the word <code>raining</code> returns a boolean indicating whether it is raining or not, and the word <code>use-umbrella</code> deploys an umbrella, the usual syntax would be <code>raining if use-umbrella</code>.
 
The word <code>'</code> alters the sequential flow by causing the item following it to be placed on the stack rather than being evaluated. The word <code>do</code> causes the item on the top of the stack to be evaluated. So we could define a new word, <code>if.1</code> with
 
<pre>[ swap do if do ] is if.1</pre>
 
which would allow us to use the syntax <code>' raining ' use-umbrella if.1</code>.
 
<code>'</code> is defined using the meta-control flow operator <code>]'[</code> thus: <code>[ ]'[ ] is '</code> Meta-control flow operators grant their behaviour to the word that calls them. So if we wanted the syntax <code>' use-umbrella if.2 raining</code> we could define <code>if.2</code> with
 
<pre>[ ]'[ do iff do else drop ] is if.2</pre>
 
(<code>iff</code> conditionally skips over two items, <code>else</code> unconditionally skips over one item.)
 
Other syntaxes can be achieved by the judicious use of <code>'</code> and <code>]'[</code>. To demonstrate just one that avoids the use of <code>if ...</code> or <code>iff ... else ...</code> entirely, one could define a word <code>ifelse</code> as
 
<pre>[ not ]'[ nested ]'[ nested join swap peek do ] is ifelse</code></pre>
 
This would have the syntax <code>raining ifelse use-umbrella use-sunscreen</code> (for an appropriate definition of <code>use-sunscreen</code>.)
 
Quackery does not have variables, so there is not exact equivalent to assignment, but it does have ancillary stacks which can be used in a variable-like manner. <code>temp</code> is a predefined ancillary stack, and an item can be moved from the stack to it with the phrase <code>temp put</code>. As with the previous examples, <code>]'[</code> can be used to vary the syntax.
 
=={{header|Qi}}==
1,467

edits