LoginSignup
1
0

More than 5 years have passed since last update.

dotoマクロ in CommonLisp

Posted at

ClojureのdotoマクロをCommonLispに移植してみた。

実装

(defmacro doto (x &rest forms)
  (let ((gx (gensym)))
    `(let ((,gx ,x))
      ,@(mapcar (lambda (f)
                  (if (listp f)
                    `(,(first f) ,gx ,@(rest f))
                    `(,f ,gx)))
                forms)
      ,gx)))

使ってみる

(defclass foo () ())

(defmethod baz ((this foo) x y)
  (print (+ x y)))

(doto (make-instance 'foo) (baz 1 2) (baz 2 3)) 
; 3 
; 5
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0