home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!mintaka.lcs.mit.edu!ai-lab!zurich.ai.mit.edu!markf
- From: markf@zurich.ai.mit.edu (Mark Friedman)
- Newsgroups: comp.lang.scheme
- Subject: Re: How do I implement trace/untrace
- Date: 6 Jan 93 09:26:30
- Organization: M.I.T. Artificial Intelligence Lab.
- Lines: 33
- Message-ID: <MARKF.93Jan6092630@montreux.ai.mit.edu>
- References: <1idc0eINNak2@fido.asd.sgi.com>
- Reply-To: markf@zurich.ai.mit.edu
- NNTP-Posting-Host: montreux.ai.mit.edu
- In-reply-to: mtoy@mycool.asd.sgi.com's message of 6 Jan 93 01:18:06 GMT
-
- You can't change the function per se in standard Scheme but if some
- variable is bound to that function you can reassign that variable to a
- new function which type checks the arguments and then calls the
- original function. For example:
-
- (define (type-check function list-of-check-funcs)
- (lambda args
- (type-checker function list-of-check-funcs args)))
-
- (define (foo bar) (numerical-func bar))
-
- (set! foo (type-check foo (list number-checker)))
-
- You can macro-ize the above with something like:
-
- (define-syntax type-check!
- (syntax-rules ()
- ((type-check! function-name check-func ...)
- (set! function-name
- (type-check function-name (list check-func ...))))))
-
- which would allow you to simply say:
-
- (type-check! foo number-checker)
-
- -Mark
- --
-
- Mark Friedman
- 42 Wyatt St.
- Somerville, Ma. 02143
-
- markf@zurich.ai.mit.edu
-