I am writing a program in Lispworks using CLSQL in windows.
When I run the program in the listener line by line it runs like a
top. When I put it in a routine I get the follow error
intermittently....
Error: The variable [TEAM] is unbound.
This is the code in question
(clsql:connect '("EmployeeDatabase" "login" "password") :database-
type :odbc)
(clsql:enable-sql-reader-syntax)
(setf Teams (clsql:select [Team] :from [EmployeeData] :result-type
nil :order-by '(([Team] :asc))))
(clsql:disconnect)
I am not sure if this is a CLSQL issue or a Lisp issue. Can someone
tell me what I have done wrong?
Thanks,
William
Jacobite1607 <············@gmail.com> writes:
> I am writing a program in Lispworks using CLSQL in windows.
>
> When I run the program in the listener line by line it runs like a
> top. When I put it in a routine I get the follow error
> intermittently....
>
>
> Error: The variable [TEAM] is unbound.
>
>
> This is the code in question
>
> (clsql:connect '("EmployeeDatabase" "login" "password") :database-
> type :odbc)
> (clsql:enable-sql-reader-syntax)
> (setf Teams (clsql:select [Team] :from [EmployeeData] :result-type
> nil :order-by '(([Team] :asc))))
> (clsql:disconnect)
>
>
> I am not sure if this is a CLSQL issue or a Lisp issue. Can someone
> tell me what I have done wrong?
The key issue that you need to understand here is the difference between
read and evaluation time. When you enter the forms line-by-line, lisp will
read and evaluate each line in turn. This is what will also happen if
you have all the forms at top-level and load such a file.
But if you "put them in a routine", then you will presumably have done
something like:
(defun get-stuff ()
(clsql:connect ...)
(clsql:enable-sql-reader-syntax)
(setf Teams (clsql:select [Team] ...))
...)
What happens is that the reader will FIRST read the entire DEFUN form.
It is only when (GET-STUFF) is evaluated, that the code to enable the
reader syntax gets executed. But that is then too late, because the
reader will have already read in the symbol [TEAM] using the normal Lisp
reader syntax.
As Edi Weitz notes, you need to make sure that the reader syntax is
setup properly before lisp reads any forms that depend on that syntax.
--
Thomas A. Russ, USC/Information Sciences Institute
> What happens is that the reader will FIRST read the entire DEFUN form.
> It is only when (GET-STUFF) is evaluated, that the code to enable the
> reader syntax gets executed. But that is then too late, because the
> reader will have already read in the symbol [TEAM] using the normal Lisp
> reader syntax.
Very Interesting.... is this a common issue for symbols or is it
because of the CLSQL reading via a foreign syntax?
Thanks for the reply,
William
From: Edi Weitz
Subject: Re: CLSQL Error: The variable [FOO] is unbound. ?
Date:
Message-ID: <ubq6dq867.fsf@agharta.de>
On Tue, 19 Feb 2008 07:22:14 -0800 (PST), Jacobite1607 <············@gmail.com> wrote:
> I am writing a program in Lispworks using CLSQL in windows.
>
> When I run the program in the listener line by line it runs like a
> top. When I put it in a routine I get the follow error
> intermittently....
>
> Error: The variable [TEAM] is unbound.
>
> This is the code in question
>
> (clsql:connect '("EmployeeDatabase" "login" "password") :database-
> type :odbc)
> (clsql:enable-sql-reader-syntax)
> (setf Teams (clsql:select [Team] :from [EmployeeData] :result-type
> nil :order-by '(([Team] :asc))))
> (clsql:disconnect)
>
> I am not sure if this is a CLSQL issue or a Lisp issue. Can someone
> tell me what I have done wrong?
You're using CLSQL's reader syntax, so you must inform your Lisp that
you want to use it. Something like this:
#.(locally-enable-sql-reader-syntax)
;;; your code here
#.(restore-sql-reader-syntax-state)
http://clsql.b9.com/manual/ref-syntax.html
Edi.
--
European Common Lisp Meeting, Amsterdam, April 19/20, 2008
http://weitz.de/eclm2008/
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
> You're using CLSQL's reader syntax, so you must inform your Lisp that
> you want to use it. Something like this:
>
> #.(locally-enable-sql-reader-syntax)
>
> ;;; your code here
>
> #.(restore-sql-reader-syntax-state)
Thank You! Worked like a champ.
William