(.getLocation (.getCodeSource (.getProtectionDomain (.getClass '(1 2)))))が
(.. '(1 2) getClass getProtectionDomain getCodeSource getLocation)と書けますよーということのようです。
Java だと
'(1 2).getClass().getProtectionDomain().getCodeSourse().getLocation();みたいなイメージで良いんでしょうかね。
scheme (gauche) の syntax-rules で書くと下記のような感じでしょうか。
良い名前が思いつきませんでした。当初は chain にしてましたが、なんとなく across に変えました。。
書いてみたコードは以下のようなもの。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; across | |
;; (across) | |
;; #f | |
;; (across 3) | |
;; 3 | |
;; 3 | |
;; (across 3 (pa$ * 10)) | |
;; ((pa$ * 10) 3) | |
;; 30 | |
;; (across 3 (cut * <> 2) (cut + 10 <>)) | |
;; (across ((cut * <> 2) 3) (cut + 10 <>)) | |
;; (across ((cut + 10 <>) ((cut * <> 2) 3))) | |
;; ((cut + 10 <>) ((cut * <> 2) 3)) | |
;; 16 | |
;; (across 3 (cut * <> 2) (cut + 10 <>) x->string) | |
;; (across ((cut * <> 2) 3) (cut + 10 <>) x->string) | |
;; (across ((cut + 10 <>) (cut * <> 2) 3) x->string) | |
;; (across (x->string ((cut + 10 <>) (cut * <> 2) 3))) | |
;; (x->string ((cut + 10 <>) ((cut * <> 2) 3))) | |
;; "16" | |
(define-syntax across | |
(syntax-rules () | |
((_) #f) | |
((_ exp) exp) | |
((_ exp1 exp2) | |
(exp2 exp1)) | |
((_ exp1 exp2 exp3 ...) | |
(let1 val (across exp1 exp2) | |
(across val exp3 ...))) | |
)) | |
(across) | |
;; #f | |
(across 3) | |
;; 3 | |
(across 3 (pa$ * 10)) | |
;; 30 | |
(across 3 (cut * <> 2) (cut + 10 <>)) | |
;; 16 | |
(across 3 (cut * <> 2) (cut + 10 <>) x->string) | |
;; "16" | |
(across (+ 1 2 3) | |
odd?) | |
;; #f | |
(across '(1 2 3 4 5) | |
length | |
odd?) | |
;; #t | |
(use srfi-1) | |
(across (iota 10) | |
(cut filter even? <>) | |
(cut fold + 0 <>)) | |
;; 20 | |
(define-syntax across | |
(syntax-rules () | |
((_ exp) exp) | |
((_ exp1 exp2) | |
(exp2 exp1)) | |
((_ exp1 exp2 exp3 ...) | |
(let1 val (across exp1 exp2) | |
(across val exp3 ...))) | |
)) | |
(define-syntax across-right | |
(syntax-rules () | |
((_ exp) exp) | |
((_ exp1 exp2) | |
(exp1 exp2)) | |
((_ exp1 exp2 exp3 ...) | |
(exp1 (across-right exp2 exp3 ...))))) | |
(across-right x->string | |
(cut + 10 <>) | |
(cut * <> 2) | |
3) | |
;; "16" | |
追記
本家ソースはこれかな。追記2
コメント欄で教えていただきました!名前が良いなぁ。let1 要らないですね。。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax across | |
(syntax-rules () | |
((_ exp) exp) | |
((_ exp1 exp2) | |
(exp2 exp1)) | |
((_ exp1 exp2 exp3 ...) | |
(across (exp2 exp1) exp3 ...)))) |
見覚えがあると思って探したらこういう記事がありました。
返信削除http://d.hatena.ne.jp/mtakuya/2009082/p1
名前は -> と付けてますね。
名前が良くてカッコイイですね!
返信削除