[plt-scheme] Re: macros and eval

From: Jose Ramirez (jomirez at gmail.com)
Date: Mon Mar 17 04:36:05 EDT 2008

On Sat, Mar 15, 2008 at 8:41 PM, Grant Rettke <grettke at acm.org> wrote:
> I've never used eval for anything, so I haven't got sense of when you
>  would use it.
>  Why do you need to use eval here?

I'm not saying that I _need_ to use it. It was first option that
crossed my mind.

Basically i want to create a simple language encompassing backups
(starting & stopping of services, copying files, automatic logging) at
first, than add other functions suitable for my workplace (support for
our automated installation, some w2k domain specific tasks etc.).

Basically i do it to get rid of those annoying batch files (and even
those less annoying bash scripts ;-), reducing the verbosity and
complexity of said scripts, having fun and learning in the process

Since it should run anywhere without drscheme installed, i thought the
best way would be to create an executable that would contain all the
necessary functionality, serving as runtime for said scripts (and
hence the need for eval - or friends).

So far, my main file looks like :

#lang scheme
(define (read-eval filename)
  (call-with-input-file filename
    (lambda (p)
      (let loop ((exp (read p)))
        (if (eof-object? exp)
              (eval exp)
              (loop (read p))))))))

(define script-file
  (if (> (vector-length (current-command-line-arguments)) 0)
      (vector-ref (current-command-line-arguments) 0)

(define nspace (make-base-namespace))

(parameterize ((current-namespace nspace))
             (namespace-require '(file "bck-dsl-top.ss"))
             (read-eval script-file))


it does exactly what it should (well, drscheme4 refuses to create
executable, so i cannot be certain, but i have the hunch that
something more will be needed so it wouldn't try to access the
bck-dsl-top.ss file in runtime, probably requiring it in the main file
and then sticking it to the newly created namespace).

thanks for the tips, everybody, and if i'm doing something in a
horribly wrong way, let me know ;-)

Posted on the users mailing list.