F.E.L.T.

Functionally Equivalent Language Translation

APOP / @>

(apop aref-expression)
(apop foo)                ; pop from the end of Array 'foo'
(@> foo)                  ; same as above, short form

The APOP instruction has the short-form @>. The greater-than sign facing away from the @ symbol is meant to visually indicate that something is leaving and that it is leaving from the end of the array. The value that is removed can be assigned to a variable or used in any other way that generates valid output syntax in the targeted language. Any valid array expression (see AREF/@ can be used after the APOP instruction.


Examples

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

(defvar items [ 10 20 "Thirty" [:a :b :c]])
(defvar a1 (apop items)) ; the array
(defvar v30 (apop items))
(defvar v20 (@> items))
(defvar v10 (@> items))
(emit "Item count, zero == " (count items) "\n")
(emit "'a' == " (@> a1) "\n")
(apop 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_pop($items);
$v30 = array_pop($items);
$v20 = array_pop($items);
$v10 = array_pop($items);
echo "Item count, zero == ", count($items), "\n";
echo "'c' == ", array_pop($a1), "\n";
array_pop($a1);
echo "'a' == ", array_pop($a1), "\n";

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

$ felt docex.felt -cw | php
felt docex.felt -cw | php
Item count0
'c' == c
'a' == a

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

var items = [10, 20, "Thirty", ['a', 'b', 'c']];
var a1 = items.pop();
var v30 = items.pop();
var v20 = items.pop();
var v10 = items.pop();
console.log("Item count, zero == "+ count(items)+ "\n");
console.log("'a' == "+ a1.pop()+ "\n");
a1.pop();
console.log("'c' == "+ a1.pop()+ "\n");

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 count0

'c' == c

'a' == a

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.