[plt-scheme] Re: macros and eval

From: jomirez (jomirez at gmail.com)
Date: Fri Mar 14 10:44:56 EDT 2008

no, i'm not trying to create my own extension language (unless i
should be doing exactly that ;-)
for now i wanna create a simple DSL that would ease the pain of
administrator writing general backup/maintanance scripts.
it works when i concatenate the two samples in one file, it doesnt
work when i try to eval/load the (job ......) definition (and probably
wouldn't for any other macro).
lets say i have a following source code (minimal example, no error
checking, etc):

#lang scheme
(require scheme/system)
(require scheme/file)

(define (start-service service)
  (system (format "net start ~a" service)))

(define (stop-service service)
  (system (format "net stop ~a" service)))

(define (mkdir name)
  (make-directory name))

(define (copy name name2)
  (copy-directory/files name name2))

(define-syntax without-service
  (syntax-rules ()
    ((_ name (body ...))
     (dynamic-wind
      (lambda ()
        (stop-service name))
      (lambda ()
        body ...)
      (lambda ()
        (start-service name))))))

(define-syntax job
  (syntax-rules ()
    ((_ name (items ...))
     (begin
       (display (format "backup-job: ~a~n" name))
       items ...
       (display (format "ending-job: ~a~n" name))))))

;; and now something like
(load (vector-ref (current-command-line-arguments) 0))
;; but something that would work ;-)))

---CUT---

which i want to compile into a self-contained binary, that should
serve as interpreter/runtime for a simple scripts like this one (and
more compilcated once it will run, since in principle it should be the
same) :

(job "vmware-backup"
     ((without-service "name"
           ((copy "source" "target")))))

---CUT---

preferrably without any #lang header or any other "not strictly
necessary" text (although if there is no way around this, i know i can
simulate it in memory, or write it into another - temporary - file) ,
so it won't confuse some of our half braindead admins ;-).

thx for your help, jr.


On Mar 14, 2:40 pm, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> Are you saying you want to write an interpreter for your VMLanguage
> or do you want to have a set of macros that compile VMLanguge into
> executables? These are two radically different tasks (though I assume
> you know it).
>
> I am conjecturing that the answer is:
>
>   PLT Scheme (mzscheme) is your interpreter
>   and VMLanguage is just an extension of Scheme.
>
> So I'd recommend that you create a language in v4 (3.99.....) and
> then people can write
>
>   #lang vmware-backup
>   ... everything here is in your language ...
>
> and then people just run mzscheme on this file (or your prefix
> the file with shell incantations.) Since mzscheme has a jit
> compiler, that should do fine.
>
> -- Matthias
>
> On Mar 14, 2008, at 6:15 AM, jomirez wrote:
>
>
>
> > Hi, i'm trying to create my own mini-language for backup purposes.
>
> > I defined a couple of functions for starting & stopping services,
> > vmware-server instances, mountning and unmounting of windows shares
> > etc.
>
> > For even sleeker syntax, i created  a couple of macros so i can write
> > my backup-jobs like
>
> > (job "vmware-backup"
> >      (with-stopped-vmware-image "c:\\images\\test\\test.vmx"
> >       (with-share "x:" "\\\\backserver\\vmware"
> >                   (copy "c:\\images\\test" "x:\\"))))
>
> > .......
>
> > When i stick the code into the body of the "main" source file, all
> > works fine  But i want to compile it into executable (for
> > deployability) and use that as an interpreter for the job files. I
> > tried evaling/loading the file with job definitions from within the
> > main code, and the macros won't get expanded (complaining "reference
> > to undefined identifier: job")
>
> > Do i have to execute the transformation process manualy, or is there
> > even better solution ?
>
> > thanks in advance,
>
> > j.
> > _________________________________________________
> >   For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.