I Have a Dream. In Common Lisp and Twitter.

Everyone’s favorite language at the moment seems to be Erlang. I don’t really like it; it’s a syntactic thing that I’m sure I could get used to, but to be honest it’s not too fast, and I have a Spanish keyboard, which means it’s horribly difficult for me to program in a language with these things ‘->’ everywhere. Let’s face it: most programming languages are a typographical nightmare. I only wish there were a grid system for source code. But I do like the Actor model. I liked it before everyone jumped on the frigging bandwagon of Acting, but I’m not here to try and tell you that I saw this coming (the Actor model’s popularity), because frankly I didn’t. Here’s one of the applications that I think would be effing cool. It’s in Common Lisp, but it’s rather self-explanatory:

(deftwitterbot retweet-mirror
    (tweet
        (from message)
            (let ((retweet-long (format nil "RT @~A: ~A" from (@ message :body))))
                (let ((retweet-short
                    (if (> (string-length retweet-long) 140)
                        (string-concat (substring retweet-long 0 137) "...")
                        retweet-long)))
                        (tweet retweet-short)))))

(run-twitterbot retweet-mirror "<username>" "<password>")
So basically, each twitter bot is an Actor with certain actions; these could be ‘tweet’, ‘direct’, ‘reply’, ‘retweet’ or ‘mention’ (for example). For each action, a parameter list is specified which binds the sender username and the message itself to the given parameter names. Then, the body of the action is evaluated in the context of these bindings. Seems simple enough, no? Well, in theory it should be very do-able, and it would possibly make Common Lisp a bit more popular (well…).

posted 1 year ago | Permatime

blog comments powered by Disqus