scsh-users
[Top] [All Lists]

scsh script --- comments and queries

To: scsh-news@zurich.ai.mit.edu
Subject: scsh script --- comments and queries
From: Andrew Tarr <arc@stuff.gen.nz>
Date: Sun, 12 May 2002 01:30:28 GMT
I've just written a scsh script to transfer files from my local
public_html directory into a directory ready for upload to the
webserver. The document root is different in each case, so `/~ajt/'
has to be changed to '/' in some of the files. 

You can find this script at http://arc.stuff.gen.nz/arcfilter.scsh I
would appreciate any comments or feedback that anyone can give. None
of my coder friends understand scheme. Or particularly want to :[

Some queries: 

I figured out how to do conditional variable binding in a schemey way: 


  (let ((filtering-rx ((lambda ()
                         (if (string=? ".css" (file-name-extension fromfile))
                             (rx (: (submatch "\"" (* any))
                                    ,source-root
                                    (submatch (* any) "\"" )))
                             (rx (:
                                  (submatch (:"<" (* any) "\"" (* any)))
                                  ,source-root
                                  (submatch (: (* any) "\"" (* any) ">"))))
                             )))))
        ;body of let 
   )

but this seems a little clumsy --- what with the use of the lambda form
plus an extra set of brackets --- when you consider that a C-like
language would just do it thus:

if (condition)
{x = true;}
else 
{x = false;} 

I know that you could something similar with set!, but I thought we
didn't like set!. Is there a nicer way to do it?

Also, I get output like this: 


ajt@ariel:~/webwork$ ~/Projects/Scheme/arcfilter.scsh
body{ background: url("/~ajt/graphics/whale-bay.jpg");
div.paper{background: url("/~ajt/graphics/paper.png");
<table background="/~ajt/graphics/controlbarbg.png" cellpadding=10>
    <td >      <a href="/~ajt/index.php">  Home </a>  |</td>
    <td >      <a href="/~ajt/stuff.php">  Stuff </a> |</td>
    <td >     <a href="/~ajt/gallery.php"> Gallery  </a> | </td>
    <td > <a href="/~ajt/me.php">  Me </a></td>
    <td >   <a href="/~ajt/diary/index.php"> Diary </a> |</td>
    <td > <a href="/~ajt/guestbook.php" >Guestbook</a> | </td>
    <td  >      <a href="/~ajt/about.html"> About </a>
ajt@ariel:~/webwork$ 

which I'm not asking for. The only thing I can think of is that this
awk invocation: 


  (awk (read-line inport) (line) ()
                 (#t 
                  (regexp-substitute/global
                   outport
                   filtering-rx
                   line
                   'pre 1 target-root 2 'post)
                  (newline outport)
                  )

is returning 'line' (whose values are in fact what's getting printed
above) which is somehow bubbling up to the top and getting outputed by
the interpreter. But I would have thought that I'd only be getting the
last line at most, if that were the case, returned as the value of 'main'. 

The program's roughly 100 lines of code, which is a lot more than the
10 line bash script I had when I started. Admittedly it's doing a lot
more than the bash script ever was...

The script as it stands isn't doing any checks to see whether the
directory is writable or anything. It might also be a good idea to add
some sort of output to stdout to give some sort of feedback as to what
it's doing, perhaps with a -v. 

The only other improvement I can think of making is putting the
reading of the directories into a function, which stores the list
somehow, so that the source directory doesn't need to get read twice.

Also, I couldn't find any documentation for read-line. I know it's in
SLIB, but I don't think that's where scsh gets its read-line from (is
it?).

thanks, 

Andrew. 

<Prev in Thread] Current Thread [Next in Thread>