Functionally Equivalent Language Translation →
(aunshift aref-expression expr1 expr2 ... exprN) (aunshift foo expr) ; push to the front of foo (>@ foo expr) ; same as above, short form
The AUNSHIFT
instruction has the short-form >@
. The greater-than sign facing towards the @
symbol is meant to visually indicate that something is being added to the front of the array. The value(s) can be any valid back-end expressions.
Here is the FELT source we are going to convert to PHP and javaScript:
(defvar items []) (>@ items []) ; items now contains a nested array (aunshift (items 0) "World") (>@ (items 0) "Hello") (defvar message (implode (@ items 0) " ")) (emit "That message says: " message "\n")
Now let's render the code as PHP and execute it to show it worked:
$items = array(); array_unshift($items, array()); array_unshift($items[0], "World"); array_unshift($items[0], "Hello"); $message = implode($items[0], " "); echo "That message says: ", $message, "\n";
and when run through the PHP interpreter we get this output:
$ felt docex.felt -cw | php That message says: Hello World felt docex.felt -cw | php That message says: Hello World
And finally for Node/javaScript, this being the modified code as javaScript has no "implode" function so we have to fake it:
(defvar items []) (>@ items []) ; items now contains a nested array (aunshift (items 0) "World") (>@ (items 0) "Hello") (defvar message (implode (@ items 0) " ")) (emit "That message says: " message "\n") (defun implode (x) (return (x.join)))
The generated code from the above FELT source is:
felt docex.felt -as nodejscoder var items = []; items.unshift([]); items[0].unshift("World"); items[0].unshift("Hello"); var message = implode(items[0], " "); console.log("That message says: " + message + "\\n"); function implode(x) {return x.join();}
$ felt docex.felt -as nodejscoder | node That message says: Hello, World