purchases:readcsv["country,amount,discount\n",read["headerless.csv"] "sii"] purchases:readcsv[read["purchases.csv"] "sii"]
Summing a column: sum purchases.amount
To create a summary, we need to reduce each group to a single row: select first country sum amount by country from purchases
Discounting: select first country sum amount-discount by country from purchases
Lil doesn't have a "median" primitive. Decks can contain multiple modules, but we happen to know this one is alone. Your path will vary: stats:first import["stats.deck"]
select first country sum amount-discount by country where amount<stats.median[amount]*10 from purchases
Calculating the median within each group is merely a matter of reordering clauses: select first country sum amount-discount where amount<stats.median[amount]*10 by country from purchases l_inner:l[1][1]
# {"age":3}
l_inner.age:9
# {"age":9}
l_inner
# {"age":9}
l
# (1,(2,{"age":3}),4)
If an amending expression isn't "rooted" in a variable binding, it also returns the entire new structure: (1,(list 2,list ().age:5),4)[1][1].age:99
# (1,(2,{"age":99}),4) cat.age:3
# {"age":3}
Defining "l" as in the example in the article. We need the "list" operator to enlist nested values so that the "," operator doesn't concatenate them into a flat list: l:1,(list 2,list cat),4
# (1,(2,{"age":3}),4)
Updating the "age" field in the nested dictionary. Lil's basic datatypes are immutable, so "l" is rebound to a new list containing a new dictionary, leaving any previous references undisturbed: l[1][1].age:9
# (1,(2,{"age":9}),4)
cat
# {"age":3}
There's no special "infix" promotion syntax, so that last example would be: l:l,5
# (1,(2,{"age":9}),4,5)
[0] http://beyondloom.com/tools/trylil.html