[‘a,2] [‘a,2] [‘b:{““,x,”“}] ****************
XXL is a new programming language whose goals are simplicity, power, and speed. We throw out most of conventional programming language thinking in order to attain these goals. (************************************** [open,close] ****************************** (************************************** [‘a:1,’b:2] (Status) *******************************************
Pretty buggy but passes tests. Useful for writing small utilities, for me. Not yet suitable for real work.
About 6 lines of code, without the tests:


// enclose (c) urly (b) races, (s) quare (b) brackets, (q) uotes: ‘ecb is {“{“, x, “}”}; ‘esb is {“[“,x,”]”}; ‘eq is {“” “, x,” “”}; ‘jc is {join “,”}; ‘jac is {each y jc}; // join x with commas; apply y to each of x then join with commas ‘pair is {encode, “:”, (y encode)}; // key: val pair for dict ‘dict is {key as’ k; x val as’ v; [k], v>: pair jc ecb}; // get keys / vals, pair merge, commas, braces // wrap non-scalar values in appropriate way: ‘many is {as’ el type case (‘char, {el str eq},’ dict, {el dict}, {el jac encode esb})}; ‘encode is {ravel [many,str]}; // ravel calls x y [0] for arrays (len>1), x y [1] for scalars
Here's what's going on in this monster. I'll explain the parts, and then the sequence of how it comes together. As per the fashion that we like, the code starts from the simple, base functions, and progresses to the more complex functions that use them.
/ (eq) enclose their argument in curly braces, square braces, or quotes, respectively. They use the name (x) to refer to their argument.
********************************************** (jc) ********************************************** (join comma) joins the contents of its argument together with a comma in between each item.
jacdoes the same thing, but after first calling its right argument ( (y) ************************************************** (on each item - ["Steve", "42", "Fact Checker"] **************************** (jac) **************************************************** (here is a mnemonic for "join and call".The astute might notice that [open,close] **************************************** (jc) ***************************************** andjacDon't refer to (x) , because the first verb inside a function will be invoked automatically withxas the left argument. In small functions, (x) **************************************************** is almost always the first term in the function's code, so being able to omit it results in some expressivity. More on this later.******************************************** (pair [open,close] ****************************************** (calls another function,encode(which we define later), without referring to (x) ****************************************************. It then appends a: to the string that is returned from (encode) , and then appends that to the result of calling (encode) *************************************************** (with the [1i, [4i, (4,0,5i), 5i] ************************************** (y) ******************************************* argument. This is a form of recursion.******************************************** dict [open,close] ********************************** takes a dictionary as an argument , gets its keys as a list using the built-in (key) verb, and saves them in a new variable called (k) . The values of the dictionary (also a list) are extracted using the built-in (val) verb and become (v) ********************)These two lists then become the left and right arguments for successive calls tojcusing the "each pair" or>: verb. Each of the key / value pairs will get commas between them. Then, we enclose the whole of the dictionary in curly braces, like{"name": "Tyler", "age": "2"}
All the looping verbs have short names that end in (***************************************************: () .********************************************** many [open,close] ********************************** looks complex, but isn ' t. Its purpose is to handle multiple-item collections (called vectors in XXL). In our case, we have to worry about two main ones: character vectors (strings) and dictionaries.First, we store the value of (x) ***************************************************** (as) el(element). Then we extract the value's type using thetype
verb, and then use the (case) **************************************************** verb to decide how to treat all the different types.If it's a character vector (a string), we pass it through thestrverb to remove its tag (a feature we'll explain later).If it's a dictionary, we call our (dict) function. If it's anything else, we recurse by calling (encode) again, and then enclose the result in square braces (think arrays of numbers).And finally the star of the show, (encode) .ravelis a verb that allows you to take one branch of logic for single-item values (like the number******** (3) ), or a different branch for values that have many items, like an array or string (vectors). Depending on the type of (x) ****************************************************, (encode) **************************************************** will dispatch either [["Bob", "30", "Programmer"] ****************************** (many) ************************************************ (for multiple values) or str(for simple, single values).
GIPHY App Key not set. Please check settings