Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  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"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement