Introduction to Var'aq Programming

This Site is intended to provide helps to Var'aq language programmers around the world through technical examples, informational articles, and personal assistance.

The following examples are meant to be a quick Getting Started sort of tutorial using the varaq-kling.pl version in Perl.

Example 3. Stack Operations
To understand better the order in which things are done in Var'aq, one has to understand the concept of "pushing" and "popping" items on a "stack". The stack is a specially-managed structure into which items are placed and subsequently operated upon or removed. In the simple arithmetic example two numbers are "pushed" onto the stack, then the '+' operator "pops" them for a short time to find their sum, and then "pushes" the result back onto the stack for the next operation.

Because things on the stack sometimes arrive in the wrong order for an upcoming operation, most stack-based languages provide some basic stack operations for making necessary position adjustments.

PUSH:
10 "The answer is " cha' cha'
10 is "pushed" onto the stack, followed by "The answer is "; the first cha' instruction prints "The answer is ", and the second cha' instruction prints "10".
POP:
10 "The answer is " woD cha'
10 is "pushed" onto the stack, followed by "The answer is "; the woD "pops"--discards--"The answer is ", and the cha' instruction prints "10".
SWAP:
10 "The answer is " tam woD cha'
10 is "pushed" onto the stack, followed by "The answer is "; the tam swaps the top two items on the stack: "The answer is " and 10, then the woD "pops"--discards--10, and the cha' instruction prints "The answer is ".
DUPLICATE:
10 "The answer is " woD latlh boq cha'
10 is "pushed" onto the stack, followed by "The answer is "; the woD "pops"--discards--"The answer is ", and the latlh duplicates the 10, boq adds the two 10's, and the cha' instruction prints "20".

See the Var'aq specification for the arithmetic operators supported by Var'aq.

Go back to go to the next example.

©Copyright 2004, Mr. Merrick J. Stemen. All rights reserved.