F.E.L.T.

Functionally Equivalent Language Translation

ALIST / {}

(alist)                                  ; an empty association list
{}                                       ; an empty association list
(defvar foo {:n 1]}                      ; contains one key, "n" with value, number 1
(defvar foo (alist "X" "unknown")        ; contains one key, "X" with value "unknown"
(defvar foo {:sum (+ 1 2) :when (time)}) ; contains (1+2) and the current time

The ALIST instruction has the short-form {}. Please refer to ARRAY for guidelines on what you can put into an ALIST. The key point to remember is that the number of entries must be divisible by two, that is, the keys and values must be equally paired up and they are read as k1 v1 k2 v2 ... kN vN until the end of the instruction. If you do not provide an even number of entries then an error will be generated at translation time.


As with creating an array, creating an association list is equally simple. You can use the ALIST instruction or the short-form, curly braces. The choice of curly braces is very similar to the JSON "object" notation and was purposely chosen because of that. An association list is essentially an object from that perspective.

FELT places no restrictions on what you can put inside an association list, as the key or as the value, but it must make syntactically correct code via the chosen back-end or you will of course experience execution / compile errors.

Examples

Here are some examples in PHP and javaScript so that you can see what you get. As stated, FELT itself places absolutely no restrictions on what you can place inside an association list; the onus is on you as the developer to know what you are doing and how you are going to be rendering out the code in the future.

There are no portability notes to take into consideration when using this instruction. The declarations can be as simple or as complex as you want to make the. Let's convert the following into PHP and then javaScript:

(defvar foo (alist :one "Hello" :two "World"))
(defvar bar {:name "Emacs" :job "Viking"})
(defvar baz {"alpha" [1 2] "beta" [3 :four] :gamma 42})

The above declarations produce this when translated to PHP:

$foo = array('one' => "Hello", 'two' => "World");
$bar = array('name' => "Emacs", 'job' => "Viking");
$baz = array("alpha" => array(1, 2), "beta" => array(3, 'four'), 'gamma' => 42);

And this when rendered as javaScript:

var foo = {'one' : "Hello", 'two' : "World"};
var bar = {'name' : "Emacs", 'job' : "Viking"};
var baz = {"alpha" : [1, 2], "beta" : [3, 'four'], 'gamma' : 42};