Skip to content

expressions inside setq #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jgarte opened this issue Dec 20, 2021 · 4 comments
Open

expressions inside setq #523

jgarte opened this issue Dec 20, 2021 · 4 comments

Comments

@jgarte
Copy link
Contributor

jgarte commented Dec 20, 2021

Hi, I get this error when opening emacs:

Error (leaf): Error occurs in leaf block: scheme
Error (leaf): Attempt modify list;  Please check your specification
Error (leaf): Error occurs in leaf block: scheme
Error (leaf): Attempt modify list;  Please check your specification

I'd like to do something like the following:

(leaf scheme
  :doc "the universe is made of atoms and pairs"
    :setq
     ((home-sweet-home . (getenv "HOME")
     (scheme-program-name . (concat home-sweet-home ".guix-profile/bin/guile"))))

This is what macroexpand outputs:

(prog1 'scheme
  (leaf-handler-leaf-path scheme)
  (leaf-handler-leaf-protect scheme
    (setq home-sweet-home nil)
    (setq getenv nil)
    (setq scheme-program-name nil)
    (setq concat nil)
    (setq home-sweet-home nil)))

Or

(prog1 'scheme
  (let
      ((file
        (leaf-this-file)))
    (if
        (boundp 'leaf--paths)
        nil
      (defvar leaf--paths nil))
    (if file
        (progn
          (add-to-list 'leaf--paths
                       (cons 'scheme file)))))
  (condition-case err
      (progn
        (setq home-sweet-home nil)
        (setq getenv nil)
        (setq scheme-program-name nil)
        (setq concat nil)
        (setq home-sweet-home nil))
    (error
     (display-warning 'leaf
                      (format "Error in `scheme' block.  Error msg: %s"
                              (error-message-string err))))))

Do you happen to know what is wrong with my code? Why are the values of setq set to nil...? 🦆

What would be the best way to debug this?

@conao3
Copy link
Owner

conao3 commented Dec 20, 2021

related: #520
Maybe you want this leaf form

(leaf scheme
  :doc "the universe is made of atoms and pairs"
  :setq
  `((home-sweet-home . ,(getenv "HOME"))
    (scheme-program-name . ,(concat home-sweet-home ".guix-profile/bin/guile"))))

but you will get below error.

;;=> Debugger entered--Lisp error: (void-variable home-sweet-home)
;;     (concat home-sweet-home ".guix-profile/bin/guile")

cus leaf (or Elisp) 'know' valiable value at macro expansion phase.

As long as Emacs know the variables during macro expansion, it can evaluate them while expanding the desired S expression.
In other words, you can use setq before it. Note that if you are want to use byte-compile your config, you need to use eval-when-compile to tell the Elisp byte compiler about the variables.

@conao3
Copy link
Owner

conao3 commented Dec 20, 2021

(setq home-sweet-home (getenv "HOME"))

(leaf scheme
  :doc "the universe is made of atoms and pairs"
  :setq
  `((scheme-program-name . ,(concat home-sweet-home ".guix-profile/bin/guile"))))

or

(leaf scheme
  :doc "the universe is made of atoms and pairs"
  :setq
  `((scheme-program-name . ,(concat (getenv "HOME") ".guix-profile/bin/guile"))))

@AkibAzmain
Copy link

@jgarte @conao3 I have observed that Leaf can't handle any list except ones whose car is either "quote" ('()) or "backquote" ("quasiquote" in Scheme). So my hack is to backquote (or quasiquote) followed by unquote (,):

(leaf scheme
  :doc "the universe is made of atoms and pairs"
  :setq
  ((home-sweet-home . `,(getenv "HOME"))
   (scheme-program-name . `,(concat home-sweet-home ".guix-profile/bin/guile"))))

@AkibAzmain
Copy link

(concat home-sweet-home ".guix-profile/bin/guile")

Are you sure that $HOME ends with a slash? You ought to use (expand-file-name ".guix-profile/bin/guile" home-sweet-home). It would also make it easy to port your config any non-Unix-like (FreeDOS?) operating system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants