F.E.L.T.

Functionally Equivalent Language Translation

ASHIFT / <@

(ashift aref-expression)
(ashift foo)               ; pop from the front of Array foo
(<@ foo)                   ; same as above, short form

The ASHIFT instruction has the short-form <@. The greater-than sign facing away from the @ symbol is meant to visually indicate that something is being removed from the front of the array. The value that is removed can be assigned into a variable, used as a function argumen etc. `foo' can be any valid AREF/@ expression.


Examples

Here is the FELT source we are going to convert to PHP and javaScript:

(defvar items [ 10 20 "Thirty" [:a :b :c]])
(defvar v10 (ashift items))
(defvar v20 (<@ items))
(defvar v30 (<@ items))
(defvar a1 (ashift items)) ; the array
(emit "Item count, zero == " (count items) "\n")
(emit "'a' == " (<@ a1) "\n")
(ashift a1) ; remove 'b'
(emit "'c' == " (<@ a1) "\n")

Now let's render the code as PHP and execute it to show it worked:

$items = array(10, 20, "Thirty", array('a', 'b', 'c'));
$a1 = array_shift($items);
$v10 = array_shift($items);
$v20 = array_shift($items);
$v30 = array_shift($items);
echo "Item count, zero == ", count($items), "\n";
echo "'a' == ", array_shift($a1), "\n";
array_shift($a1);
echo "'c' == ", array_shift($a1), "\n";

and when run through the PHP interpreter we get this output:

felt docex.felt -cw | php
Item count, zero == 0
'a' == a
'c' == c

And finally for Node/javaScript, this being the rendered code:

var items = [10, 20, "Thirty", ['a', 'b', 'c']];
var v10 = items.shift();
var v20 = items.shift();
var v30 = items.shift();
var a1 = items.shift();
console.log("Item count, zero == "+ count(items)+ "\n");
console.log("'a' == "+ a1.shift()+ "\n");
a1.shift();
console.log("'c' == "+ a1.shift()+ "\n");
function count(z)
{return z.length;}

Note that we had to provide an implementation of count for this code to work at run-time. When piped into "node" we get this output:

felt docex.felt -as nodejscoder | node
Item count, zero == 0

'a' == a

'c' == c

We could have put the count function in the original code example but I wanted to keep it concise. Please see the #F:WHEN instruction for complete details on how to provide different versions of functions for different target languages.