[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [plt-scheme] eval question



> >what, exactly, should be documented?

> What's not documented is the settings that are stored in the file 
> that you're loading. I can see this causing a bunch of problems 
> down the line. Let me use the first person, to make this less 
> acerbic. 

Uninformative, destructive, non-reflective ... that would have been
more to the point than acerbic. But let's see about this one ...

> I've written code like this before, and I always end up forgetting 
> what settings were in the file, and having to go back and check it. 
> If I have more than one such file, I'm really in the soup.

The settings-file is manipulated by the program, exclusively. The user
doesn't worry about it. What's more, there are only two settings: a
string and a list of strings, hardly difficult to remember.

> In essence, I think a solution using modules (or units, if you 
> prefer them) is more robust and inherently better-documented.

... but less standard. Nevertheless, I'm already reading up on units
and on match-lambda which both seemed very interesting and powerful
solutions to this particular problem ... so I might change my point of
view (and my code, maybe) during the next hours.

> You'll have to pardon my knee-jerk reaction; 

Forgiven. Forgotten.

> I've just spent a few weeks grading assignments for our software 
> design class, and I've seen a lot of extremely non-portable, non-
> modular, non-documented, poorly designed code.

Do you believe in self-fulfilling prophecy?

---------------------------------------------------------------------

Toy example about my use of eval/load.

I can't rip the relevant parts out of the program because they don't
perform out of context - that's why I didn't do that in my initial
message. If you want to see the original code, look at www.biont.org 
file: installer.ss - I'll add a tarball later that night).


;; One of the two installation-parameters
;; the options-file remembers for future use.
(define include-directory
  (let ((data #f))
    (lambda x
      (case (length x)
        ((0) data)
        ((1) (set! data (car x)))
        (else (error 'wrong-arity))))))

;; Save installation-parameters to file.
(define saveopts
  (lambda ()
    (with-output-to-file "c:/x/options.ss"
      (lambda ()
        (write (list 'include-directory (include-directory))))
      'replace)))

;; Read installation-parameters from file.
(define loadopts
  (lambda () (load "c:/x/options.ss")))

;; Saving the settings.
(include-directory) ;; => #f
(include-directory "c:/x/include")
(include-directory) ;; => "c:/x/include"
(saveopts)

;; Deleting the settings.
(include-directory #f)
(include-directory) ;; => #f

;; Resurrecting the settings.
(loadopts)
(include-directory) ;; => "c:/x/include"