Wednesday, December 24, 2014

December 24, 2014

As Sheldon would say, "bazinga!" (emphasis mine):
It’s a tough decision to normalize relations with a country whose police force murders its own innocent civilians on almost a daily basis, and even more abroad, but Cuba needs to do it.

There's been a lot of hand-wringing and "what kind of people would do something like this" about the Peshawar massacre. 'Joe Hillshoist' at RI gets it right:

From what I understand a recent Pakistan Army offensive left between 500 and 2500 civilians dead in the border region where the Pakistan Taliban are based. I'm not justifying killing kids - what seems to have happened at Peshawar is horrific, like the 7 or 8 kids found stabbed, along with their mum, in a house in Cairns today. But you can't just single out one horrific act in a series of tit for tat horrific acts and pretend it signifies anything other than a horrible cycle of revenge. A cycle that needs more than one actor to perpetuate it. I'd like to think that if someone blew up my wife and child while I was at work I wouldn't want to retaliate like that but who knows really. I hope I never find out.

One bomb
The whole block gone
Can't find my children
And dust covers the sun
Everywhere is noise, panic
And confusion
But to some another fun day in Babylon
I'm going to bury my wife
And dig up my gun
My life is done
So now I'm going to kill someone...
This post is turning into a quote-fest, last one, I promise. This time from a letter to the editor in The Hindu (side note: the letters section in The Hindu is the place you go to to bone up on your collection of barely-appropriate figures of speech and metaphors [a sample from letters on the same day: eye-opener, take with a pinch of salt, hand-in-glove, pillar of support, riding on the plank of, nip the trouble in the bud, ...]) -- a rare voice of critical thinking:

The findings (that if the intelligence agencies of the UK, US and India had shared information and connected the dots, 26/11 could have been prevented) are striking, but one needs to take them with a pinch of salt. It is a fact that the U.S. still has not come clean on the role of David Headley. Or it could be that India knows the truth and has chosen not to pursue the matter keeping in mind the importance of economic interests. The West definitely knows a lot more about global plots and plans than it ever reveals. Wikileaks is a good example of doublespeak by the West.
(Yeah, I know, "pinch of salt", but still)
Question time: Do you remember the kiss you stole when she was standing under the mistletoe? Or the time you got a buzz from splurging on plum cakes? What about the time you went a-carolling late at night, with the snowflakes grazing your face as you stamped your feet and buried your hands deep into your jacket pockets to keep away the cold?

If you are a typical denizen of the tropical lands of India for whom all this Christmas revelry means is nothing more than a break from work and a disgusted shake of the head at the way the festival is being commercialized just to ring in a few more pieces of silver into the coffers of businesses, your answers to these questions would have been "No", "No", and  "Fuck no" respectively. The correct question to ask is "What the fuck is Coke doing with a half-page ad peddling its wares as a staple of Christmas revelers ("Plum cakes, bright lights / Mistletoes,carol nights / Christmas is about togetherness / With Coca-Cola (R), family and friends") in India?

Thursday, December 04, 2014

December 4, 2014

In a move that's bound to offend Lisp purists, I have added support for C-style arrays in pLisp; it is now possible to get and set array elements by syntax like a[10 2]. I initially thought of doing this the canonical way, i.e. a[10][2], but this complicates the lexical analysis (I have already introduced shift/reduce conflicts with these changes), so a single pair of square brackets will have to do.

You can thus do things like these now:

USER> (define a (array (2 2) 1))

[[1 1] [1 1]]

USER> a[0 0]

USER> (aset a[0 0] 100)

[[100 1] [1 1]]

array and aset are macros that internally call make-array and array-get/array-set respectively:

(defmacro array (dims default-value)
  (if (eq (length dims) 1)
      `(make-array ,(car dims) ,default-value)
    `(make-array ,(car dims) (array ,(cdr dims) ,default-value))))

(defmacro aset (ref val)
  (let ((a (second ref))
    (last-index (last ref))
    (indexes (butlast (cddr ref) 1)))
    `(array-set (build-ref ,a ,indexes) ,last-index ,val)))

During lexical analysis, the form a[x y] is converted into a list (aref x y) so that the sanctum sanctorum of the interpreter and other bits of pLisp are not polluted by the impurity of the square brackets.

build-ref is a macro that is used internally to convert a reference of the form (aref array-name i1 i2 ...) to one that uses array-get.

(defmacro build-ref (a indexes)
  (let ((rev-indexes (reverse indexes)))
    (if (eq (length rev-indexes) 1)
    `(array-get ,a ,(car rev-indexes))
      `(array-get (build-ref ,a ,(cdr rev-indexes)) ,(car rev-indexes)))))