0

I just learned about the function (mac-frame-geometry). It produces a list in the form of:

'((outer-position 0 . 25)
  (outer-size 1920 . 1055)
  (external-border-size 0 . 0)
  (title-bar-size 1920 . 0)
  (menu-bar-external . t)
  (menu-bar-size 1920 . 24)
  (tab-bar-size 0 . 0)
  (tool-bar-external . t)
  (tool-bar-position . top)
  (tool-bar-size 0 . 0)
  (internal-border-width . 0))

How would I lookup values from this list by symbol name (e.g. menu-bar-size to return ( 0 . 0 ))

It looks like an alist, but ... weird.

1 Answer 1

0

It’s an alist:

(cdr (assoc 'menu-bar-size (mac-frame-geometry))) → (1920 . 24)

Each item in the list is a pair, where the first element is the key and the second is the value:

'((k₁ . v₁) (k₂ . v₂) (k₃ . v₃)) 

However, if the value is a long list, then it will look proper:

'((k₁ v₁ v₁ v₁ …))

Unless the end of that long list is improper (not nil terminated). If the long list is improper, the dot will show up at the end.

What you have in this case are values that are themselves conses of two numbers: '((k₁ v₁ . v₁)).

While it may be unusual, it's a valid alist and assoc and related functions will work with it.

3
  • The dot notation threw me. I only see that in cons... is this some improper list form?
    – ocodo
    Aug 24, 2022 at 3:26
  • Alists are always “improper”, yes. Each item in the list is a pair, where the first element is the key and the second is the value: '((k₁ . v₁) (k₂ . v₂) (k₃ . v₃)) However, if the value is a long list, then it will look proper: '((k₁ v₁ v₁ v₁ …)), unless the end of that long list is improper. If the long list is improper, the dot will show up at the end. Finally, what you have in this case are values that are themselves conses of two numbers: '((k₁ v₁ . v₁)) You can think of this as a very short improper list.
    – db48x
    Aug 24, 2022 at 14:18
  • Updated to include these details in the answer.
    – ocodo
    Aug 25, 2022 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.