0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LISPでインライン展開する関数

Last updated at Posted at 2025-08-24

s7 schemeにはdefine-expansionとゆう静的に展開するマクロがある。これを用いてC++のinline関数みたいなのを作ってみたのでご紹介。

(define-macro (define-inline decl . body)
  (let ((bind (map (lambda (arg)
                     (list arg (list 'unquote arg)))
                (cdr decl))))
    `(define-expansion ,decl
       ,(list quasiquote `(let ,bind ,@body)))))

使い方は、

(define-inline (hoge a b)
  (+ a a b))

こんな感じで普通の関数と同じように定義する。実際に速くなるのかはまだ検証してないw

いじょう

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?