mccad 发表于 2012-9-2 19:47:36

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>

mccad 发表于 2012-9-2 19:47:50

示例预留

【KAIXIN】 发表于 2012-10-5 16:55:31

;画一条直线
(defun c:XX()
    (setq a '("line" (0 0) (100 100) ""))
    (apply 'command a)
)

Throne 发表于 2014-12-4 18:15:31

;求点表中心
(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))
)
)

Throne 发表于 2014-12-4 18:16:04

;;从点列表(point list)得到坐标范围(coordinate extents).
(defun GetExtents (plist /)
(list
    (apply 'mapcar (cons 'min plist))
    (apply 'mapcar (cons 'max plist))
)
)

Throne 发表于 2014-12-6 13:23:27

;; 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]
查看完整版本: apply 将参数表传给指定的函数