Functionally Equivalent Language Translation →
(apush aref-expression value) (apush foo 100) ; push 100 into the end of Array 'foo' (@< foo 100) ; same as above, short form
The APUSH
instruction has the short-form @<
. The greater-than sign facing towards the @
symbol is meant to visually indicate that something is being added and that it is being added to the end of the array. The value that is added must generate a valid term in the target language. Any valid array expression (see AREF/@ can be used after the APUSH instruction.
Here is the FELT source we are going to convert to PHP and javaScript:
(defvar items []) (@< items []) ; items now contains a nested array (apush (items 0) "Hello") (@< (items 0) "World") (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_push($items, array()); array_push($items[0], "Hello"); array_push($items[0], "World"); $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
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 two arrays (apush (items 0) "Hello") (@< (items 0) "World") (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.push([]); items[0].push("Hello"); items[0].push("World"); var message = implode(items[0], " "); console.log("That message says: " + message + "\\n"); function implode(x) {return x.join();}
And the generated output is:
$ felt docex.felt -as nodejscoder | node That message says: Hello,World