2007年10月20日土曜日

Metacircular Semantics for Common Lisp Special Forms (2)

This is done not just because such definitions can be entered and
quickly checked using a standard Common Lisp
implementation, but also because we feel that the
Common Lisp "macro" is the sanctioned mechanism for
adding new "special forms".

これら一連の考察において、我々の定義を標準的なの
Common Lispの実装を使用して手短に試すことができた、
というだけではなく、Common Lispのマクロは、新しい"
特殊形式"を加えるための手段として広く認知できるものだ、
という実感を持つことができた。
[ワカランナ]

While this view of
special forms is not evident from CLtL2
[Steele90], it should be obvious by the end of
this paper.

In short, the choice of which "macros"
are "special forms" is just as arbitrary as the
choice of a axes in a coordinate system for the
Cartesian X-Y plane--e.g., some sets of macros are
"linearly independent", and some sets of macros
"span" the space of special forms.

また一連の検証はCLtL2[Steele90]には準拠するもので
はない。このことは、この論文の文末にて詳細を述べる。

要約すると、"マクロ"を"特殊形式"とすることは、
あたかも、カーテシアン座標系のX-Y面で座標系の軸を
任意に選択することといえる--例えば、特殊形式の座標
空間において、いくつかのマクロは、線形独立で、また、
いくつかのマクロは範囲とみなせる。
[ナンデスカソレ]

Some of our emulations may only be approximate, in
the sense that certain syntactic variations are
not supported, and certain error conditions are
not recognized.
These emulations are meant to be
only a starting point for a serious effort in
pinning down the semantics of Common Lisp, and
significant additional effort will be required to
complete this task.[3]

いくつかの我々の試みは、これらが適切に文法的な変化
に対応できておらず、また適切にエラーを補足できない
という点で、大まかな外観を与えるに留まるかもしれな
いが、本格的なCommon Lispの意味論を明確にする取り
組みのまさに出発点に過ぎず、完遂には、多大な追加努
力が必要とするだろう。

The "Portable Common Loops" ("PCL") version of the
Common Lisp Object System (CLOS) exemplifies the
need for a more reflexive view of Common Lisp
special forms.

"Portable Common Loops" ("PCL")版のCommon Lisp
Object System (CLOS)は
よりCommon Lispの特殊形式の性質をより反映させた視
点が必要であることを例示している。

PCL does not quite live up to its
name, since it needs to diddle the representation
of function closures, which is different in every
Common Lisp implementation. Through the techniques
we exhibit here, a truly portable version of PCL
could be produced, thereby eliminating the need to
include CLOS in a Common Lisp standard.

PCLは、その名前の通り「ポータブル」なものにはなっ
ていないのが現状である。
Common Lispの実装ごとに違っている関数のクロージャ
表現については、実装ごとに対処するというごまかしも
必要になっている。
我々がここで述べる一連の技法のなかで、本来の意味で
「ポータブル」なPCLというものの実現が可能となった。
結果として、Common Lispの標準規格にCLOSを含める必
要性も排除することができた。

LAZY EVALUATION OF "IF"

The Common Lisp special form if is often thought
to be primitive, in the sense that it cannot be
defined in terms of other special forms.
Of
course, if can be defined in terms of cond or
case, so one of these macros could have been
chosen as the primitive conditional special form
rather than if.

Nevertheless, the lazy evaluation
of the "then" and the "else" arms of if can be
emulated by means of lambda, as the following
macro shows:

遅延評価版"IF"

Common Lispの特殊形式のプリミティブなものといえば、
他の特殊形式で再定義できないという意味で"if"が想起
されるのではないだろうか。
もちろん、実際には、"if"は、"cond"もしくは、"case"
によって定義可能であるし、これらのマクロはプリミティ
ブな特別形式による条件式として、"if"より好ましかっ
たかもしれないが、それはともかく、"if"の"then"節と、
"else"節のlambdaを使用した遅延評価による模倣は下記
の様なマクロとなる:
(setf (get 't 'select-function) #'(lambda (x y) (funcall x))
(get 'nil 'select-function) #'(lambda (x y) (funcall y)))

(defmacro if (be te &optional (ee ''nil))
`(funcall (get (not (not ,be)) 'select-function)
#'(lambda () ,te)
#'(lambda () ,ee)))

0 件のコメント: