apply 将参数表传给指定的函数
<P id=crleadin class=cr_leadin>将参数表传给指定的函数</P><PRE class=prog_in_end>(apply ’function list)</PRE><P class=Heading-2>参数</P>
<P class=define_head>’function</P>
<P class=define_text>函数,可以是表示 defun 或 lambda 表达式的符号。</P>
<P class=define_head>list</P>
<P class=define_text>表。如果函数不接收参数,则该参数为 nil。</P>
<P class=Heading-2>返回值</P>
<P class=body>函数调用的结果。</P>
<P class=Heading-2>示例</P>
<P class=prompt_end>命令: <SPAN class=CharSansBold>(apply '+ '(1 2 3))</SPAN> </P>
<P class=prompt_end>6</P>
<P class=prompt_end>命令: <SPAN class=CharSansBold>(apply 'strcat '("a" "b" "c"))</SPAN> </P>
<P class=prompt_end>"abc"</P> 示例预留 ;画一条直线
(defun c:XX()
(setq a '("line" (0 0) (100 100) ""))
(apply 'command a)
) ;求点表中心
(defun avg_pts (lst / n)
(setq n (float (length lst)))
(mapcar '/ (apply 'mapcar (cons '+ lst)) (list n n n))
)
(defun avg_pts2 (lst / n)
(setq n (float (length lst)))
(mapcar (function (lambda (x) (/ x n)))
(apply 'mapcar (cons '+ lst))
)
) ;;从点列表(point list)得到坐标范围(coordinate extents).
(defun GetExtents (plist /)
(list
(apply 'mapcar (cons 'min plist))
(apply 'mapcar (cons 'max plist))
)
) ;; if you only want the X and Y values
(setq p (apply '(lambda (x y z)(list x y))(getpoint "\nPick a point: ")))
;; if you want to reverse the X and Y values
(setq p (apply '(lambda (x y z)(list y x))(getpoint "\nPick a point: ")))
页:
[1]