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

  1. Path: sparky!uunet!olivea!sgigate!odin!fido!mycool.asd.sgi.com!mtoy
  2. From: mtoy@mycool.asd.sgi.com (Michael Toy)
  3. Newsgroups: comp.lang.scheme
  4. Subject: How do I implement trace/untrace
  5. Message-ID: <1idc0eINNak2@fido.asd.sgi.com>
  6. Date: 6 Jan 93 01:18:06 GMT
  7. Organization: Silicon Graphics, Inc., Mountain View, CA
  8. Lines: 35
  9. NNTP-Posting-Host: mycool.asd.sgi.com
  10.  
  11. I am new to scheme and I am trying various small projects
  12. to explore what can and can not be done.  One idea was to
  13. add a factility for strict type checking, which would allow
  14. you to declare what the legal types for a function were,
  15. and the type check would be "inserted" into the procedure,
  16. similar to the way "trace" and "untrace" work in some schemes.
  17.  
  18. I failed to get very far in figuring out how to do this.
  19.  
  20. Is pseudo-code I want something like:
  21.  
  22. ;; "type-check" insert a type check into references to a function
  23. (define (type-check function list-of-check-funcs)
  24.  (set! (bindingof function)
  25.  (lambda args
  26.   (type-checker (current-binding function) list-of-check-funcs args))))
  27. (define (type-checker func checkers args)
  28.   (letrec
  29.    ((good
  30.      (lambda (chk-list arg-list)
  31.       (cond
  32.        ((null? chk-list) (null? arg-list))
  33.        ((null? arg-list) (error "Too many arguments"))
  34.        (((car chk-list) (car arg-list)) (good (cdr chk-list) (cdr arg-list)))
  35.        (else #f)))))
  36.    (if (good checkers args) (apply func args) (error "Type Error"))))
  37.  
  38. Obviously this type checking is not sophisticated, but the point for me now
  39. is not what sort of type checking, but how I implement "type-check".  With
  40. some doodling i discovered that if I pass the quoted name of the function to
  41. "type-check" I can use unquote to get the current binding, but since set!
  42. is a special form, it doesn't like an expression for its first argument.
  43.  
  44. What do I need to learn to make this possible?  My scheme has a "trace"
  45. debugging aid which does something like this.  Can this be done in Scheme?
  46.