[plt-scheme] Newbie problems with leftparen and **

From: Rob Hunter (rob.hunter at gmail.com)
Date: Thu Jul 16 02:39:09 EDT 2009


Well, there are at least two of us LeftParen users out there,
so...yes?  I'll address your question here about  the ** function.
I'm certainly happy to answer any other questions you might have, but
they should probably be sent privately to me so that we can keep this
list specifically about PLT stuff.

** is a way to group together multiple html elements.  Say you want to
write a function that consumes a name and returns an html markup
welcome message.  E.g., given "rob", you want to return the markup

<h1>Welcome, Rob</h1>
<p>Your name has 3 letters in it.</p>

One solution would be to write

(define (welcome name)
     (h1 ,name)
     (p ,(format "Your name has ~A letters in it." (string-length name)))))

But this would return a bogus <div /> wrapper--something we didn't ask
for in the spec.  It might not matter, but sometimes when doing CSS
styling, it is nice to be able to get the exact markup that you want.
This is why LeftParen offers **, which you could use like this:

(define (welcome name)
  (** `(h1 ,name)
       `(p ,(format "Your name has ~A letters in it." (string-length name)))))

And now when you invoke (name "Rob"), you get the desired html markup.
 The implementation of ** is quite simple.  It's just a "group" tag
(which you discovered).  The group tag is just something random I
chose, and LeftParen automatically searches for group tags and strips
them before actually painting the html--so they should never show up
on an actual LeftParen rendered web page.

Just a few other notes:
- You wrote `(p "Hello world") but there's no reason to use the
backtick here since you aren't "splicing in" any Scheme expressions.
Using '(p "Hello world") would suffice.

- For the link you were wondering about, you could just write
'(a ((href "some address")) "some text here")
or use the web-link function (included by default; defined in
web-support.scm in the LeftParen source):
(web-link "some text here" "some address")


On Wed, Jul 15, 2009 at 9:58 AM, TPJ<tprimke at gmail.com> wrote:
> Does anybody use the leftparen framework?
> I started to work on a tutorial on writing servlets in Scheme (http://
> tprimke.wikidot.com/scheme:servlet:tutorial) and I'm trying to find
> out what the ** function does.
> For example, I know I can use it as follows:
> (** '(p "Hello, world!"))
> to get the "<p>Hello, world</p>" content, but how could I get a link
> like "<a href="some address">Some text here</a>"?
> Besides, evaluating
> (** '(p "Hello, world!"))
> gives (group (p "Hello, world!")) on my PLT Scheme 4.1.5. I can't find
> out what this group form is.
> Sorry, if my questions are lame, but I'm quite a newbie Schemer and a
> newbie servlet developer.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.