Sunday 11 January 2015

Feeding the Shoggoth

There is something about H.P. Lovecraft. He gets to your head. 



~*~
"The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown."
~*~

The plot of his stories is largely inconsequential, and his characters show little emotion aside from those of fear and disbelief. It's the after-taste that's delicious. That there are beings amongst us that are far beyond the comprehension of our senses, beings that have lived for aeons and traveled long through space and time, is a possibility that strikes the conscience in an ungodly manner and lingers in one of its many corners forever after.

The question is- what was he driven by?

Many people have attempted answering this question, and they seem to focus too much on his parents' mental condition. I believe there was a deeper reason behind all of it- he had lost his faith, but did not want to 'come out'.


~*~
"If religion were true, its followers would not try to bludgeon their young into an artificial conformity; but would merely insist on their unbending quest for truth, irrespective of artificial backgrounds or practical consequences."
~*~

He feared that if he publicly renounced his faith, he would be deemed one of those slow, primitive, racist stereotypes that he described so much in detail. 

He was torn between civilization and science.

He could not bring himself to believe in what his priests told, and he asked himself- "Why should I believe them? I myself have seen no proof."

And so he set out on a social experiment to see what he could get others to believe, and more importantly, fear. He thought of cults that had their own beliefs, their own gods- gods that were as probable to exist as the ones he'd been told about.

And out of this social experiment, came the Cthulhu Mythos.

~*~
"Bunch together a group of people deliberately chosen for strong religious feelings, and you have a practical guarantee of dark morbidities expressed in crime, perversion, and insanity."
~*~

The other religion that he thought of taking to should arguably have been morphine, as apparent through his writings. He feared that he would get addicted to it, and it would lead him to madness.

But, curious as he was, he fantasized about the apparent delirium brought on by opium, and others' perception of him in that situation, and wrote the extremely detailed emotions that he imagined everyone would experience.

Thus, The Mythos, though born out of a fear of madness, were inspired by his disbelief in religion and the desire to take to drugs to escape this life that he so disliked- in true Goth fashion. 

In fact, I would argue that Lovecraft's ideas brought on the Beatnik movement. Burroughs said this on coming across a real (fake) Necronomicon:

~*~
"The deepest levels of the unconscious mind where the Ancient Ones dwell must inevitably surface for all to see. This is the best assurance against such secrets being monopolized by vested interests for morbid and selfish ends." 
~*~

Thus, the Beats saw their inner demons reflected in these strange, indifferent gods, and the struggle to be out and open with them before they became weapons in the hands of others, came to be a central, fundamental principle of their philosophy.

H.P. Lovecraft was awesome.

Wednesday 7 January 2015

Maya- A DSL for math and numerical work


I feel awkward writing mathematical functions as s-exps

(defn quadratic-1 [a b c]
  (let [d (* 4 a c),
        D (Math/sqrt (- (* b b) d)),
        t (* 2 a), -b (- b)]
    [(/ (+ -b D) t) 
     (/ (- -b D) t)]))


Clojure's thread-first macro eases the pain a bit..


(defn quadratic-2 [a b c]
  (let [d (* 4 a c),
        D (-> (* b b) (- d) Math/sqrt),
        t (* 2 a), -b (- b)]
    [(-> -b (+ D) (/ t)) 
     (-> -b (- D) (/ t))]))


..but it's still pretty loaded with parens, and not very clear.

We need a math DSL that looks infixy and uses fewer parens.
Luckily, we can hack one for ourselves in no time.

~*~

Step 1- Thread mathematical expressions

(defmacro math->
  "(math-> 1 + 5 * 2 / 3) ;=> (-> 1 (+ 5) (* 2) (/ 3)) ;=> 4" 
  [exp & f-x-pairs]
  (if (even? (count f-x-pairs))
    `(-> ~exp 
       ~@(for [[f x] (partition 2 f-x-pairs)]
           (list f x)))
    (throw (Exception. "f-x-pairs should be even."))))

Step 2- Allow temporary bindings

(defmacro maya
  "(maya 1 + 5 :as six, six * 2 :as twelve, twelve / 3 * 2) ;=> 8"
  [& exprs]
  (let [[exp [_ ?as & next-exprs :as E]] (split-with #(not= :as %) exprs)]
    (if (empty? E)
      (cons `math-> exp)
      `(let [~?as (math-> ~@exp)]
         (maya ~@next-exprs)))))

Step 3- Profit?

(defn quadratic [a b c]
  (maya 4 * a * c :as d,
        b * b - d -> Math/sqrt :as D,
        2 * a :as t, (- b) :as -b,
        -b + D / t :as x1,
        -b - D / t :as x2,
    [x1 x2]))


~*~

Edit: Here's the original gist.