[plt-scheme] structures and named let (two questions, more or less)

From: Greg Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Fri Feb 24 16:34:39 EST 2006

Okay, question of the day: The read/eval/print loop I had been using
looks like this:

(require (lib "string.ss"))

(define (run)
  (let loop ((env (new-environment)))
    (begin
      (printf ">> ")
      (let ((input-exp (read-line)))
        (unless (equal? input-exp "(exit)")
          (let ((exp (read-from-string input-exp
                                       (lambda (m) (printf "Syntax
error: ~a~n" m))
                                       (lambda () (void)))))
            (printf "~a~n" (evaluate-exp exp env))
            (loop env)))))))


Now, when I started writin the code, I expected that env would be
updated on each iteration. In fact, it's a list of hash tables, but is
only modified by set! and define (which, ironically, I did not
implement until yesterday). Within evaluate-exp I do extend the
environment (by consing an empty hash table onto the list and passing
THAT value to functions called by evaluate-exp. 

All of this works fine, but it raises a couple of questions in my mind:

1. Is binding a hash-table via let like this expensive? The structure
could be quite large. What about consing a list containing the
hash-table and passing that to another function? (Okay, I guess that's
already two questions.)

2. What if I require struct.ss and use copy-struct to create a new
environment? That seems attractive because it doesn't involve any
mutation, but absent any compiler optimizations, it could involve a lot
of copying. I guess what I'm really asking is this: If a structure is
immutable and I update a copy, am I really copying the underlying data?

(Okay. I'll throw in a third question because it's something that's
been bugging me: How come all the libraries end in .ss? Is that a
convention for modules?)


===
Gregory Woodhouse  <gregory.woodhouse at sbcglobal.net>
"All truth passes through three stages: First, it is ridiculed.
Second, it is violently opposed. Third, it is accepted as
being self-evident."
--Arthur Schopenhauer


Posted on the users mailing list.