This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Guile as modperl



> Also, i'm considering to have a feature similar to 
> Embedperl/PHP - inline-code in HTML.
> Everything around <?scm ... ?> would be translated into
> ``(display "...'', <?scm to ``")'', ?> to ``(display "'',
> and EOF to ``")''

Hi,

I have actually implemented this as a cgi interpreter, but not for guile
(long story, I needed a super-light weight version of scheme, so I used
my own little scheme implementation.)

I would _highly_ recommend dispensing with the <?scm notation. I found
that just lumping the scheme straight into HTML worked very well. It
results in just one special character being added to HTML (of course it
is the "(" character). Once it sees "(" it goes into scheme mode and
keeps parsing until it sees the corresponding ")".

So you get code like....
<HTML><BODY>
(lamda () ...)
<TABLE>
(foobar ...)
</TABLE>

You get the idea. I was very pleased with the way the syntaxes didn't
run over each other. The lispy () parenthesis syntax is sent from heaven
for this stuff because it is by nature enclosed in () without having to
invent new syntax.

I didn't implement something like being able to do like EmbPerl
[$ if (foo) $]
some lines of text
[$ endif $]

But if you want to do that, I'd still recommend staying with () syntax.
I'm not sure that it's necessary though. My experience with embperl is
that anything like this is often a candidate for re-use, and therefore
it ends up having to be in a separate file. It's better I think to leave
the code in a proper function, because then when you factor it out, you
don't need a new file for each factored out bit. Embperl seems to end up
with hundreds of little files for all the factored out bits. I found
that simply embedding scheme into HTML was what I wanted without going
to the extent of being able to just dump text between if and endif. I
found
(if (foo) (print
"this is some text"
"This is some more text"
"This is even more text"
))
To be quite sufficient. I think (probably)
<?scm (if (foo) ?>
This is some text
<?scm ) ?>

creates more problems than it solves. But experimentation would confirm
or deny this.


Anyway, you can pick it up from ftp://tech.com.au/pub/embscheme.tgz

The code itself may or may not be that much use, but it may give you
some ideas.


> This simple transformation would make the whole stuff very simple
> and elegant. As an example:
> 
> Checking for browser ...
> <?scm (if (string-match "lynx" (user-agent)) ?>
>         You use "lynx"
> <?scm?>
>         You use some inferior browser
> <?scm ) ?>
> <br>
> 
> Would be translated into
> (display "Checking for browser ...")
> (if (string-match "lynx" (user-agent))
>     (display "  You use \"lynx\"")
>     (display "  You use some inferior browser"))
> (display "<br>")
> 
> (well ok, probably not that nicely formatted, but formatting
> isn't *that* important here :])
> I ordered "Writing Apache modules in Perl and C" which should
> arrive on friday so i can start working then.
> 
> Things i'm not sure about for now:
> - I want to make apache modules be writeable in guile, like
>   mod_perl. Should the above be implemented rather in guile, then?
>   (sounds like a good idea)
> - How to make the environment secure. In perl (or Tcl, or Python)
>   i'd just create a new instances of the interpreter. Guile
>   doesn't have things like instances. I guess i'll have to do
>   something with the environment there, but i'm not sure about it
>   yet.
> - Wether to use a C parser in the mod_guile.c or a different
>   reader for guile for those pages
> 
> I wanted to come to this list and ask for people who have
> experience with Apache modules, and a better understanding of
> Guile's internals than i do, but since you asked, i guess i can
> come now :) Any more suggestions, ideas, etc.?
> 
> And to the other points:
> PHP sounds like a good platform to look at. It has all the stuff
> to be utterly replaced by guile.
> - Simple syntax&semantics: PHP reader for guile shouldn't be
>         a big problem
> - Crappy language: experienced people would love to use a more
>         powerful language without losing all the functions PHP
>         gives them
> - Nice function collection: PHP has alot of nice functions
>         (mostly library wrappers), which we could add to Guile's
>         module list.
>         (I've done a GD module, though it's not integrated into
>         Guile's module system (yet) - i'm waiting for the new
>         version. See http://forcix.cx/code/guile-gd.tar.gz)
>         People wanting to add to guile but not knowing what to do
>         can take a look at the online-manual of PHP (www.php.net)
>         and see what other libraries PHP uses and which are not
>         yet wrapped by guile
> 
> Then again, for the main mod_guile package (the one to make
> apache modules writeable in guile), i'll take a close look at
> mod_perl. Wrapping Apache's data structures in guile smobs or
> vectors can't be too difficult from what i've seen so far.
> 
> (define (add-version param d vers)
>   (ap-add-version-component vers))
> 
> (define version-cmds
>   (("AddVersion" add-version 0 RSRC_CONF TAKE1 "Server version to add")))
> 
> (module 0 0 0 0 0 version-cmds 0 0 0 0 0 0 0 0)
> 
> ... would be nice to write modules like that :]
> 
> Ok, to repeat my request above:
> If any of you have ideas, comments, critics, etc. please let me
> know.
>         -forcer
> 
> --
> ((email . "forcer@mindless.com")       (www . "http://forcix.cx/")
>  (irc   . "forcer@#StarWars (IRCnet)") (gpg . "/other/forcer.gpg"))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]