Skip to main content
24 votes
Accepted

require 'cl or require 'cl-lib

The first is the old library, the second is the new one. The old one defines things like defstruct, symbol-macrolet, incf, whereas the second defines instead cl-defstruct, cl-symbol-macrolet, and cl-...
Stefan's user avatar
  • 26.5k
6 votes

Is using cl-lib crucial for writing good Emacs Lisp code?

No, it's definitely not crucial: A quick sed | sort | uniq -c says that within Emacs's own code we have: [...] 20 (cl-ecase 24 (cl-labels 26 (cl-callf 26 (cl-defmacro 26 (cl-dolist 26 (cl-...
Stefan's user avatar
  • 26.5k
4 votes

Defining a generic function and implementing specialised methods

An attempt... (require 'cl-generic) ;; Checking accounts can have a negative balance ;; Savings accounts can't (cl-defstruct checking-account balance) (cl-defstruct savings-account balance) ;; A ...
antonio's user avatar
  • 1,822
3 votes
Accepted

Why does pp-macroexpand return nonsense for cl-loop?

As phils pointed out, the reason is that those symbols are uninterned. You can set print-gensym and print-circle to t to get uninterned symbols to print correctly. Once that is done, the expansion ...
d125q's user avatar
  • 1,463
3 votes

Why is cl-loop autoloaded on byte-compilation?

This is a bug (will be fixed in 27.1); https://debbugs.gnu.org/30635
throwaway_xa3I's user avatar
3 votes
Accepted

Why is cl-loop autoloaded on byte-compilation?

byte-compile-file comes from bytecomp.el which (require 'cl-lib), thus cl-lib is always already loaded before any byte compilation. The info manual does also not contain any information about ...
xuchunyang's user avatar
  • 14.6k
3 votes

with-slots with defstruct "class" instance

While waiting for a better answer, I wrote a with-slots macro that seems to work with defstruct instances: (defmacro my-with-slots (class-name slots obj &rest body) "Bind slot names SLOTS ...
erjoalgo's user avatar
  • 873
3 votes

cl-lib isn't loaded the first time an autoloaded function is used from it

It's an internal autoload of the cl-lib package, not a global autoload. cl- has no global autoloads. To use cl- functions, require cl-lib. To use cl- macros, eval-when-compile require cl-lib.
ocoh2's user avatar
  • 31
3 votes
Accepted

Equivalent of EIEIO's make-instance for cl-lib structs?

Actually, the cl-defstruct macro does preserve enough info to make such a function possible, but I don't think anyone has written such a beast yet. The way this info is stored has changed in Emacs-25:...
Stefan's user avatar
  • 26.5k
2 votes

Indenting `cl-flet` etc

This is not possible with the current codebase, there is an open bug for it. Fixing it should be a matter of copying the functionality from cl-indent.el without getting the misindenting of defcustom, ...
npostavs's user avatar
  • 9,223
2 votes
Accepted

Using local variables in cl-loop

Thanks to bpalmer in #emacs for helping me solve this. The issue was with the and after for start...; instead, it needed to be another for (or as). I chose to use as instead of the other fors since it ...
aiguofer's user avatar
  • 588
2 votes

Search for occurrence of character within a string without using the common lisp library?

It looks like you ultimately want the characters between % and & in the buffer name? You might do this: (let ((s (buffer-name))) (string-match "%\\(.*?\\)&" s) (match-string 1 s))
phils's user avatar
  • 51.8k
2 votes
Accepted

Alternative way to disambiguate "dangling else" in a cl-loop

I think this is what you want: (let ((flag1 nil) (flag2 nil)) (cl-loop if flag1 if flag2 return 1 else return 0 else return 2)) if flag1 is nil, you get 2 if flag1 is t, and flag2 ...
John Kitchin's user avatar
  • 11.9k
2 votes
Accepted

Symbol's function definition is void: cl-loop

The direct solution is to (require 'cl-lib) somewhere, but this is a trivial enough loop that Emacs comes with a macro specifically for it, without needing cl-lib: (dolist (face (face-list)) (set-...
Stefan's user avatar
  • 26.5k
1 vote

Why does pp-macroexpand return nonsense for cl-loop?

The --cl-vec-- and --cl-idx-- symbols (and other similarly-named symbols, should you see any) are uninterned, and there may be more than one of each. You're only seeing the printed representation of ...
phils's user avatar
  • 51.8k
1 vote
Accepted

How to create a structure instance out of a -pkg.el file?

(package-load-descriptor DIRECTORY) will read the *-pkg.el file in the given directory, create a new package-desc structure object, add it to package-alist and return the object. That seems to cover ...
phils's user avatar
  • 51.8k
1 vote

Equivalent of `continue' in `cl-loop'?

As @NickD pointed out, you can also use cl-block and cl-return-from to simulate continue. (cl-loop for item in '(1 2 3 4) with items ;; declare variable `items' ...
Firmin Martin's user avatar
1 vote

Equivalent of `continue' in `cl-loop'?

This "answer" is not meant to be an the answer to the question because it is not "using cl-loop". But rather provide an alternative (as many other answers have done already). I ...
Aquaactress's user avatar
  • 1,453
1 vote

Equivalent of `continue' in `cl-loop'?

If you are looking for short-circuiting logic, e.g. nothing proceeds after one condition fails, I think you need to use something like the and macro. I don't know a way to do this other than to let ...
John Kitchin's user avatar
  • 11.9k
1 vote
Accepted

Is it necessary for me to use `cl-labels` in this grouping function, when plain recursion does the job as well?

It's not necessary to use cl-labels, but note that recursing over *hx/group-recurse imposes some overhead in that it must test (> 0 group-size) every call, when obviously that is not needed beyond ...
phils's user avatar
  • 51.8k
1 vote

Indenting `cl-flet` etc

Define the indentation for a given function/macro etc. by putting the indentation spec on the function etc. symbol as property common-lisp-indent-function. As one possible example: (put 'cl-flet ...
Drew's user avatar
  • 78.1k
1 vote

cl-lib isn't loaded the first time an autoloaded function is used from it

As ocoh2 points out, cl-lib is not autoloaded, the only way to get it is to require it or have it indirectly autoloaded (some autoloaded package requires it). It must be the Debugger that loads cl-...
jpkotta's user avatar
  • 508
1 vote

How can I use edebug with cl-block?

Edebug is arguably right: The tag is not evaluated and needs to be a symbol, not (quote foo).
politza's user avatar
  • 3,346

Only top scored, non community-wiki answers of a minimum length are eligible