é¢æ°ã®ããã¥ã¡ã³ã
Javaã«ã¯Javadocã¨ããæåãªããã¥ã¡ã³ãã³ã¡ã³ããããã
(å®è·µãã¦ãããã©ããã¯å¥ã¨ãã¦)é¢æ°ãã®ä»ã«ããã¥ã¡ã³ããã¤ããã¨ããèãã¯è¯ãã¨æãã
ãã ãJavadocã®å ´åãååã®éã(ä¸å®ã®è¦ç´ã«å¾ã£ã)ã³ã¡ã³ãã使ã£ã¦(é¢æ°ãã®ä»ã®)ææ¸åãè¡ã£ã¦ããã®ã§ã(å¤å)ããã°ã©ã å
ãããã®ããã¥ã¡ã³ãã«ã¢ã¯ã»ã¹ãããã¨ã¯åºæ¥ãªã(ã¨æã)ã
common lispã®å ´åã¯ãææ¸åã®ããã®æ©è½ããããããè¨èªã«çµã¿è¾¼ã¾ãã¦ããã
;; ããã¥ã¡ã³ãä»ãã®é¢æ°å®ç¾© > (defun doc-example () "é¢æ°å®ç¾©ã®ä¸çªç®ã®å¼ãæååã®å ´åããã®é¢æ°ã®ããã¥ã¡ã³ãã¨èªèããã" 'done) --> DOC-EXAMPLE ;; ããã¥ã¡ã³ããåç §ãã > (documentation 'doc-example 'function) --> "é¢æ°å®ç¾©ã®ä¸çªç®ã®å¼ãæååã®å ´åããã®é¢æ°ã®ããã¥ã¡ã³ãã¨èªèããã" ;; ã¤ãã§ã«é¢æ°ãå®è¡ > (doc-example) --> DONE
ãã®å ´åãä¸ã®ä¾ã«ãããããã«ãããã°ã©ã å ããç°¡åã«åç §ã§ããã®ã§ãå°ã便å©*1ã
åé¡ç¹
ãã ãcommon lispã®ããã¥ã¡ã³ãæ©è½ã«ã¯åé¡*2ãããã
以ä¸ããã®ä¾ã
;; common lispã®ããã¥ã¡ã³ãã®åé¡ç¹ã示ããé¢æ°å®ç¾© ;; é·ãã³ã¡ã³ããå®ç¾©æ¬ä½ãåããã«ãããã¦ããã (defun Hello (name) "ããã¯ãHelloé¢æ°ã®ããã¥ã¡ã³ãã§ãã Helloé¢æ°ã¯ãä¸ã¤ã®å¼æ°ãåãã¨ãã¾ãã å¼æ°ã®ååã¯ãnameã§ãã nameã¯ã©ããªåã§ãæ§ãã¾ããã Helloé¢æ°ã¯ãåãåã£ãnameããã¨ã«ã次ã®ãããªåºåãè¡ãã¾ãã \"Hello [name]!\" # [name]ã®é¨åã¯ãå¼æ°nameã®å¤ã§å±éããã¾ãã ãã®é¢æ°ã®æ»ãå¤ã¯æªå®ç¾©ã§ãã" (format t "Hello ~A!" name))
ããã¥ã¡ã³ãã¯ååã«èª¬æçã«æ¸ãã®ãæã¾ããã¨æãããããããã¨é¢æ°å®ç¾©æ¬ä½ãåããã«ãããªã£ã¦ãã¾ã(ã¨å人çã«ã¯æã)ã
Javadocãçä¼¼ã¦ãç¹æ®ãªè¦ç´ã«å¾ã£ã¦ã³ã¡ã³ããæ¸ãã¦ããããããã¥ã¡ã³ãã¨ããæ¹æ³ããããããã®å ´åå°ç¨ã®ãã¼ãµ*3ãå¿
è¦ã ããæ¢ã«æ¸ããããã«ããã°ã©ã å
ããåç
§ããã®ãé£ãããªã£ã¦ãã¾ãã
解決ç
ã§ããã®è§£æ±ºçã
åç
§: nlet
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Javadoc風ã®(é¢æ°å®ç¾©ã®ä¸ã«)ããã¥ã¡ã³ããæ¸ãããã®æºå ;; ããã¥ã¡ã³ãå 容ãæ ¼ç´ãã¦ããããã®å¤æ° (defvar *doc* "") ;; å ¥åã¹ããªã¼ã ãããåend-quotsãæ¤åºããã¾ã§ãæåãèªã¿è¾¼ã ;; èªã¿è¾¼ãã æåã®åã¯ãæååã¨ãã¦è¿ã (defun read-string (end-quots stream) (let ((len (length end-quots)) (end-quots (reverse end-quots))) (flet ((eos-reached? (s) (= (mismatch end-quots s) len))) (nlet self ((c #1=(read-char stream)) str) (if (eos-reached? str) (coerce (nreverse (nthcdr len str)) 'string) (self #1# (cons c str))))))) ;; #/.../#å½¢å¼ã®æååããªã¼ããã¯ãã¨ãã¦ç»é²ãã ;; æå¾ã«èªã¿è¾¼ã¾ããä¸è¨å½¢å¼ã®æååã¯ãå¤æ°*doc*ã«æ ¼ç´ããã¦ãã ;; TODO: nilãè¿ãæ¹ãè¯ã? (set-dispatch-macro-character #\# #\/ (lambda (stream char arg) (declare (ignore char arg)) (setf *doc* (read-string "/#" stream)))) ;;;;;;;;;;;;; ;;;; é¢æ°å®ç¾© #/ ããã¯ãHelloé¢æ°ã®ããã¥ã¡ã³ãã§ãã Helloé¢æ°ã¯ãä¸ã¤ã®å¼æ°ãåãã¨ãã¾ãã å¼æ°ã®ååã¯ãnameã§ãã nameã¯ã©ããªåã§ãæ§ãã¾ããã Helloé¢æ°ã¯ãåãåã£ãnameããã¨ã«ã次ã®ãããªåºåãè¡ãã¾ãã "Hello [name]!" # [name]ã®é¨åã¯ãå¼æ°nameã®å¤ã§å±éããã¾ãã ãã®é¢æ°ã®æ»ãå¤ã¯æªå®ç¾©ã§ãã /# (defun Hello (name) #.*doc* (format t "Hello ~A!" name))
ãã£ã¦ãããã¨ã¯ãæååã®å¥è¡¨è¨ã¨ãã¦#/.../#ãå°å
¥ããããã§èªã¿è¾¼ãã æååã*doc*å¤æ°ã«ä¿åãé¢æ°å®ç¾©å
ã§åç
§ãã¦ããã ãã
ãã ãããã ãã§ãé¢æ°å®ç¾©ã¯å¤§åè¦ããããªã£ãããã«æãã
å¾ãä¸ã®æ¹æ³ã®å ´åã#/.../#å
ã§æååãèªã¿è¾¼ãã§ããé¢æ°(read-stringé¢æ°)ãå¥ã®é¢æ°*4ã«å¤æ´ãããã¨ã§ãããã¥ã¡ã³ãç¨ã®ç¹æ®è¨æ³ãªã©ã使ããããã«ã§ãã*5ã¨ããäºç´°ãªã¡ãªãããããã¨æãã
æå¾ã«ãsbcl(1.0.34)ã§ã®describeå®è¡ä¾ã
> (describe 'Hello) COMMON-LISP-USER::HELLO [symbol] HELLO names a compiled function: Lambda-list: (NAME) Derived type: (FUNCTION (T) (VALUES NULL &OPTIONAL)) Documentation: ããã¯ãHelloé¢æ°ã®ããã¥ã¡ã³ãã§ãã Helloé¢æ°ã¯ãä¸ã¤ã®å¼æ°ãåãã¨ãã¾ãã å¼æ°ã®ååã¯ãnameã§ãã nameã¯ã©ããªåã§ãæ§ãã¾ããã Helloé¢æ°ã¯ãåãåã£ãnameããã¨ã«ã次ã®ãããªåºåãè¡ãã¾ãã "Hello [name]!" # [name]ã®é¨åã¯ãå¼æ°nameã®å¤ã§å±éããã¾ãã ãã®é¢æ°ã®æ»ãå¤ã¯æªå®ç¾©ã§ãã Source form: (LAMBDA () (DECLARE (MUFFLE-CONDITIONS COMPILER-NOTE)) (PROGN (SB-INT:NAMED-LAMBDA HELLO (NAME) (BLOCK HELLO (FORMAT T "Hello ~A!" NAME)))))
å°ãæ¹è¯
*doc*å¤æ°ãä¸è¦ã«ããçã
æè»æ§ã¯è¥å¹²å£ã*6ããããã·ã³ãã«ã
;; read-stringé¢æ°ã®å®ç¾©ã¯ãã®ã¾ã¾ ;; #/.../#ã®ç´å¾ã«é¢æ°å®ç¾©ãç¶ããã¨ãæ³å®ãã¦ãã (set-dispatch-macro-character #\# #\/ (lambda (stream char arg) (declare (ignore char arg)) (let ((doc (read-string "/#" stream)) (fn-def (read stream))) (destructuring-bind (defun name arg . body) fn-def `(,defun ,name ,arg ,doc ,@body))))) ;; 使ç¨ä¾ #/ ããã¯ãHelloé¢æ°ã®ããã¥ã¡ã³ãã§ãã Helloé¢æ°ã¯ãä¸ã¤ã®å¼æ°ãåãã¨ãã¾ãã å¼æ°ã®ååã¯ãnameã§ãã nameã¯ã©ããªåã§ãæ§ãã¾ããã Helloé¢æ°ã¯ãåãåã£ãnameããã¨ã«ã次ã®ãããªåºåãè¡ãã¾ãã "Hello [name]!" # [name]ã®é¨åã¯ãå¼æ°nameã®å¤ã§å±éããã¾ãã ãã®é¢æ°ã®æ»ãå¤ã¯æªå®ç¾©ã§ãã /# (defun Hello (name) (format t "Hello ~A!" name))
*1:å¤å大æµã®å¦çç³»ã®describeé¢æ°ã¯ãå¼æ°ã®ã·ã³ãã«ã«ç´ä»ãããã¥ã¡ã³ããããå ´åã¯ä¸ç·ã«è¡¨ç¤ºãã¦ããããsbclã®sb-extãsb-implå ã®é¢æ°ã®æ¦è¦ãç¥ãããã¨ãã«çµæ§éå®ãã¦ããã
*2:åã«ã¹ã¿ã¤ã«=ã³ã¼ãã®è¦æ ãã«é¢ãããã¨ãªã®ã§ãåé¡ã¨æãããã©ããã¯äººã«ããããã ã¨æããã
*3:å ãã¦ãããã¥ã¡ã³ãã¨é¢æ°ã®å¯¾å¿ãä¿æãã¦ããä»çµã¿ãå¿ è¦ãããã«ããããããã¨ã«ãcommon lispã¯Javaã¨ç°ãªããé¢æ°å®ç¾©ãdefunã¨ããæååã§å§ã¾ããªããã°ãªããªãã¨ããå¶ç´ããªãã®ã§ãçµå±ã®ã¨ãããããã¥ã¡ã³ãã³ã¡ã³ããé©åã«èªèããããã«ã¯ãå®å ¨ãªcommon lispã¤ã³ã¿ããªã¿ãå¿ è¦ã«ãªã£ã¦ãã¾ããããããªã
*4:ä¾ãã°åã«ä½æããeLispæååèªã¿è¾¼ã¿é¢æ°
*5:è¨ãæããã°ãããã¥ã¡ã³ãè¨è¿°ã«ç¹åããããè¨èªãå²åæ軽ã«ä½æã»ä½¿ç¨ãããã¨ãå¯è½
*6:defunã¨åãæ§é ãæã£ãå¼ã«ãã使ããªããªã