SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defgeneric glue (object &rest with-other-objects))
  2.  
  3. (defgeneric binary-glue (left right))
  4.  
  5. (defmethod glue ((object t) &rest with-other-objects)
  6.   (if with-other-objects
  7.       (binary-glue object (apply (function glue) with-other-objects))
  8.       object))
  9.  
  10. (defmethod binary-glue ((left integer) (right integer))
  11.   (+ (* left (expt 10 (ceiling (log right 10))))
  12.      right))
  13.  
  14. (defmethod binary-glue ((left string) (right string))
  15.   (concatenate 'string left right))
  16.  
  17. (defmethod binary-glue ((left symbol) (right symbol))
  18.   (intern (binary-glue (string left) (string right))))
  19.  
  20. (defmethod binary-glue ((left symbol) (right string))
  21.   (intern (binary-glue (string left) right)))
  22.  
  23. (defmethod binary-glue ((left string) (right symbol))
  24.   (binary-glue left (string right)))
  25.  
  26. (defmethod binary-glue ((left integer) (right symbol))
  27.   (intern (binary-glue (prin1-to-string left) (string right))))
  28.  
  29. (defmethod binary-glue ((left integer) (right string))
  30.    (binary-glue (prin1-to-string left) right))
  31.  
  32. (glue 1 'deux "trois")
  33. --> |1DEUXtrois|
  34.  
  35. (glue 1 "deux" 'trois)
  36. --> "1deuxTROIS"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top