reddit / emacs

Why should pushnew work in a program but not cl-pushnew?

vfclists · 2022-08-06 12:02
I changed `cl-pushnew` to `pushnew` in a file which used it and it worked. After looking at the info it seems that there is some conflict between `cl` and `cl-lib` and having both installed seems to the problem. The conclusion for me is that although `cl-pushnew` is defined in `cl-lib` the loading of `cl` seemed to void it in some way. Every now and then I get a warning that I should use `cl is deprecated`. How do I get rid of it? I don't think I have `require'd` it in my own code, but other libraries seem to depend on it. **Info on pushnew** pushnew is an alias for ‘cl-pushnew’ in ‘cl.el’. (pushnew X PLACE [KEYWORD VALUE]...) Add X to the list stored in PLACE unless X is already in the list. PLACE is a generalized variable that stores a list. Like (push X PLACE), except that PLACE is unmodified if X is ‘eql’ to an element already in the list stored in PLACE. Keywords supported: :test :test-not :key **Info on cl-pushnew** cl-pushnew is a Lisp macro in ‘cl-lib.el’. (cl-pushnew X PLACE [KEYWORD VALUE]...) Add X to the list stored in PLACE unless X is already in the list. PLACE is a generalized variable that stores a list. Like (push X PLACE), except that PLACE is unmodified if X is ‘eql’ to an element already in the list stored in PLACE. Keywords supported: :test :test-not :key [back] [forward]
usaoc · 2022-08-06 12:24
Try posting a minimal example that reproduces the problem, otherwise no one can guess what the problem is.
vfclists · 2022-08-06 12:52
I installed a package https://gitlab.com/mtekman/elisp-depmap.el and the installation warned about `cl-pushnew` and other related functions being undefined. The `cl-pushnew` error occurred when I run its commands so I went into the file `elisp-depmap-parse` and changed `(cl-pushnew name mentions)` to `(pushnew name mentions` and that fixed it. If you want to test it you need replace the `:config` command in the `use-package` to ` :custom (elisp-depmap-exec-file "~/graphviz2.dot" "Location of dot file... etc")`
usaoc · 2022-08-06 13:06
Ask the maintainer to patch the file. `cl-lib` should’ve been explicitly `require`d.
flexibeast · 2022-08-06 13:35
My guess is that the problem is that the author doesn't have a `(require 'cl-lib)` line at the start of `elisp-depmap-parse.el`. Do things work if you evaluate that form yourself before trying to use any of the package's functions?
vfclists · 2022-08-06 14:09
I didn't try it myself, but adding `(require 'cl-lib)` in the file allows it work. I required `(cl-lib)` manually before but it still didn't work although it appears quite early in my `features` list. Does the failure have something to do with some `autoloads` in the file or some other compilation related issue?
usaoc · 2022-08-06 15:15
`cl-pushnew` is a macro, so the feature must also be available at compile time, given that macros and inline functions are processed ahead of time by the compiler. `require`ing the feature at top level of the package makes the feature available both at compile time and execution time, while `require`ing the feature before loading the package only makes the feature available at execution time.