LISPOS: My manifesto
Kragen
kragen@pobox.com
Tue, 31 Mar 1998 16:08:18 -0500 (EST)
On Sat, 28 Mar 1998, cosc19z5@bayou.uh.edu wrote:
> For instance:
> select * from f where condition
>
> Can be modeled in Common Lisp by:
> (select '* :from f :where #'(lambda (x) (condition ...)))
>
> This construct is both familiar to users to Common Lisp, but also
> close enough syntactically to the SQL version to be familiar to SQL
> users as well.
>
> On a side note, use of the lambda in the :where adds
> some serious power (you now have the ability to format your tables
> and perform other side effecting as well as comparison operations
> all within the :where, and essentially for free from an
> implementation perspective).
If it's a traditional Scheme lambda, it's opaque to the select
function. This means that it is impossible to use indices. That is,
(select '(name) :from users :where (lambda (x) (= (acctnum x) 44833)))
can't use the primary-key index on users by acctnum, it has to look at
every record and call the lambda function on it.
This means that what was originally a simple hash-table lookup and
fetch, or possibly a b-tree lookup and fetch, becomes a process that
requires fetching something like 50,000 records from disk and calling a
couple of Scheme functions for each one of them.
This does not meet my definition of `essentially for free'.
However, I believe that you might reasonably be able to do it with
slightly different syntax.
(select '(name) :from users :where '(acctnum = 44833))
This is also more readable to SQL folks.
> (in this case lambda expressions give "where" tremendous
> flexibility and power [I believe more so than the original SQL],
I suspect that it is possible to incorporate lambda expressions into
where clauses and order by clauses in a reasonable way.
Kragen