An undocumented function called rec in Common Lisp source with labels?

I notice that this function called recappears many times in the Common Lisp code, but I can’t find a link to what it actually does. Can someone explain to me what this is? For example, it appears in some code from another question, How to convert a flat list into a nested tree structure? :

(defun mimicry (source pattern)
  (labels ((rec (pattern)
             (mapcar (lambda (x)
                       (if (atom x)
                         (pop source)
                         (rec x)))
                     pattern)))
    (rec pattern)))
+4
source share
1 answer

recis not a global function in your code unless you define it that way. This is a local helper function defined with labels.

labels defun, , . defparameter let .

(labels ((banana (arg1)    ; make function banana
           (+ arg1 arg1)))
  (banana 10))             ; use it
; banana doesn't exist anymore

, :

(defun banan (arg1) ; make function banana
  (+ arg1 arg1))
(banana 10)         ; use it
; banana still exists

, labels, defun . labels , , rec, loop aux , .

, flet, , , . , rec, rec - .

CL, . rec loop ( Lisp), , CL, , , CL SO, aux test-aux , test.

+8

All Articles