fbe-extapply.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. ;;;; Scheme evaluator extensions for algebra.
  21. ;;; Extension of Scheme for application of non-procedures in operator position.
  22. ;;; FBE start: comment out
  23. ;; (define *enable-generic-apply* true)
  24. ;; (define inapplicable-object/operator
  25. ;; (condition-accessor condition-type:inapplicable-object 'DATUM))
  26. ;; (define (apply-extension-init)
  27. ;; (bind-default-condition-handler
  28. ;; (list condition-type:inapplicable-object)
  29. ;; (lambda (condition)
  30. ;; (if *enable-generic-apply*
  31. ;; (use-value
  32. ;; (lambda args
  33. ;; (g:apply (inapplicable-object/operator condition) args)))))))
  34. ;; (define (once-only! thunk name)
  35. ;; (if (lexical-unbound? system-global-environment name)
  36. ;; (begin (thunk)
  37. ;; ;; Create NAME in SGE
  38. ;; (eval `(define ,name #t) system-global-environment)
  39. ;; 'done)
  40. ;; 'already-done))
  41. ;; (once-only! apply-extension-init 'apply-extension-init)
  42. ;; #|
  43. ;; ;;; Example of the way it should not be done!
  44. ;; (define (apply-extension-init)
  45. ;; (bind-default-condition-handler
  46. ;; (list condition-type:inapplicable-object)
  47. ;; (lambda (condition)
  48. ;; (if *enable-generic-apply*
  49. ;; ((stack-frame->continuation
  50. ;; (stack-frame/next
  51. ;; (stack-frame/next
  52. ;; (stack-frame/next
  53. ;; (continuation->stack-frame
  54. ;; (condition/continuation condition))))))
  55. ;; (lambda args
  56. ;; (g:apply (inapplicable-object/operator condition) args)))))))
  57. ;; |#
  58. ;;
  59. ;; ;;; Extension of Scheme for self-evaluating unbound variables
  60. ;; (define (with-self-evaluating-unbound-variables thunk)
  61. ;; (bind-condition-handler
  62. ;; (list condition-type:unbound-variable)
  63. ;; (lambda (condition)
  64. ;; (let ((variable-name
  65. ;; (access-condition condition 'location)))
  66. ;; (use-value variable-name)))
  67. ;; thunk))
  68. ;;; FBE end
  69. #|
  70. (pe (with-self-evaluating-unbound-variables
  71. (lambda ()
  72. (+ a 1))))
  73. (+ 1 a)
  74. |#
  75. ;;; Extension of Scheme for allowing symbolic literals to be applied
  76. ;;; *enable-generic-apply* is tested in applicable-literal?, used in
  77. ;;; g:apply. See generic.scm.
  78. ;;; FBE start
  79. ;; (define *enable-literal-apply* #f)
  80. ;; (define (with-literal-apply-enabled thunk)
  81. ;; (fluid-let ((*enable-literal-apply* #t))
  82. ;; (thunk)))
  83. (define *enable-literal-apply* (make-parameter #f))
  84. (define (with-literal-apply-enabled thunk)
  85. (parameterize ((*enable-literal-apply* #t))
  86. (thunk)))
  87. ;;; FBE end
  88. #|
  89. (pe (+ (f 'a) 3))
  90. ;Unbound variable: f
  91. (pe (with-literal-apply-enabled
  92. (lambda ()
  93. (+ (f 'a) 3))))
  94. ;Unbound variable: f
  95. (pe (with-self-evaluating-unbound-variables
  96. (lambda ()
  97. (+ (f 'a) 3)) ))
  98. ;Application of a number not allowed f ((a))
  99. (pe (with-literal-apply-enabled
  100. (lambda ()
  101. (with-self-evaluating-unbound-variables
  102. (lambda ()
  103. (+ (f 'a) 3)) ))))
  104. (+ 3 (f a))
  105. |#
  106. ;;; (define *numbers-are-constant-functions* #f) in numbers.scm. If
  107. ;;; this is set to #t then numbers are applied as constant functions.
  108. ;;; This allows literal functions to be reconstructed.
  109. ;;; FBE: we made *literal-reconstruction* a parameter in kernel/litfun.scm
  110. ;; (define (with-literal-reconstruction-enabled thunk)
  111. ;; (fluid-let ((*literal-reconstruction* #t))
  112. ;; (thunk)))
  113. (define (with-literal-reconstruction-enabled thunk)
  114. (parameterize ((*literal-reconstruction* #t))
  115. (thunk)))
  116. ;;; Sometimes this saves the butt of a number jockey.
  117. ;;; FBE comment out
  118. ;; (define (with-underflow->zero thunk)
  119. ;; (bind-condition-handler
  120. ;; (list condition-type:floating-point-underflow)
  121. ;; (lambda (condition)
  122. ;; (use-value 0.))
  123. ;; thunk))