Previous: Def Cmd Conventions, Up: Definition Commands [Contents][Index]
´Ø¿ôÄêµÁ¤Ï¡¤@defun
¤È@end defun
¤ò»ÈÍѤ·¤Þ¤¹¡¥´Ø¿ô̾¤Ï
@defun
¥³¥Þ¥ó¥É¤Îľ¸å¤Ë³¤¡¤Æ±¤¸¹Ô¤Ë¥Ñ¥é¥á¡¼¥¿¥ê¥¹¥È¤¬Â³¤¤Þ¤¹¡¥
Calling Functions in The GNU Emacs Lisp Reference Manual¤Î ÄêµÁ¤Ë¤Ï°Ê²¼¤Î¤â¤Î¤¬¤¢¤ê¤Þ¤¹¡¥
- Function: apply function &rest arguments
apply
¤Ïarguments¤Çfunction¤ò¸Æ¤Ó½Ð¤·¡¤funcall
¤Ë»÷¤Æ¤¤¤Þ¤¹¤¬¡¤°ìÅÀ¤¬°Û¤Ê¤ê¤Þ¤¹¡¥arguments¤Î½ª¤ê¤Ï¡¤ function ¤ËÍ¿¤¨¤é¤ì¤ëñ°ì¤Î°ú¿ô¤Ç¤Ï¤Ê¤¯°ú¿ô¤Î¥ê¥¹¥È¤Ç¤¹¡¥²æ¡¹¤Ï¡¤ ¤³¤Î¥ê¥¹¥È¤¬Â¾¤Î°ú¿ô¤Ëappend¤µ¤ì¤ë¤È¤â¸À¤Ã¤Æ¤¤¤Þ¤¹¡¥
apply
¤Ïfunction¸Æ¤Ó½Ð¤·¤Î·ë²Ì¤òÊÖ¤·¤Þ¤¹¡¥funcall
¤Î¤è ¤¦¤Ë¡¤function¤ÏLisp´Ø¿ô¤ä¥×¥ê¥ß¥Æ¥£¥Ö´Ø¿ô¤Ç¤¢¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡¥¥¹ ¥Ú¥·¥ã¥ë¥Õ¥©¡¼¥à¤È¥Þ¥¯¥í¤Ï¡¤apply
¤Ç¤Ï°ÕÌ£¤¬¤¢¤ê¤Þ¤»¤ó¡¥(setq f 'list) ⇒ list (apply f 'x 'y 'z) error→ Wrong type argument: listp, z (apply '+ 1 2 '(3 4)) ⇒ 10 (apply '+ '(1 2 3 4)) ⇒ 10 (apply 'append '((a b c) nil (x y z) nil)) ⇒ (a b c x y z)
apply
¤ò»ÈÍѤ·¤¿¶½Ì£¿¼¤¤Îã¤Ï¡¤mapcar
¤Îµ½Ò¤Ç¸«ÉÕ¤«¤ê¤Þ¤¹¡¥
Texinfo¥½¡¼¥¹¥Õ¥¡¥¤¥ë¤Ç¤Ï¡¤¤³¤ÎÎã¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥
@defun apply function &rest arguments @code{apply}¤Ï@var{arguments}¤Ç@var{function}¤ò¸Æ¤Ó½Ð¤·¡¤ @code{funcall}¤Ë»÷¤Æ¤¤¤Þ¤¹¤¬¡¤1ÅÀ°Û¤Ê¤ê¤Þ¤¹¡¥@var{arguments}¤Î½ª¤ê ¤Ï¡¤@var{function}¤ËÍ¿¤¨¤é¤ì¤¿Ã±°ì¤Î°ú¿ô¤Ç¤Ï¤Ê¤¯°ú¿ô¤Î¥ê¥¹¥È¤Ç¤¹¡¥²æ¡¹ ¤Ï¡¤¤³¤Î¥ê¥¹¥È¤¬Â¾¤Î°ú¿ô¤Ë@dfn{²Ã¤¨¤é¤ì¤ë}¤È¤â¸À¤Ã¤Æ¤¤¤Þ¤¹¡¥
@code{apply}¤Ï@var{function}¸Æ¤Ó½Ð¤·¤Î·ë²Ì¤òÊÖ¤·¤Þ¤¹¡¥ @code{funcall}¤Î¤è¤¦¤Ë¡¤@var{function}¤ÏLisp´Ø¿ô¤ä¥×¥ê¥ß¥Æ¥£¥Ö´Ø¿ô ¤Ç¤¢¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡¥¥¹¥Ú¥·¥ã¥ë¥Õ¥©¡¼¥à¤È¥Þ¥¯¥í¤Ï¡¤@code{apply}¤Ç¤Ï °ÕÌ£¤¬¤¢¤ê¤Þ¤»¤ó¡¥
@example (setq f 'list) @result{} list (apply f 'x 'y 'z) @error{} Wrong type argument: listp, z (apply '+ 1 2 '(3 4)) @result{} 10 (apply '+ '(1 2 3 4)) @result{} 10 (apply 'append '((a b c) nil (x y z) nil)) @result{} (a b c x y z) @end example
@code{apply}¤ò»ÈÍѤ·¤¿¶½Ì£¿¼¤¤Îã¤Ï¡¤@code{mapcar}¤Îµ½Ò¤Ç¸«ÉÕ¤«¤ê ¤Þ¤¹¡¥ @end defun
¤³¤Î¥Þ¥Ë¥å¥¢¥ë¤Ç¤Ï¡¤¤³¤Î´Ø¿ô¤Ïapply
¤Î²¼¤Î¥³¥Þ¥ó¥É¤ÈÊÑ¿ôº÷°ú¤Ë¥ê¥¹
¥È¥¢¥Ã¥×¤µ¤ì¤Æ¤¤¤Þ¤¹¡¥
Ä̾ï¤ÎÊÑ¿ô¤È¥æ¡¼¥¶¡¼¥ª¥×¥·¥ç¥ó¤Ï¡¤ÊÑ¿ô¤¬°ú¿ô¤ò¼è¤é¤Ê¤¤°Ê³°¡¤´Ø¿ô¤ËÂФ¹¤ë ¤â¤Î¤Ë»÷¤¿½ñ¼°¤ò»ÈÍѤ·µ½Ò¤µ¤ì¤Þ¤¹¡¥