Oladon

Dynamic Fun

Jun 12th, 2022 (edited)
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.74 KB | None | 0 0
  1. (ql:quickload 'cl-redis)
  2.  
  3. (eval-when (:compile-toplevel :load-toplevel :execute)
  4.   (defparameter *connection-info* '(:host #(127 0 0 1))))
  5.  
  6. (defmacro with-connection-info (() &body body)
  7.   `(redis:with-persistent-connection ,*connection-info*
  8.      ,@body))
  9.  
  10. ;; This trace allows us to see which set of connection info is in use
  11. (trace usocket:socket-connect)
  12.  
  13. ;; This expands as using fakedomain:14 (correct)...
  14. (let ((*connection-info* '(:host "fakedomain" :port 14)))
  15.   (macroexpand-1 '(with-connection-info () (redis:red-get "foo"))))
  16.  
  17. ;; ... but this runs using the top-level definition (incorrect)!
  18. (let ((*connection-info* '(:host "fakedomain" :port 14)))
  19.   (with-connection-info () (redis:red-get "foo")))
  20.  
  21. ;; What am I missing?!
  22.  
Add Comment
Please, Sign In to add comment