home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / dylan / 114 < prev    next >
Encoding:
Text File  |  1993-01-21  |  5.2 KB  |  139 lines

  1. Newsgroups: comp.lang.dylan
  2. Path: sparky!uunet!world!jsidlo
  3. From: jsidlo@world.std.com (John R Sidlo)
  4. Subject: Improvements to Thomas Read-Eval-Print
  5. Message-ID: <C188s6.BtL@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. Date: Thu, 21 Jan 1993 23:19:17 GMT
  8. Lines: 129
  9.  
  10. The learning of a new language is definitely enhanced by the exercise of
  11. using it, so I'd like to start out by thanking those at Digital's
  12. Cambridge Research Labs, like jmiller@crl.enet.dec.com and
  13. birkholz@martigny.ai.mit.edu, and to Marc Feeley
  14. (gambit@trex.iro.umontreal.ca) in providing their Thomas/Dylan interpreter.
  15.  
  16. I've noticed or heard of several shortcomings in the Interpreter, in
  17. <deque> and with the Dylan Read-Eval-Print loop.  I believe I found the
  18. <deque> initialization problem, code included below.  I also made some
  19. changes to the copy of Thomas-rep I have, making the Thomas interpreter
  20. more pleasant to use.  I found myself aggravated by the internal
  21. structure dumps that Thomas prints: they are certainly not succinct, and
  22. therefore not particularly informative.  I modified several error
  23. handlers and the main r-e-p to detect these situations, and print the
  24. short text description of the object, rather than a structure dump.  The
  25. code for these changes also appears below.  I'll note that I may not
  26. have the latest copy of the source used in the Gambit Thomas: in fact
  27. I'm sure there are small differences.  
  28.  
  29. I've tested these changes out on the Thomas Interpreter based on Marc
  30. Feeley's gambit.  These changes may also work for other implementations
  31. of Thomas, but I haven't tried them out.
  32.  
  33. I've distributed the <deque> fix on comp.lang.dylan, but this is the
  34. first time for the Thomas read-eval-print changes.
  35.  
  36. These changes have also been sent to Feeley and Digital.
  37.  
  38. John Sidlo (jsidlo@world.std.com)
  39.  
  40. ****
  41. <deque> fix
  42. ***
  43.  
  44. (add-method
  45.  dylan:make
  46.  (dylan::dylan-callable->method
  47.   (make-param-list `((DEQUE ,(dylan::make-singleton <deque>)))
  48.                    #F #F '(size: fill:))
  49.   (lambda (multiple-values next-method class . rest)
  50.     multiple-values class               ; Not used
  51.     (dylan::keyword-validate next-method rest '(size: fill:))
  52.     (let* ((size (dylan::find-keyword rest 'size: (lambda () 0)))
  53.            (fill (dylan::find-keyword rest 'fill: (lambda () #F))))
  54.       (if (or (not (integer? size)) (negative? size))
  55.           (dylan-call dylan:error
  56.                       "make -- deque size invalid" size))
  57.       (let ((instance (dylan::make-<object> <deque>)))
  58. ;        (dylan-call dylan:set-deque-front! instance '())
  59. ;        (dylan-call dylan:set-deque-last! instance '())
  60.         (dylan-call dylan:set-deque-front! instance #F)
  61.         (dylan-call dylan:set-deque-last! instance #F)
  62.         (do ((n 0 (+ n 1)))
  63.             ((= n size) instance)
  64.           (dylan-call dylan:push instance fill)))))))
  65. ;I changed the commented lines
  66.  
  67. ***
  68. Thomas-rep/error handler changes
  69. ***
  70.  
  71. (define (thomas-rep)
  72. ;  (newline)
  73. ;  (display "Entering Thomas read-eval-print-loop.")
  74. ;  (newline)
  75. ;  (display "Exit by typing \"thomas:done\"")
  76. ;  (newline)
  77.   (dylan::catch-all-conditions
  78.    (lambda ()
  79.      (let loop ()
  80.        (newline)
  81.        (display "? ")
  82.        (let ((input (read)))
  83.          (newline)
  84.          (if (and (eq? input 'thomas:done))
  85.              'thomas:done
  86.              (compile-expression
  87.               input '!MULTIPLE-VALUES thomas-rep-module-variables
  88.               (lambda (new-vars preamble compiled-output)
  89.                 (implementation-specific:eval
  90.                  `(BEGIN
  91.                     ,@preamble
  92.                     (LET* ((!MULTIPLE-VALUES (VECTOR '()))
  93.                            (!RESULT ,compiled-output))
  94.                       (IF (EQ? !RESULT !MULTIPLE-VALUES)
  95.                           (LET RESULT-LOOP
  96.                               ((COUNT 1)
  97.                                (RESULTS (VECTOR-REF !MULTIPLE-VALUES 0)))
  98.                             (IF (PAIR? RESULTS)
  99.                                 (LET ((RESULT (CAR RESULTS)))
  100.                                   (NEWLINE)
  101.                                   (DISPLAY ";Value[")(DISPLAY COUNT)
  102.                                   (DISPLAY "]: ")
  103. ;(WRITE RESULT)
  104.   (if (record? RESULT)
  105.     (WRITE (record-type-name (record-type-descriptor RESULT)))
  106.     (WRITE RESULT))
  107.  
  108.                                   (RESULT-LOOP (+ 1 COUNT) (CDR RESULTS)))
  109.                                 (NEWLINE)))
  110.                           (BEGIN
  111. ;                            (NEWLINE)(DISPLAY ";Value: ")(WRITE !RESULT)
  112.                             (NEWLINE)(DISPLAY ";Value: ")
  113.   (if (record? !result)
  114.     (WRITE (record-type-name (record-type-descriptor !result)))
  115.     (WRITE !RESULT))
  116.                              (NEWLINE))))))
  117.                 (set! thomas-rep-module-variables
  118.                       (append new-vars thomas-rep-module-variables))
  119.                 (loop)))))))))
  120.  
  121.  
  122.  
  123. (define (display-simple-error format-string format-args)
  124.   (display format-string)
  125.   (do ((args format-args (cdr args)))
  126.       ((null? args) #t)
  127.     (display " ")
  128. ;(write (car args))
  129.  (if (record? (car args))
  130.    (WRITE (record-type-name (record-type-descriptor (car args))))
  131.    (WRITE (car args)))
  132. ))
  133.  
  134. (define (implementation-specific:induce-error format-string format-args)
  135. ;  (apply error format-string format-args)
  136.   (error format-string))
  137.  
  138.  
  139.