0

The following workflow contains the steps needed to reproduce the error:

;; Byte-compile the function.
(byte-compile '(defun flatten (x)
                 (cl-labels ((rec (x acc)
                                  (cond ((null x) acc)
                                        ((atom x) (cons x acc))
                                        (t (rec (car x) (rec (cdr x) acc))))))
                   (rec x nil))))

;; `pp-eval-last-sexp` output.
(byte-code "\300\301\302\"\207"
           [defalias flatten
             #[(x)
               "\302\303\211    \302\")\207"
               [--cl-rec-- x nil
                           #[(x acc)
                             "\306  \n\211\204\0\306\202'\0\f:\204\0\fB\306\202'\0\f@
\fA\"\307*\204\0)\207"
                             [retval x acc acc x --cl-rec-- nil :recurse]
                             4]]
               4]]
           3)

;; Taking out the actual bytecode so as to eval the expression.
(#[(x)
  "\302\303\211 \302\")\207"
  [--cl-rec-- x nil
              #[(x acc)
                "\306   \n\211\204\0\306\202'\0\f:\204\0\fB\306\202'\0\f@
\fA\"\307*\204\0)\207"
                [retval x acc acc x --cl-rec-- nil :recurse]
                4]]
  4] '(1 2 3))

As shown, I byte-compile a function and try to eval it with the argument '(1 2 3). It throws the following error and I don't know why:

Debugger entered--Lisp error: (wrong-type-argument listp 1)
  #f(compiled-function (x acc) #<bytecode 0x4c32e213416e008>)((1 2 3) nil)
  #f(compiled-function (x) #<bytecode -0x1a3b6ef3b20a60c7>)((1 2 3))
  eval((#f(compiled-function (x) #<bytecode -0x1a3b6ef3b20a60c7>) '(1 2 3)) nil)
...
...
...

I've pinpointed that perhaps (cl-labels ((rec (x acc) has something to do with this.

John DeBord
  • 550
  • 3
  • 13
  • 1
    If no-one answers here, you can always ask the experts on the `emacs-devel` mailing list. – Basil Mar 17 '21 at 17:57
  • I have tried your code in an `lisp-interaction-mode` buffer of Emacs 27.1.90 and the evaluation step at the end gives the result `(1 2 3)`. I also changed the argument `'(1 2 3)` to `'(1 (21 22) 3)` and this gives the result `(1 21 22 3)`. – Tobias Mar 25 '21 at 05:31
  • Note that the byte code looks quite different on Emacs 27.1.90: `(byte-code "\300\301\302\"\207" [defalias flatten #[257 "\300C\211\301\302\303\304\305^F^F!\306\"\307\310%\240\210\211\242^B\300\"\207" [nil make-byte-code 514 "^A\204^E\0\207^A:\204^N\0^A^AB\207\300\242^B@\300\242^DA^D\"\"\207" vconcat vector [] 7 " (fn X ACC)"] 9 " (fn X)"]] 3)` – Tobias Mar 25 '21 at 05:49

0 Answers0