home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!sgigate!odin!fido!mycool.asd.sgi.com!mtoy
- From: mtoy@mycool.asd.sgi.com (Michael Toy)
- Newsgroups: comp.lang.scheme
- Subject: How do I implement trace/untrace
- Message-ID: <1idc0eINNak2@fido.asd.sgi.com>
- Date: 6 Jan 93 01:18:06 GMT
- Organization: Silicon Graphics, Inc., Mountain View, CA
- Lines: 35
- NNTP-Posting-Host: mycool.asd.sgi.com
-
- I am new to scheme and I am trying various small projects
- to explore what can and can not be done. One idea was to
- add a factility for strict type checking, which would allow
- you to declare what the legal types for a function were,
- and the type check would be "inserted" into the procedure,
- similar to the way "trace" and "untrace" work in some schemes.
-
- I failed to get very far in figuring out how to do this.
-
- Is pseudo-code I want something like:
-
- ;; "type-check" insert a type check into references to a function
- (define (type-check function list-of-check-funcs)
- (set! (bindingof function)
- (lambda args
- (type-checker (current-binding function) list-of-check-funcs args))))
- (define (type-checker func checkers args)
- (letrec
- ((good
- (lambda (chk-list arg-list)
- (cond
- ((null? chk-list) (null? arg-list))
- ((null? arg-list) (error "Too many arguments"))
- (((car chk-list) (car arg-list)) (good (cdr chk-list) (cdr arg-list)))
- (else #f)))))
- (if (good checkers args) (apply func args) (error "Type Error"))))
-
- Obviously this type checking is not sophisticated, but the point for me now
- is not what sort of type checking, but how I implement "type-check". With
- some doodling i discovered that if I pass the quoted name of the function to
- "type-check" I can use unquote to get the current binding, but since set!
- is a special form, it doesn't like an expression for its first argument.
-
- What do I need to learn to make this possible? My scheme has a "trace"
- debugging aid which does something like this. Can this be done in Scheme?
-