[plt-scheme] Template Forms

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Thu Mar 4 14:14:50 EST 2010

On Thu, Mar 4, 2010 at 9:45 AM, Doug Williams
<m.douglas.williams at gmail.com> wrote:
> The template documentation in Web: PLT Web Applications includes a little
> blurb about the in special form that wraps a for/list to make it easier to
> use. Are there other helper forms for other binding forms. In particular,
> are there any that wrap simple let or let-values?
>
> A real example from a template that generates Graphviz output:
>
> The following uses in and looks nice. It binds the values and generates the
> line for each query result.
>
> @in[(action-class-id action-class-label) (in-query `(action-class ,rule-id
> ?id ?label))]{
> "@|rule-id|":"action-class" -> "@|action-class-id|" [style=dashed];
> }
>
> But, since there should be exactly one result to that query and there is a
> lighter-weight function, query-values, that has more appropriate semantics -
> in particular, it will generate an error if there is not exactly one result,
> I'd rather use let-values than the sequencing form.
>
> @let-values[(((action-class-id action-class-label) (query-values
> `(action-class ,rule-id ?id ?label))))]{
> @list{
> "@|rule-id|":"action-class" -> "@|action-class-id|" [style=dashed];
> }}
>
> works just fine, but is rather cumbersome. Is there a better way to write
> this using @ syntax?

If you limit yourself to one body, you could use a macro like:

(let-values-ish [(a b) expr] ... expr)

You could parse a little more and make

(let-values-ish (a b) expr ... expr)

work. But I haven't written either of these or something like it.

Jay

>
> Doug
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.