suppress-args.scm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #| -*-Scheme-*-
  2. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  3. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Massachusetts
  5. Institute of Technology
  6. This file is part of MIT/GNU Scheme.
  7. MIT/GNU Scheme is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11. MIT/GNU Scheme is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with MIT/GNU Scheme; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
  18. USA.
  19. |#
  20. ;;; FBE: make a parameter
  21. (define *suppressed-argument-list* (make-parameter '()))
  22. (define *suppressed-argument-list-counter* (make-parameter 0))
  23. (define (suppress-arguments arguments)
  24. (let ((n (+ (length (*suppressed-argument-list*)) 1)))
  25. (*suppressed-argument-list-counter*
  26. (+ (*suppressed-argument-list-counter*) 1))
  27. (*suppressed-argument-list*
  28. (cons (cons arguments
  29. (symbol "args."
  30. (*suppressed-argument-list-counter*)))
  31. (*suppressed-argument-list*)))
  32. n))
  33. (define (show-suppressed-arguments)
  34. (pp (map (lambda (al)
  35. `(,(cdr al) = ,@(car al)))
  36. (*suppressed-argument-list*))))
  37. (define (clear-arguments)
  38. (*suppressed-argument-list* '())
  39. (*suppressed-argument-list-counter* 0)
  40. 0)
  41. (define (arg-suppressor expression)
  42. (if (pair? expression)
  43. (let ((v (assoc (cdr expression) (*suppressed-argument-list*))))
  44. (if v
  45. (list (arg-suppressor (car expression)) (cdr v))
  46. (cons (arg-suppressor (car expression))
  47. (arg-suppressor (cdr expression)))))
  48. expression))
  49. #|
  50. ;;; For example
  51. (let ((t 't) (xy (up 'x 'y)) (uv (up 'r 's)))
  52. (* (((partial 2) Hp) (up t uv (- (((partial 2) F1) t xy uv))))
  53. (((partial 2) ((partial 1) F1)) 't xy uv)))
  54. #|
  55. (down
  56. (+
  57. (*
  58. (((partial 1 0) ((partial 2 1) F1)) t (up x y) (up r s))
  59. (((partial 2 1) Hp)
  60. (up t
  61. (up r s)
  62. (down (* -1 (((partial 2 0) F1) t (up x y) (up r s)))
  63. (* -1 (((partial 2 1) F1) t (up x y) (up r s)))))))
  64. ...mess...)
  65. ...mess...)
  66. |#
  67. ;;; We choose arguments to suppress:
  68. (suppress-arguments '((up t
  69. (up r s)
  70. (down (* -1 (((partial 2 0) F1) t (up x y) (up r s)))
  71. (* -1 (((partial 2 1) F1) t (up x y) (up r s)))))))
  72. #| 1 |#
  73. (suppress-arguments '(t (up x y) (up r s)))
  74. #| 2 |#
  75. ;;; Now look at the pretty result:
  76. (let ((t 't) (xy (up 'x 'y)) (uv (up 'r 's)))
  77. (* (((partial 2) Hp) (up t uv (- (((partial 2) F1) t xy uv))))
  78. (((partial 2) ((partial 1) F1)) 't xy uv)))
  79. #|
  80. (down
  81. (+ (* (((partial 2 0) Hp) args.1) (((partial 1 0) ((partial 2 0) F1)) args.2))
  82. (* (((partial 2 1) Hp) args.1) (((partial 1 0) ((partial 2 1) F1)) args.2)))
  83. (+ (* (((partial 2 0) Hp) args.1) (((partial 1 1) ((partial 2 0) F1)) args.2))
  84. (* (((partial 2 1) Hp) args.1) (((partial 1 1) ((partial 2 1) F1)) args.2))))
  85. |#
  86. (show-suppressed-arguments)
  87. ((args.2 = t (up x y) (up r s))
  88. (args.1 = (up t
  89. (up r s)
  90. (down (* -1 (((partial 2 0) F1) t (up x y) (up r s)))
  91. (* -1 (((partial 2 1) F1) t (up x y) (up r s)))))))
  92. |#