home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / scheme / 2875 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  1.4 KB

  1. Path: sparky!uunet!think.com!mintaka.lcs.mit.edu!ai-lab!zurich.ai.mit.edu!markf
  2. From: markf@zurich.ai.mit.edu (Mark Friedman)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Re: How do I implement trace/untrace
  5. Date: 6 Jan 93 09:26:30
  6. Organization: M.I.T. Artificial Intelligence Lab.
  7. Lines: 33
  8. Message-ID: <MARKF.93Jan6092630@montreux.ai.mit.edu>
  9. References: <1idc0eINNak2@fido.asd.sgi.com>
  10. Reply-To: markf@zurich.ai.mit.edu
  11. NNTP-Posting-Host: montreux.ai.mit.edu
  12. In-reply-to: mtoy@mycool.asd.sgi.com's message of 6 Jan 93 01:18:06 GMT
  13.  
  14. You can't change the function per se in standard Scheme but if some
  15. variable is bound to that function you can reassign that variable to a
  16. new function which type checks the arguments and then calls the
  17. original function. For example:
  18.  
  19.   (define (type-check function list-of-check-funcs)
  20.     (lambda args
  21.        (type-checker function list-of-check-funcs args)))
  22.  
  23.   (define (foo bar) (numerical-func bar))
  24.  
  25.   (set! foo (type-check foo (list number-checker)))
  26.  
  27. You can macro-ize the above with something like:
  28.  
  29.   (define-syntax type-check!
  30.     (syntax-rules ()
  31.       ((type-check! function-name check-func ...)
  32.        (set! function-name 
  33.              (type-check function-name (list check-func ...))))))
  34.  
  35. which would allow you to simply say:
  36.  
  37.   (type-check! foo number-checker)
  38.  
  39. -Mark
  40. --
  41.  
  42. Mark Friedman
  43. 42 Wyatt St.
  44. Somerville, Ma. 02143
  45.  
  46. markf@zurich.ai.mit.edu
  47.