0

I am using a variable storing a cons cell

(defvar typex-frame-position (cons 1270 1223))

Followed by

(setq initial-frame-alist
  '((left . (car typex-frame-position))
    (top . (cdr typex-frame-position))
    (width . 73) (height . 21)))

But, the only way I get the frame at the correct position is to hardwire the numbers like this.

(setq initial-frame-alist
  '((left . 1270)
    (top . 1223)
    (width . 73) (height . 21)))

How can I use the values from typex-frame-position?

Dilna
  • 1,173
  • 3
  • 10
  • I do not understand the description about backward quote, why I have to use it, and how to use it in my case. – Dilna Sep 18 '22 at 00:27
  • What about this one? [How to evaluate the variables before adding them to a list?](https://emacs.stackexchange.com/questions/7481/how-to-evaluate-the-variables-before-adding-them-to-a-list) – db48x Sep 18 '22 at 00:35
  • It is not helping at all. Because they relate to things that are different from what I am doing and fail to understand how to apply what you are saying. I need an explanation of the solution and why it is needed, but has to be direct on what I am doing here. – Dilna Sep 18 '22 at 00:42
  • The `'` suppresses evaluation, allowing you to write a literal list. but `(car typex-frame-position)` is an expression that you want to evaluate. So you need to use ` instead: `((left ,(car …)) …)). – db48x Sep 18 '22 at 00:47
  • In more simple terms, the quoting in front of the list passed to `initial-frame-alist` suppresses any evaluation. Meaning that `(car typex-frame-position)` is not evaluated, and consequently the value of the expression does not get associated with `left`. Using `,` allows `(car typex-frame-position)` to be evaluated to the value `1270`. Right? – Dilna Sep 18 '22 at 00:56
  • Right, but you can only use a `,` inside of a backquoted expression. Using it inside an ordinary quoted expression doesn’t work. – db48x Sep 18 '22 at 00:57
  • I understand how things work now. – Dilna Sep 18 '22 at 00:59
  • It works very well, and things function as planned. – Dilna Sep 18 '22 at 01:00
  • I may be mistaken, but this thing is not described in the Emacs Lisp Tutorial. – Dilna Sep 18 '22 at 01:02
  • Nope. It is described in the Emacs Lisp Manual though. – db48x Sep 18 '22 at 01:04
  • Would the backquote also be applicable if instead of `(car typex-frame-position)`, I had a variable like `fxpos` ? – Dilna Sep 18 '22 at 01:07
  • Yes, you would put the comma in front of any expression of any type that you wanted to be evaluated instead of quoted. – db48x Sep 18 '22 at 01:09
  • Thusly, doing `(left . ,fxpos)` would evaluate to the value `1270`. – Dilna Sep 18 '22 at 01:19

1 Answers1

0

Summary of discussion with @db48x

Quoting in front of the list passed to initial-frame-alist suppresses any evaluation - meaning that (car typex-frame-position) is not evaluated.

In addition to quote a list, tho Backquote construct allows one to evaluate expressions by using the comma marker.

Thus

(setq initial-frame-alist
  `((left . ,(car typex-frame-position))
    (top . ,(cdr typex-frame-position))
    (width . 73) (height . 21)))
Dilna
  • 1,173
  • 3
  • 10