2012/09/20

Common Lisp から Skype を使う

なんだ。簡単だった。

dbus 経由。

リファレンス http://developer.skype.com/public-api-reference#Linux

(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload :dbus))

(defpackage :try-dbus
(:use :cl :dbus))

(in-package :try-dbus)

(with-open-bus (bus (session-server-addresses))
(with-introspected-object (skype
bus
"/com/Skype"
"com.Skype.API")
(flet ((skype (command)
(skype "com.Skype.API" "Invoke" command)))
(print (skype "NAME FromCommonLisp"))
(print (skype "PROTOCOL 8"))
(print (skype "GET USERSTATUS"))
(print (skype "PING"))
;; #xxx... はチャットルームの ID
(skype "CHATMESSAGE #xxxxxxx/$yyyyyyy;9999aaaa9999 てすとです(f)"))))

2012/08/25

夏休み

20日(月)から24日(金)まで鳥取に帰省していた。ニ年ぶりの帰省。

20日(月)

飛行機で羽田から米子へ。

米子空港の名前が米子鬼太郎空港にかわっていた。

家でバーベキューをして、家の裏の暗がりから天の川をながめた。

お風呂は白鳳の里。

21日(火)

水木しげるロードと、水木しげる記念館に行った。

水木しげるロードは以前よりブロンズ像がずっと増えていて、おもしろくなっていた。

水木しげる記念館は初めて入った。思っていたよりずっとよかった。壁に直筆の鬼太郎が描いてあったり、妖怪の模型や説明が充実してたり、うちの小学4年生もおおいに楽しんでいた。〇〇記念館の類の中でも秀逸だと思う。

「お魚天国すし若竹内団地2号店」で食事をして、夢みなとタワーに行った。「動物地球館」という移動動物園(?)を見た。ゾウガメに触れたのがよかった。しっぽがかわいい。

お風呂はうなばら荘。

22日(水)

午前中は近くの海へ海水浴に行った。お盆を過ぎているとはいえ、誰一人いなかった。プライベートビーチ。カモメと白鳥とクラゲ(2匹だけ)しかいなった。

午後は大山の森の国に行って、アスレチックで遊んだ。臆病な(それとも慎重派?)うちの子は、ろくにクリアできなかったけど、とても楽しかったらしい。

23日(木)

青山剛昌ふるさと館の方に行った。ちょうど「名探偵コナン 巨大迷路で少年探偵団を探せ!」というのやっていたので、迷路で遊んだ。

青山剛昌ふるさと館の方は。。。水木しげるロードと、水木しげる記念館はすごいな、という感じ。

お風呂は湧くわく天然温泉ラピスパ。

24日(金)

空港に行く前に、回転寿司「大漁丸 境港店」に行った。イワシと生サバが美味しかった。

米子鬼太郎空港から羽田へ。

2012/08/19

logtest

Common Lisp になら、あるんじゃないかなと思ったら、やっぱりあった。

(not (zerop (logand event-mask isys:epollin)))

は

(logtest event-mask isys:epollin)

http://www.lispworks.com/documentation/HyperSpec/Body/f_logtes.htm

http://www.lispworks.com/documentation/HyperSpec/Body/c_number.htm このへんは知らないのいっぱいある。

2012/08/12

Common Lisp で thread + epoll の Web サーバを作ってみた

https://github.com/quek/info.read-eval-print.httpd

(info.read-eval-print.httpd:start (make-instance 'info.read-eval-print.httpd:server))
ab -n 10000 -c 10 'http://localhost:1958/sbcl-doc/html/index.html'

Linux + SBCL にべったりで GET に対してファイルを返せるだけ。

システムコールばかりなので性能は悪くない感じ。

2012/07/10

Debian sid に Skype をインストールする

http://wiki.debian.org/skype に書いてあるとおり。

sudo dpkg --add-architecture i386
sudo apt-get update
wget -O skype-install.deb http://www.skype.com/go/getskype-linux-deb
sudo dpkg -i skype-install.deb

ひっかかったら

sudo apt-get -f install

Skype のバージョン 4.0.0.7 になってた。この前まで 2.x.x? beta だったのに。画面の共有もできるようになったようだ。

2012/06/26

だいたいこれくらい動いちゃうと

満足して実装したい衝動が消えちゃう。。。

https://github.com/quek/info.read-eval-print.active-record

(establish-connection)

(defrecord prefecture ()
()
(:has-many :facilities))

(defrecord facility ()
()
(:belongs-to :prefecture)
(:has-many :experiences :as :experiencable))

(defrecord experience ()
()
(:belongs-to :experiencable :polymorphic t))

(let ((facilities (with-ar (facility)
(where "name like ?" "%水族館")
(where :publish 1)
(order :name)
(get-list))))
(values
(mapcar #'name-of facilities)
(name-of (prefecture-of (car facilities)))))

(facilities-of (with-ar (prefecture)
(where "id = 1")
(get-first)))

(experiences-of (with-ar (facility)
(get-first)))

(experiencable-of (with-ar (experience)
(get-first)))

(with-ar (facility)
(joins :prefecture)
(where :prefectures.name "鳥取県")
(get-list))

2012/06/24

Common Lisp ならスペシャル変数とマクロで

ときどき Active Record を Common Lisp で実装したくなる。それでひっかかるものの一つがメソッドチェーン。

Ralis の Active Record Query Interface や jQuery や S2JDBC とか、メソッドチェーン多いよね。でも、Common Lisp だとメソッドチェーンはやりにくい。

リーダマクロという手はあるが、 Common Lisp らしくスペシャル変数と with 系マクロでいきたいと思う。

こんな感じになる。

(with-ar (facility)
(where "name like ?" "%水族館")
(when only-published-p
(where :publish 1))
(order :name)
(get-list))

with-ar でかこんで、後は普通に関数呼び出し。メソッドチェーンは条件分岐があるとめんどうだけで、普通の関数呼び出しだから when や if の条件分岐とかも間に入れられる。

次のような defvar と defmacro だけで簡単にできちゃう。

(defvar *association* nil "association")

(defmacro with-ar ((table) &body body)
`(let ((*association* (ensure-association ,table)))
,@body))

好きな言語がスペシャル変数とマクロのある言語でよかった。