Guest User

contents of randomsnippets.lisp

a guest
Jun 19th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1.  
  2. (defun make-gensym-list (length &optional (x "G"))
  3. "Returns a list of LENGTH gensyms, each generated as if with a call to MAKE-GENSYM,
  4. using the second (optional, defaulting to \"G\") argument."
  5. (let ((g (if (typep x '(integer 0)) x (string x))))
  6. (loop repeat length
  7. collect (gensym g))))
  8.  
  9. (define-compiler-macro rcurry (function &rest arguments)
  10. (let ((rcurries (make-gensym-list (length arguments) "RCURRY"))
  11. (fun (gensym "FUN")))
  12. `(let ((,fun (ensure-function ,function))
  13. ,@(mapcar #'list rcurries arguments))
  14. (declare (optimize (speed 3) (safety 1)))
  15. (function(lambda (&rest more)
  16. (declare (dynamic-extent more))
  17. (multiple-value-call ,fun (values-list more) ,@rcurries))))
  18. ))
  19.  
  20. (defun ensure-function (function-designator)
  21. "Returns the function designated by FUNCTION-DESIGNATOR:
  22. if FUNCTION-DESIGNATOR is a function, it is returned, otherwise
  23. it must be a function name and its FDEFINITION is returned."
  24. (if (functionp function-designator)
  25. function-designator
  26. (fdefinition function-designator)))
  27.  
  28. (defmacro partial (fn &rest args)
  29. `(function (lambda (&rest more-args)
  30. (apply ,fn ,@args more-args))))
  31.  
  32.  
  33.  
  34. (defmacro o (&rest fn)
  35. (flet ((wrap (x) (if (symbolp x) `#',x x)))
  36. (let ((args (gensym "ARGS")))
  37. `(lambda (&rest ,args)
  38. ,(reduce (lambda (acc x)
  39. (list 'funcall (wrap x) acc))
  40. (butlast fn)
  41. :initial-value `(apply ,(wrap (car (last fn))) ,args))))))
Advertisement
Add Comment
Please, Sign In to add comment