さくらんぼのlambda日記

lambdaちっくなことからゲーム開発までいろいろ書きます。

hatena-modeの設定メモ

さっそく会社で記事書こうとしてたらトラブルです。
どうもEmacsのfaceの問題でhatena-modeの記事のタイトルが読めない。
背景が黒でタイトルも黒っぽくて読めない感じ。

hatena-vars.elに設定があるっぽいので
該当行を変更して対処しました。

以下が設定です。

(defface hatena-html-face 
  '((((class color) (background light)) (:foreground "DarkSeaGreen4"))
    (((class color) (background dark)) (:foreground "IndianRed3" :bold t)))
  "htmlのface"
  :group 'hatena-face)

clbuildへ移行 & 便利だったパッケージ

asdf-installで管理というのが基本だったLispのライブラリ管理ですが
最近だとclbuildが便利に使えるみたいですので一気に移行してしまいました。

このclbuild基本的に巨大なshellscriptなので利用も簡単です。
Debianだと以下のパッケージが必要です。

sudo aptitude install darcs subversion mercurial git-core cvs

そのうえで

 darcs get http://common-lisp.net/project/clbuild/clbuild
 cd clbuild
 chmod +x clbuild

これで完璧です。

clbuild/clbuildというのが実体になりますので、コマンドラインから使いたいひとは
パスを通しても良いかもしれません。
が、個人的にはパス通さないでclbuildの中で完結してて欲しいので
通さないで利用してます。

./coluild help

とかすると使い方はだいたい分かるはずです。


いろいろインストールしてみたパッケージのなかで

  • lispbuilder-sdl
  • hunchentoot

あたりはasdfでインストールするよりも手軽に試せて良い感じでした。

genericsが分かってなかった話

C++のtemplateとJavaのgenericsは大分違う。

  • templateはexpansionで解釈される。genericsはErasureで解釈される
  • templateでは引数として定数値を与えることができる、genericsでは出来ない
  • genericsではList> とか書ける
  • templateは型別にバイナリを生成するためコードサイズが肥大化する(code bloat)。

genericsは基本的に型安全のみを考慮して作られているので
変なことが出来ないようになってる感じですね。

http://d.hatena.ne.jp/amachang/20080415/1208229209


この辺りの話はJava言語仕様にものってた気がするので
帰ったらチェックします。

特に

public static <T, S extends T> T cast(S o) { return (T) o; }

この辺り。

あと自己言及的なtemplateをgenericsで記述しても問題無く動作するようですね。

ソースの例は続きのあとに。

public class GenericClass<T extends GenericClass<T>> {
	      private T value;

	      public T getValue() {
	      return value;
	      }
	      public void setValue(T c) {
	      value = c;
	      }

	      public void method() {
	      as_derived().method();
	      }
	      public GenericClass<T> as_derived() {
		return this;
		}
		public T hoge() {
		return (T) this;
		}

}

public class A extends GenericClass<A> {
		  @Override
		  public void method() {
		  System.out.println("This is A::method()");
		  }

}

public class B extends GenericClass<B> {
		    @Override
		    public void method() {
		    System.out.println("This is B::method()");
		    }
}

public class Main {

			/**
			 * @param args
			 */
			public static void main(String[] args) {

			A a = new A();
			A a2 = new A();
			a.setValue(a2);
			a2.setValue(a);


			B b = new B();
			b.method();

			B b2 = b.hoge();
			b2.method();

			}

}

Memo

hunchentootの簡単なサンプル。
あとで解説が付く予定。

(asdf:oos 'asdf:load-op 'hunchentoot)
(asdf:oos 'asdf:load-op 'cl-who)
(require :hunchentoot)
(require :cl-who)
(setq *server* (hunchentoot:start (make-instance 'hunchentoot:acceptor :port 3000)))

(hunchentoot:define-easy-handler (say-yo :uri "/yo") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (format nil "Hey!~@[ ~A~]!" name))

(hunchentoot:define-easy-handler (hoi-yo :uri "/ho") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (format nil "Hoi~@[ ~A~]!" name))


(hunchentoot:define-easy-handler (memo :uri "/memo/memo") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (format nil "this is memo site~@[ ~A~]!" name))

(hunchentoot:define-easy-handler (hoge :uri "/hoge") (name)
  (format nil "~A" (hello-world))
  )

;; ハンドラ定義
(defun hello-world ()
  (cl-who:with-html-output-to-string
      (str nil :prologue t)
    (:html (:head (:title "hoge"))
	   (:body (:h1 "varのぺーじ")))))
(setq hunchentoot:*default-content-type* "text/html; charset=utf-8")

(setq hunchentoot:*hunchentoot-default-external-format*
      (flex:make-external-format :utf-8 :eol-style :lf))