据我了解,标签的使用是定义一个与 flet 相同但范围更大的本地函数。那是对的吗。我将提供一个例子:
(defun nested-average (tree)
;labels are the same as flet but with higher scope, define local functions
(labels ((%nested-average
;arguments for the function
(branch sum visited)
(cond
((consp branch)
(multiple-value-call
;calls the previous function with reference to the label
#'%nested-average (rest branch)
(%nested-average (first branch) sum visited)))
;is branch a number
((numberp branch)
(values (+ sum branch) (1+ visited)))
;otherwise
(t
(values sum visited))
)
)
)
(multiple-value-call #'/ (%nested-average tree 0 0))
)
)
;(nested-average ' (10 ((30 1) 20) (8 (5 (50 7)) 9) 40))