[plt-scheme] Re: adventure game code ported to PLT 4 ?

From: Fred G. Martin (fredm at cs.uml.edu)
Date: Sun Oct 19 22:24:28 EDT 2008

Well, this was actually pretty easy, with one exception... the "show" procedure.

It seems to use MIT Scheme-specific features (environment->package,
fluid-let, environment-bindings)... Is this portable to PLT?

Thanks all,

(define (show thing)
  (define (global-environment? frame)
    (environment->package frame))
  (define (pp-binding name value width)
    (let ((value* (with-string-output-port
                   (lambda (port)
                     (if (pair? value)
                         (pretty-print value port #F (+ width 2))
                         (display value port))))))
      (display name)
      (display ": ")
      (display (make-string (- width (string-length name)) #\Space))
      (if (pair? value)
          (display (substring value* (+ width 2) (string-length value*)))
          (display value*))))
  (define (show-frame frame)
    (if (global-environment? frame)
        (display "\nGlobal Environment")
        (let* ((bindings (environment-bindings frame))
               (parent   (environment-parent frame))
               (names    (cons "Parent frame"
                               (map symbol->string (map car bindings))))
               (values   (cons (if (global-environment? parent)
                               (map cadr bindings)))
               (width    (reduce max 0 (map string-length names))))
          (for-each (lambda (n v) (pp-binding n v width))
            names values))))
  (define (show-procedure proc)
    (fluid-let ((*unparser-list-depth-limit* 4)
                (*unparser-list-breadth-limit* 4))
      (display "Frame:")
      (display "  ")
      (if (global-environment? (procedure-environment proc))
          (display "Global Environment")
          (display (procedure-environment proc)))
      (display "Body:")
      (pretty-print (procedure-lambda proc) (current-output-port) #T 2)))

  (define (print-nicely thing)
    (display thing)
    (cond ((false? thing)
          ((environment? thing)
           (show-frame thing))
          ((compound-procedure? thing)
           (show-procedure thing))
          (else 'uninteresting)))

   (or (if (exact-integer? thing)
           (object-unhash thing)

On Sun, Oct 19, 2008 at 9:10 PM, Fred G. Martin <fredm at cs.uml.edu> wrote:
> Hi all,
> Has anyone ported the MIT adventure game code to PLT version 4?
> thanks,
> Fred

Posted on the users mailing list.