Source of Nothingness - format

* Menu

[[About:self:AboutPage.txt]] | [[Profile:file/southly/]] | [[まとめ:self:1163859357.txt]] | [[オリジナル:http://ninjinix.x0.com/rn/]] | [[xyzzy:lisp/]] | [[あんてな:listall]] | [[■:lisp]] | [[buzz:files/southly#buzz]]

* xyzzy lisp : format ~&

(format nil "~&") ; 何もしない
""
(format nil "xyzzy~&") ; 改行を出力
"xyzzy
"
(format nil "~2&") ; 何もしない + 1つ改行を出力
"
"
(format nil "xyzzy~3&") ; 改行を出力 + 2つ改行を出力
"xyzzy


"

* xyzzy lisp : format ~{

(format nil "~{~A ~}" '(a b c d))
"a b c d "
(format nil "~:{~A ~}" '((a) (b) (c) (d)))
"a b c d "
(format nil "~@{~A ~}" 'a 'b 'c 'd)
"a b c d "
(format nil "~:@{~A ~}" '(a) '(b) '(c) '(d))
"a b c d "
(format nil "~2{~A ~}" '(a b c d))
"a b "
(format nil "~{~A ~}" nil)
""
(format nil "~{~A ~:}" '(a))    ; nilが引数だとエラー
"a "
; "~^"と一緒に使うのが便利
(format nil "~{~A~^,  ~}~%" '(one two three four)) ; 最後に", "はいらない
"one,  two,  three,  four
"

* xyzzy lisp : format ~(

(format nil "~(~A fUga~)" "hoGe")
"hoge fuga"
(format nil "~:(~A fUga~)" "hoGe")
"Hoge Fuga"
(format nil "~@(~A fUga~)" "hoGe")
"Hoge fuga"
(format nil "~:@(~A fUga~)" "hoGe")
"HOGE FUGA"

* xyzzy lisp : format ~?

(format nil "~D, ~?" 10 "[~A ~D]" '(hoge 30))
"10, [hoge 30]"
(format nil "~D, ~@?" 10 "[~A ~D]" 'hoge 30)
"10, [hoge 30]"

* 2006-09-20

で、移植の手順。
1. [[Emacs lisp 移植キット:xyzzy.html]]を使えるようにする。
2. 使えないもの(defgroup, font-lock関係, フレーム関係, etc)をコメントアウト
3. 文字の表現を書き直し(?a → #\a) 特に#\SPCとか
4. キーバインドの記述を書き直し(文字列 → 文字 or cons)
5. formatの引数を直す
6. 無い関数を記述 & 無い変数を代替の関数へ
7. 位置の調整(xyzzyは0 origin, emacsは1 origin)
8. functionとsymbol
9. その他こまごまとした修正

* memo : iterationで最後だけ出力しない

(format nil "~{~A~^ ~}" '(a b c))
=>"a b c"

* xyzzy lisp : へなちょこ補完その3

絞込み
[[(ReadMore...) index.rb?1155828305.txt]]

* xyzzy lisp : なんとなく

(defun sort-by-column-region (beg end &optional (f #'<))
  (interactive "*r")
  (let ((lines (split-string (buffer-substring beg end) #\LFD t))
        (pred #'(lambda (x y) (funcall f (length x) (length y)))))
    (setq lines (sort lines pred))
    (goto-char (min beg end))
    (delete-region beg end)
    (insert (format nil "~{~A~%~}" lines))))

* xyzzy lisp : 位置とサイズの操作

また勢いだけで使いそうに無いものを作ってしまった。
[[(ReadMore...) index.rb?1154192130.txt]]

* xyzzy lisp : format ~*

(format nil "~A ~A ~*~A ~A ~A" 'a 'b 'c 'd 'e 'f)
"a b d e f"
(format nil "~A ~A ~2*~A ~A" 'a 'b 'c 'd 'e 'f)
"a b e f"
(format nil "~A ~A ~A ~2:*~A ~A ~A ~A" 'a 'b 'c 'd 'e 'f)
"a b c b c d e"
(format nil "~A ~A ~4@*~A ~A" 'a 'b 'c 'd 'e 'f)
"a b e f"

* xyzzy lisp : format ~T