Emacs Lisp ããããªãæããåã®ç®ãããEmacs Lisp ããã¡ã ã¨æãã¨ãããã¾ã¨ãã¦ããã¾ãã
æåçãªåé¡
Emacs Lisper ã®å¤ãã¯ãLisp ã好ãã§ä½¿ã£ã¦ããã®ã§ã¯ãªããEmacs ã好ãã ããããããªã使ã£ã¦ããã®ã§ããããæ¬å½ã¯ C ã§æ¸ãããã®ã«ãç¡çã㦠Lisp ãå©ç¨ãã¦ããæãã§ãã
ãã®ãããEmacs ã«ä»ãã¦ãã Emacs Lisp ã®ã³ã¼ãã¯ãLisp ããããªããã®ãã»ã¨ãã©ã§ããåã« C ã§ã®çºæ³ã Lisp ã§è¡¨ç¾ãã¦ãã¾ãã
ãããã®ã³ã¼ãã¯ãèªã¿ããªããªããããé¢æ°ã大ãããå¯ä½ç¨ã®ããé¨åã¨ãªãé¨åãåé¢ããã¦ãã¾ãããã¾ãé«éé¢æ°ãç¨ãã¦ããã¼ã¿æ§é ãèµ°æ»ããã³ã¼ãã¨å®éã«ä»äºãããã³ã¼ããåé¢ããã¨ããæèãä½ãããã§ãã
Google ã® MapReduceã¨ããè«æã®ãé°ã§ãLisp ã®ååé¢æ°(map)ã¨ç³è¾¼ã¿é¢æ°(reduce)ããé¢æ°åè¨èªåå¤ã®äººããã注ç®ãããããã«ãªãã¾ãããEmacs Lisp ã«ã¯ãmapcar ã¯ããã¾ãããreduce ãæ¨æºã§æä¾ããã¦ããªãã®ã¯ããã¾ãã«æ®å¿µã§ãã('cl ã require ããã¨ä½¿ããããã«ãªãã¾ãã)
å¤ãã®äººã C ã£ã½ãã³ã¼ããæ¸ãã®ã§ããããåèã«ãã人ã C ã£ã½ãã³ã¼ããæ¸ãããã«ãªãã¾ãã(åãããã§ããã)
åèï¼
æ«å°¾å帰ã®æé©åããªã
Emacs Lisp ã§ã大ããªç¹°ãè¿ããå帰é¢æ°ã§å®ç¾ããã®ã¯ãç¾å®çã§ã¯ããã¾ãããããã«ã¹ã¿ãã¯ã溢ãã¦ãã¾ãã¾ãããããããªãã®ã§ãwhile æã¨ä»£å ¥ãå¤ç¨ãã¦ç¹°ãè¿ããå®è£ ãã¾ãã
åèï¼
ã¯ãã¼ã¸ã£ããªã
AJAX ã«ãã£ã¦åçºè¦ããã JavaScript ã¯ãã¯ãã¼ã¸ã£ãåçºè¦ãã¾ãããã¯ãã¼ã¸ã£ãããã°ãé¢æ°ãçæããé¢æ°ãªã©ãç°¡åã«å®ç¾ã§ãã¾ãã以ä¸ã¯ãScheme ã§å ç®å¨ãçæããé¢æ°ã®ä¾ã§ãã
(define (make-accumulator increment) (lambda (n) (+ n increment))) (define add2 (make-accumulator 2)) (add2 5) ;; => 7
RMS ã Emacs Lisp ãèæ¡ããã¨ãã«ã¯ããã§ã« Scheme ãããã¾ããããéçã¹ã³ã¼ãã¯é¸ã°ãã«ãåçã¹ã³ã¼ããé¸ã³ã¾ãããã©ãããéçã¹ã³ã¼ãã¯é ãã¨èãã¦ããããã§ãã
Elisp ã® info ã11.9.1 Scopeãããï¼
Emacs Lisp uses dynamic scoping because simple implementations of lexical scoping are slow.
ã¾ãããããã¡ãã¼ã«ã«å¤æ°ãªã©ã®åé¡ãããã¾ããããå ¨é¢çã«éçã¹ã³ã¼ããæ¡ç¨ãããã¨ã¯é£ããã§ããããã
åèï¼
æ£è¦è¡¨ç¾ãããµã
Emacs Lisp ã®æ£è¦è¡¨ç¾ã¯ãããã¯ã¹ã©ãã·ã¥ã®ãåãã§ãã以ä¸ã¯ãã©ãããæå³ã ãç解ã§ãã¾ããï¼
(looking-at "\\(\\*\\*\\|\\?\\?\\)")
ãããªã£ã¦ãã¾ãã®ã¯ã2ã¤ã®çç±ãããã¾ãã
- '(' ãªã©ã®ãã使ãæ©è½ãããã¯ã¹ã©ãã·ã¥ã使ã£ã¦ '\(' ã¨æ¸ããªããã°ãªããªã
- æ£è¦è¡¨ç¾ã®ãªãã©ã«ããªããæååã§è¡¨ç¾ããã®ã§ãããã«ããã¯ã¹ã©ãã·ã¥ãå ã㦠'\\(' ãæ¸ãå¿ è¦ããã
åèï¼
ã¢ã¸ã¥ã¼ã«ã§åå空éãåãããã¨ãã§ããªã
Emacs Lisp ã§ã¯ãã¡ã¤ã«åä½ã§ã¢ã¸ã¥ã¼ã«ãæ§æãã¾ãããåå空éã¯å ¨ä½ã§ãã©ããã§ããã§ããããå¿ ãååã®å é ã«ãèªåã§æ éã«é¸ãã ãã¬ãã£ãã¯ã¹ãä»ããå¿ è¦ãããã¾ããã³ã¼ãã£ã³ã°ä¸ã«é·ãååãå ¥åããªããã°ãªããªãã®ã¯ã¹ãã¬ã¹ã§ãã
ã¹ã¬ããããªã
Emacs Lisp ã§éåææ§ãå®ç¾ããã«ã¯ãTCP ã³ãã¯ã·ã§ã³ãéãããå¤é¨ã³ãã³ããèµ·åããå¿ è¦ãããã¾ããéåæã«å¦çãããä½æ¥ããTCP ã使ããµã¼ãç¸æã ããªãããã®ã§ããããã¼ã«ã«ã®ä½æ¥ã Emacs Lisp ã ãã§éåæã«ããããã¨æã£ã¦ãã§ãã¾ãããå¤é¨ã³ãã³ãã C ãªã©ã§å®è£ ããå¿ è¦ãããã¾ãã
åèï¼
ä»æ§ãããå¤ãã
Emacs Lisp ã®ä»æ§ã¯ããå¤ããã¾ããEmacs ã®ããç¹å®ã®ãã¼ã¸ã§ã³ã ãã対象ã«ã³ã¼ããæ¸ãã®ã¯ç°¡åã§ãããè¤æ°ã®ãã¼ã¸ã§ã³ã対象ã«ããã¨æ³£ãããã«ãªãã¾ããXEmacs ã対象ã«å«ããã¨ãäºæ ã¯ããã«æªåãã¾ãã
ãã®éããå¸åããã©ã¤ãã©ãªãæä¾ããã¦ãããããã require ãã¦ããã³ã¼ããå®è¡ãããã¨ããã¬ãã£ãã¯ã¹ãä»ãã¦ããªãé¢æ°ãæ°ä»ããªãéã«å®ç¾©ããã¾ããããã¨ãèªåã§å·®åãèæ ®ããã³ã¼ããåããªããªããã¨ã£ã¦ãæ²ããæãããã¾ãã
Lint
Emacs Lisp ã®ãã¤ãã³ã³ãã¤ã©ã¼ã¯ãæªä½¿ç¨ã®ãã¼ã«ã«å¤æ°ãæ¤ç¥ãã¦ããã¾ããããããããªãã®ã§ããã®æ©è½ãæ㤠XEmacs ã§ãã¤ãã³ã³ãã¤ã«ãã¦æ¤æ»ãã¾ãã
λè¨ç®éã³ãããã«ãã
Emacs Lisp ã§ã¯ãå¤æ°åã¨é¢æ°åã®ç©ºéãåããã¦ãã¾ãããã®ãããå¤æ°ã«é¢æ°ãä»£å ¥ãã¦ããã¦ããããåã«ååã§å¼ã³åºããã¨ã¯ã§ãã¾ããããã¨ãã°ã以ä¸ã®ã³ã¼ãã¯åãã¾ããã
(let ((add2 (lambda (x) (+ x 2)))) (add2 3))
å¼ã³åºãããã«ã¯ãfuncall ã使ãã¾ããã¾ããé¢æ°ããè¿ãããé¢æ°ãå¼ã³åºãã®ã«ã funcall ã使ããªããã°ãªãã¾ããããã¨ãã°ã以ä¸ã®ã³ã¼ããã¨ã©ã¼ã«ãªãã¾ãã
(((lambda () (lambda (x) (+ x 2)))) 3)
ãããã®å¶ç´ãé常ã®ããã°ã©ãã³ã°ã§åé¡ã«ãªããã¨ã¯ãã»ã¨ãã©ããã¾ãããããããλè¨ç®ãã·ãã¥ã¬ã¼ãããããã¨ããã¨ãå«ã«ãªãã¾ãã
Scheme ã§ã¯ãã©ã¡ãã®ã³ã¼ããåãã¾ããããλè¨ç®ãã·ãã¥ã¬ã¼ããããã¨ã㯠scheme ãé¸ã¶ã®ãå¾çã§ãã
åèï¼
ãªã¼ããã¯ãããªã
ãªã¼ããã¯ãããªãã®ã§ãåç½®æ§æã®å¶ç´ããæãåºãã¾ããããã¨ãã°ãããã·ã¥ããã¼ã§æ¤ç´¢ããã®ã以ä¸ã®ããã«æ¸ããã°ä¾¿å©ã§ãããããã¯ç¡çã§ãã
hash=>key
åèï¼
æ§é ä½ããªã
æ§é ä½ãæ¨æºã§æä¾ããã¦ãã¾ããã'cl ã require ããã°ãCommon Lisp ã® defstruct ã使ããããã«ãªãã¾ãããå㯠setter ããªããã®ãã¯ãã¯å¥½ãã«ãªãã¾ããã
åèï¼
å¤ç¸æ§ããªã
ç·ç§°é¢æ°ãããã°ãè¤æ°ã®åãæ±ãé¢æ°ã«å¯¾ããåãã¨ã«åä½ãç»é²ãã¦ããã¾ãã
ããããEmacs Lisp ã«ã¯åå¤æ°ãæä¾ããã¦ãã¾ãããã§ããããè¤æ°ã®åãæ±ãé¢æ°ã¯ãä¸ã«æã§å®ç¾©ãã¦å é¨ã§åã«å¿ãã¦ã¹ã¤ãã(cond)ããå¿ è¦ãããã¾ãã
åèï¼