fn.scm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (module (arguile base fn)
  2. #:export (comp id? defd? wrap))
  3. (export-syntax fn fn-case def defp let ret w/ \\ ->> inline)
  4. (use (arguile guile)
  5. (arguile base mac)
  6. (ice-9 receive))
  7. (mac fn
  8. ((_ args body ...) #'(lambda args body ...)))
  9. (mac fn-case
  10. ((_ fn1 fn2 ...) #'(case-lambda fn1 fn2 ...)))
  11. (mac def x
  12. ((_ name (arg ... . rest) e1 e2 ...)
  13. #`(#,@(if (has-kwargs? #'(arg ...))
  14. #`(define* (name #,@(expand-kwargs #'(arg ...) x) . rest))
  15. #'(define (name arg ... . rest)))
  16. e1 e2 ...))
  17. ((_ name val) #'(define name val)))
  18. (mac defp
  19. ((_ name . rest) #'(begin (def name . rest) (export name))))
  20. (mac let
  21. ((_ var val e1 e2 ...) #'(w/ (var val) e1 e2 ...)))
  22. (mac ret ((ret var e1 e2 ...) #'(let var e1 e2 ... var)))
  23. (mac w/
  24. ((_ () e1 e2 ...)
  25. #'(_let () e1 e2 ...))
  26. ((_ (var val) e1 e2 ...)
  27. (if (id? #'var)
  28. #'(_let ((var val)) e1 e2 ...)
  29. #'(receive var val e1 e2 ...)))
  30. ((_ (var val rest ...) e1 e2 ...)
  31. (if (id? #'var)
  32. #'(_let ((var val)) (w/ (rest ...) e1 e2 ...))
  33. #'(receive var val (w/ (rest ...) e1 e2 ...)))))
  34. (mac \\ ((\\ fn args ...) #'(cut fn args ...)))
  35. ;;; Replace w/ => when loop export is handled
  36. (mac ->>
  37. ((_ fn ... exp) #'((compose fn ...) exp)))
  38. (mac inline
  39. ((_ name (arg ...) body ...)
  40. #'(define-inlinable (name arg ...) body ...)))
  41. (eval-when (expand load eval)
  42. (def comp compose)
  43. (def id? identifier?)
  44. (def defd? defined?)
  45. (def wrap const))