tlack / xxl, Hacker News

tlack / xxl, Hacker News

[‘a,2]                     [‘a,2]          [‘b:{““,x,”“}] ****************

[1i, [4i, (4,0,5i), 5i] ********************** [“Steve”, “42”, “Fact Checker”] ************ [“name”:”Steve”,”age”:”42″,”job”:”Fact Checker”]

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.

Tested so far on Linux (bit x) ****************************************************************************************************************************************************************** & GCC or Clang, OS X (Clang), Windows (Cygwin, Android under termux, Intel Edison and Raspberry Pi. Should work on iOS as well but untested. (************************************** [open,close] ********************************** [open,close] **************************** (************************************** [‘a,2] [“Arca”, “2”, “Tiny Dog”] Examples (********************************************** (************************************** [open,close] ****************************** (**************************************** (JSON encoder)

About 6 lines of code, without the tests:

******************************************** [open,close] **********************json encoder screenshot with syntax highlightingjson encoder screenshot with syntax highlighting

// 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.

********************************************** (ecb) **************************************************** / esb/ (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.

does 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) ***************************************** and
Don't refer to  (x) , because the first verb inside a function will be invoked automatically with
as 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 tojc

using 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"}XXL logo
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 thetypeverb, 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) .
is 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).

What do you think?

Leave a Reply

Your email address will not be published.

GIPHY App Key not set. Please check settings

[100% OFF] Mental Models For Wall Street – Become A Better Trader

The Machine Learning Reproducibility Checklist [pdf], Hacker News