Skip to content
New issue

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

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

Already on GitHub? # to your account

Use lambda instead of evaling s-expressions #18

Open
Stebalien opened this issue Jan 18, 2024 · 2 comments
Open

Use lambda instead of evaling s-expressions #18

Stebalien opened this issue Jan 18, 2024 · 2 comments

Comments

@Stebalien
Copy link
Contributor

Several types define expressions to be evaluated at runtime. E.g.:

  1. Switch statements where we have to eval the expression then find the matching case.
  2. List sizes.
  3. Struct sizes.

Instead, we should just use lambda expression so the byte-compiler can optimize them. We can likely provide some nice macros if lambdas become unwieldy. E.g., a switch could be written as:

(defclast ...
  (xcb:-struct)
  ((thing :initform
          (xcb:-switch (xcb:-fieldref 'class-id)
	        ((0) pitch duration led-mask led-values global-auto-repeat click percent pad~0 auto-repeats~)
	        ((1)
	         pad~1 accel-num accel-denom threshold)
	        ((2)
	         max-symbols num-keysyms keysyms~)
	        ((3)
	         resolution min-value max-value)
	        ((4)
	         led-mask* led-values*)
	        ((5)
	         percent* pad~2 pitch* duration*))))

Where xcb:-switch would compile the switch down to a lambda returning the correct case to use given some obj.

@medranocalvo
Copy link
Contributor

I wrote the comment below first, but realized now that it makes the assumption that the lambdas would be evaluated at :initform time. Would these lambdas be evaluated in xcb:marshall, kind of substituting the eval and case processing?


I think this would imply that the value is determined at construction time instead of at marshalling time. This would prevent building a message piece by piece. Say:

(let (obj (make-instance 'xcb:ConfigureWindow
                         :window xwin
                         :x x :y y :width width :height height))
  (setf (slot-value obj :value-mask)
        (logior (if x xcb:ConfigWindow:X 0)
                (if y xcb:ConfigWindow:Y 0)
                (if width xcb:ConfigWindow:Width 0)
                (if height xcb:ConfigWindow:Height 0))))

We don't do that in EXWM as far as I can see, but I think that it should be supported.

@Stebalien
Copy link
Contributor Author

Would these lambdas be evaluated in xcb:marshall, kind of substituting the eval and case processing?

Yes. The goal is to have them parsed and byte-compiled along with the rest of the file. Basically, instead of storing the code as raw s-expressions, we'd store it as compiled lambdas.

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

No branches or pull requests

2 participants