Lisp

例の問題

CLの練習で適当に書いた。いったい何を訴えたいのかよくわからないコードになった。 解き方はいたって普通。 (require :alexandria) (require :cl-ppcre) (defun perms (n xs list fn) (if (zerop n) (funcall fn list) (loop for x in xs do (perms (1- n) …

ccl:*command-line-argument-list* がなんか変

● 実行形式ファイルが作りたい コマンドライン引数リストをそのまま表示するプログラム(Clozure CL) ;;; hello.lisp (defun -main () (format t "~a" ccl:*command-line-argument-list*)) (ccl:save-application "hello" :toplevel-function #'-main :prepen…

partial関数(マクロ)の続き

前回書いた partial マクロ利用例 (mapcar (partial #'args-rotate-right 1 #'make-list :initial-element 'X) '(1 2 3 4 5)) mapcar の第一引数をもう少し理解しやすい形にしたい。 そこで部分適用を段階的にしてみる。args-rotate-right 1 を部分適用した…

partial関数書いてみた

●partial関数 Common Lisp で *1 (defun partial (f &rest args) (lambda (&rest rest-args) (apply f (append args rest-args)))) (funcall (partial #'* 2) 10) ;=> 20 (funcall (partial #'list 1 2) 3 4 5) ;=> (1 2 3 4 5) 一応できてますね。左から順…

emacs lisp にも clojure の ->> が欲しいよね

試しに書いてみたんだけど、これはいいかも... (require 'cl) (defmacro my:-> (&rest exprs) (when exprs (reduce '(lambda (acc expr) (if (listp expr) (cons (car expr) (cons acc (cdr expr))) (list expr acc))) exprs))) (defmacro my:->> (&rest exp…