[plt-scheme] Errors from Snooze Quick Start

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Tue Jan 6 18:59:57 EST 2009

Typos corrected in Snooze 2.5.

> Cool, with that fix the only hitch I ran into was that the sqlite3

> version of make-database seems to expect a path, and not a string as
> the Quick Start suggests.

I saw and fixed that one too. It turns out Jay has added support for  
in-memory and temporary-file databases to sqlite.plt as well, which is  
rather nice! Pass one of the following special paths to specify them:

     (make-database ':memory:)
     (make-database ':temp:)

>> It's ugly but when I wrote the code I didn't know how to do it any  
>> other way
>> (suggestions for improvement would be much appreciated).
> I see, I've been thinking that it would be convenient for the
> structure syntax to expand to dynamic structure information when used
> as an expression. This is one place that would be useful.

Sorry - this is going to make me look really dense. Does "as an  
expression" mean wrapping it in parentheses? If so I think I might  
have had the same or a similar idea. See below.

> This is more of a general question, not related to the quick start, so
> I guess the list is still the right place. Is there a way to avoid
> having two sets of names for each data type? I can see that person1 is
> used to prevent the names from conflicting with the structure
> accessors, but it's confusing to have to remember the differences
> between person and person1.

This has always bugged me.

I've been working on an SQL language for Mirrors, to give people the  
ability to create SQL without all the ERA trappings of Snooze. I  
thought about this problem again and I came up with a tentative  

The Mirrors language as it stands will have a define-table macro,  
which is basically like define-persistent-struct:

   (define-table person
     ([name ...]
      [age  ...]))

One you have defined a table, you can access the run-time metadata  
using the identifier without parentheses:

   (table-name person)    ; ==> symbol
   (table-columns person) ; ==> (listof column)
   ; and so on ...

but if you use my-table with parentheses, you get what is effectively  
an alias for use in queries:

   (person)               ; ==> table-alias
   (person name)          ; ==> column-alias

   (sql (select #:from (my-table)))

You still have access to define-alias if you need to reference two  
instances of a table in a single query:

   (define-alias my-table-1 my-table)
   (sql (select #:from (outer my-table my-table-1)))

This is obviously a bit cryptic but it does solve a number of problems:

   - you don't have to use define-alias unless you want to alias a  
table twice within the same query;
   - you have a default alias you can rely on when constructing  
queries from code spread across several modules;
   - all the aliases for a table and its columns come from a single  
identifier, making them easier to provide/require.

What do you think?

-- Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090106/587c8446/attachment.html>

Posted on the users mailing list.