manipulation.org_archive 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # -*- mode: org -*-
  2. Archived entries from file /home/swflint/Projects/lisp-cas/manipulation.org
  3. * WORKING Rewrite Rules [0/5]
  4. :PROPERTIES:
  5. :CREATED: <2016-04-30 Sat 22:58>
  6. :ARCHIVE_TIME: 2016-05-04 Wed 19:03
  7. :ARCHIVE_FILE: ~/Projects/lisp-cas/manipulation.org
  8. :ARCHIVE_CATEGORY: manipulation
  9. :ARCHIVE_TODO: WORKING
  10. :END:
  11. Foo
  12. ** TODO Match Expressions
  13. :PROPERTIES:
  14. :CREATED: <2016-05-01 Sun 16:26>
  15. :END:
  16. Foo
  17. #+Caption: Match Expressions
  18. #+Name: match-expressions
  19. #+BEGIN_SRC lisp
  20. (defun generate-match-expression (on arity &optional (type '=))
  21. (check-type on symbol)
  22. (check-type type (member = > >=))
  23. (check-type arity (integer 0))
  24. (case type
  25. (=
  26. `(and (eq function ',on)
  27. (= arg-count ,arity)))
  28. (>
  29. `(and (eq function ',on)
  30. (> arg-count ,arity)))
  31. (>=
  32. `(and (eq function ',on)
  33. (>= arg-count ,arity)))))
  34. #+END_SRC
  35. ** TODO Define Rule
  36. :PROPERTIES:
  37. :CREATED: <2016-04-30 Sat 23:07>
  38. :END:
  39. Foo
  40. #+Caption: Define Rule
  41. #+Name: define-rule
  42. #+BEGIN_SRC lisp
  43. (defmacro defrule (name (on arity &optional (type '=)) (&rest arguments) &body expansion)
  44. (let ((match-expression (generate-match-expression on arity type))
  45. (test-name (symbolicate name '-test))
  46. (expansion-name (symbolicate name '-expansion)))
  47. `(progn
  48. (defun ,test-name (function &rest arguments &aux (arg-count (length arguments)))
  49. ,match-expression)
  50. (defun ,expansion-name (,@arguments)
  51. ,@expansion)
  52. (setf (aget *rules* ',name)
  53. (make-rule :name ',name
  54. :test-function #',test-name
  55. :expansion-function #',expansion-name))
  56. ',name)))
  57. #+END_SRC
  58. ** TODO Rule Storage
  59. :PROPERTIES:
  60. :CREATED: <2016-04-30 Sat 23:07>
  61. :END:
  62. Foo
  63. #+Caption: Rule Storage
  64. #+Name: rule-storage
  65. #+BEGIN_SRC lisp
  66. (defstruct (rule (:type list))
  67. name test-function expansion-function)
  68. (defvar *rules* '())
  69. #+END_SRC
  70. ** TODO Rule Retrieval
  71. :PROPERTIES:
  72. :CREATED: <2016-04-30 Sat 23:07>
  73. :END:
  74. Foo
  75. ** TODO Rule Application
  76. :PROPERTIES:
  77. :CREATED: <2016-04-30 Sat 23:08>
  78. :END:
  79. Foo