From: Emre Sevinc
Subject: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <b4738fd6-501b-4f99-bf91-b4a1c4bbd023@p2g2000prf.googlegroups.com>
Dear Lispers,

I have searched the archives for "Problem enabling bracket mode it
CLSQL" but the replies there did not help me.

As you may have guessed I have a similar problem:

CG-USER(104): (clsql:enable-sql-reader-syntax)
CG-USER(105): (clsql:select 'album
              :where [= [slot-value 'album 'id] 1]
              :flatp t)

Error: Attempt to take the value of the unbound variable `[='.
[condition type: UNBOUND-VARIABLE]

The clqsl manual says that "ENABLE-SQL-READER-SYNTAX — Globally enable
square bracket reader syntax." so I couldn't understand why it didn't
work.

I tried it without brackets, again no success:

CG-USER(106): (clsql:select 'album
              :where (= (slot-value 'album 'id) 1)
              :flatp t)
Error: The slot ID is missing from the object ALBUM of class
       #<BUILT-IN-CLASS SYMBOL> during operation SLOT-VALUE
[condition type: PROGRAM-ERROR]

To assure you, I must state that I DO have the id field in my album
class and it works, e.g.:

CG-USER(107): (loop for an-album in (clsql:select 'album :flatp t)
                  do (format t "~A~%" (id an-album)))
1
2
3
4
5
.
.
.


You may see the definiton of my album class at the end of the message.

Any ideas about how I can retrieve only some of the album instances
based on some WHERE conditions within clsql?

Regards.

Here's my album class definition:

(clsql:def-view-class album ()
  ((id
    :accessor id
    :db-kind :key
    :db-constraints :not-null
    :type integer
    :initarg :ID)
   (name
    :accessor name
    :type (varchar 255)
    :db-reader utf-8-bytes
    :initarg :Name)
   (artist
    :accessor artist
    :type integer
    :initarg :Artist)
   (date
    :accessor date
    :type (varchar 4)
    :initarg :Date)
   (label
    :accessor :label
    :type integer
    :initarg :Label)
   (studio
    :accessor :studio
    :type (varchar 255)
    :db-reader utf-8-bytes
    :initarg :Studio))
  (:base-table "Album"))


--
Emre Sevinc

From: Wade
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <bd08d437-14bc-487a-9078-39727446cec0@i24g2000prf.googlegroups.com>
Looks like you have a problem with the Lisp you are using.  Which
one is it?  (It works fine with ccl).  Your enable sql syntax
appears to be broken.

In case you're wondering what the select expands to, its

(CLSQL-SYS:SELECT 'ALBUM
                  :WHERE
                  (CLSQL-SYS:SQL-= (CLSQL-SYS:SQL-SLOT-VALUE 'ALBUM
'ID) 1)
                  :FLATP
                  T)

You could use that in the meantime.

Wade
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <4320f046-7ed9-4109-bfe9-7d972b97234c@w1g2000prk.googlegroups.com>
On Dec 29, 5:51 pm, Wade <·············@gmail.com> wrote:
> Looks like you have a problem with the Lisp you are using.  Which
> one is it?  (It works fine with ccl).  Your enable sql syntax
> appears to be broken.
>
> In case you're wondering what the select expands to, its
>
> (CLSQL-SYS:SELECT 'ALBUM
>                   :WHERE
>                   (CLSQL-SYS:SQL-= (CLSQL-SYS:SQL-SLOT-VALUE 'ALBUM
> 'ID) 1)
>                   :FLATP
>                   T)
>
> You could use that in the meantime.

I've just tried that and it works:

CG-USER(10): (clsql:select 'album
              :where
              (clsql:sql-=
               (clsql-sys:sql-slot-value 'album 'id) 1)
              :flatp t)
(#<ALBUM @ #x720cdf8a>)

--
Emre Sevinc
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <b97db6fc-989f-40e5-aaf2-5e8f5a9218f6@n33g2000pri.googlegroups.com>
On Dec 29, 5:51 pm, Wade <·············@gmail.com> wrote:
> Looks like you have a problem with the Lisp you are using.  Which
> one is it?  (It works fine with ccl).  Your enable sql syntax
> appears to be broken.

I'm running Allegro Common Lisp Express Edition 8.1 (the free as in
beer version) on my Ubuntu GNU/Linux. I had aptitude install the cl-
sql package from the Ubuntu hardy repository.

This is how I compiled and then run my clsql within Allegro CL
typically:

(push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
(asdf:operate 'asdf:load-op 'clsql)

--
Emre Sevinc
From: Pascal J. Bourguignon
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <7cljtzawgg.fsf@pbourguignon.anevia.com>
Emre Sevinc <···········@gmail.com> writes:

> Dear Lispers,
>
> I have searched the archives for "Problem enabling bracket mode it
> CLSQL" but the replies there did not help me.
>
> As you may have guessed I have a similar problem:
>
> CG-USER(104): (clsql:enable-sql-reader-syntax)
> CG-USER(105): (clsql:select 'album
>               :where [= [slot-value 'album 'id] 1]
>               :flatp t)
>
> Error: Attempt to take the value of the unbound variable `[='.
> [condition type: UNBOUND-VARIABLE]
>
> The clqsl manual says that "ENABLE-SQL-READER-SYNTAX — Globally enable
> square bracket reader syntax." so I couldn't understand why it didn't
> work.

Try:

(clsql:select 'album
               :where [ = [ slot-value 'album 'id ] 1 ]
               :flatp t)

If that works, then it might be an error in the non-terminating-p flag
in ENABLE-SQL-READER-SYNTAX...

Otherwise, check that (get-macro-character #\[ ) doesn't return NIL.
If it does, or if it doesn't return the reader function from CLSQL,
then again it would mean a problem with ENABLE-SQL-READER-SYNTAX.

-- 
__Pascal Bourguignon__
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <4a782a69-09ab-48c8-9bfe-a65f652734b8@b38g2000prf.googlegroups.com>
On Dec 29, 4:26 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Emre Sevinc <···········@gmail.com> writes:
> > Dear Lispers,
>
> > I have searched the archives for "Problem enabling bracket mode it
> > CLSQL" but the replies there did not help me.
>
> > As you may have guessed I have a similar problem:
>
> > CG-USER(104): (clsql:enable-sql-reader-syntax)
> > CG-USER(105): (clsql:select 'album
> >               :where [= [slot-value 'album 'id] 1]
> >               :flatp t)
>
> > Error: Attempt to take the value of the unbound variable `[='.
> > [condition type: UNBOUND-VARIABLE]
>
> > The clqsl manual says that "ENABLE-SQL-READER-SYNTAX — Globally enable
> > square bracket reader syntax." so I couldn't understand why it didn't
> > work.
>
> Try:
>
> (clsql:select 'album
>                :where [ = [ slot-value 'album 'id ] 1 ]
>                :flatp t)
>
> If that works, then it might be an error in the non-terminating-p flag
> in ENABLE-SQL-READER-SYNTAX...
>
> Otherwise, check that (get-macro-character #\[ ) doesn't return NIL.
> If it does, or if it doesn't return the reader function from CLSQL,
> then again it would mean a problem with ENABLE-SQL-READER-SYNTAX.

Here are the results:

CG-USER(112): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

CG-USER(113): (clsql:select 'album
                            :where [ = [ slot-value 'album 'id ] 1 ]
                            :flatp t)
Error: Attempt to take the value of the unbound variable `['.
[condition type: UNBOUND-VARIABLE]

Should I pass some parameters to ENABLE-SQL-READER-SYNTAX?

--
Emre Sevinc
From: Pascal J. Bourguignon
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <7chc4nar7b.fsf@pbourguignon.anevia.com>
Emre Sevinc <···········@gmail.com> writes:

> On Dec 29, 4:26 pm, ····@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> Emre Sevinc <···········@gmail.com> writes:
>> > Dear Lispers,
>>
>> > I have searched the archives for "Problem enabling bracket mode it
>> > CLSQL" but the replies there did not help me.
>>
>> > As you may have guessed I have a similar problem:
>>
>> > CG-USER(104): (clsql:enable-sql-reader-syntax)
>> > CG-USER(105): (clsql:select 'album
>> >               :where [= [slot-value 'album 'id] 1]
>> >               :flatp t)
>>
>> > Error: Attempt to take the value of the unbound variable `[='.
>> > [condition type: UNBOUND-VARIABLE]
>>
>> > The clqsl manual says that "ENABLE-SQL-READER-SYNTAX — Globally enable
>> > square bracket reader syntax." so I couldn't understand why it didn't
>> > work.
>>
>> Try:
>>
>> (clsql:select 'album
>>                :where [ = [ slot-value 'album 'id ] 1 ]
>>                :flatp t)
>>
>> If that works, then it might be an error in the non-terminating-p flag
>> in ENABLE-SQL-READER-SYNTAX...
>>
>> Otherwise, check that (get-macro-character #\[ ) doesn't return NIL.
>> If it does, or if it doesn't return the reader function from CLSQL,
>> then again it would mean a problem with ENABLE-SQL-READER-SYNTAX.
>
> Here are the results:
>
> CG-USER(112): (get-macro-character #\[ )
> #<Function READ-TOKEN>
> T
>
> CG-USER(113): (clsql:select 'album
>                             :where [ = [ slot-value 'album 'id ] 1 ]
>                             :flatp t)
> Error: Attempt to take the value of the unbound variable `['.
> [condition type: UNBOUND-VARIABLE]
>
> Should I pass some parameters to ENABLE-SQL-READER-SYNTAX?

No, the reader syntax is installed ok, but that syntax doesn't know [.  It's the second [ that is in error.

Try:

 (clsql:select 'album
          :where [ = (slot-value 'album 'id) 1 ]
          :flatp t)

Now, I don't know what syntax is processed by the reader macro for #\[
but (slot-value 'album 'id) is a lisp form that will signal an error
(as you've seen in  your previous post), since ALBUM is not a CLOS
object but a mere symbol.  Perhaps you will have to write something
else instead of (slot-value 'album 'id).  But the point is that reader
macro for #\[ does not seem to expect square brackets inside.

-- 
__Pascal Bourguignon__
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <08b8751e-1099-4e18-b541-9e1eabd2485c@q26g2000prq.googlegroups.com>
On Dec 29, 6:20 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Emre Sevinc <···········@gmail.com> writes:
> > On Dec 29, 4:26 pm, ····@informatimago.com (Pascal J. Bourguignon)
> > wrote:
> >> Emre Sevinc <···········@gmail.com> writes:
> >> > Dear Lispers,
>
> >> > I have searched the archives for "Problem enabling bracket mode it
> >> > CLSQL" but the replies there did not help me.
>
> >> > As you may have guessed I have a similar problem:
>
> >> > CG-USER(104): (clsql:enable-sql-reader-syntax)
> >> > CG-USER(105): (clsql:select 'album
> >> >               :where [= [slot-value 'album 'id] 1]
> >> >               :flatp t)
>
> >> > Error: Attempt to take the value of the unbound variable `[='.
> >> > [condition type: UNBOUND-VARIABLE]
>
> >> > The clqsl manual says that "ENABLE-SQL-READER-SYNTAX — Globally enable
> >> > square bracket reader syntax." so I couldn't understand why it didn't
> >> > work.
>
> >> Try:
>
> >> (clsql:select 'album
> >>                :where [ = [ slot-value 'album 'id ] 1 ]
> >>                :flatp t)
>
> >> If that works, then it might be an error in the non-terminating-p flag
> >> in ENABLE-SQL-READER-SYNTAX...
>
> >> Otherwise, check that (get-macro-character #\[ ) doesn't return NIL.
> >> If it does, or if it doesn't return the reader function from CLSQL,
> >> then again it would mean a problem with ENABLE-SQL-READER-SYNTAX.
>
> > Here are the results:
>
> > CG-USER(112): (get-macro-character #\[ )
> > #<Function READ-TOKEN>
> > T
>
> > CG-USER(113): (clsql:select 'album
> >                             :where [ = [ slot-value 'album 'id ] 1 ]
> >                             :flatp t)
> > Error: Attempt to take the value of the unbound variable `['.
> > [condition type: UNBOUND-VARIABLE]
>
> > Should I pass some parameters to ENABLE-SQL-READER-SYNTAX?
>
> No, the reader syntax is installed ok, but that syntax doesn't know [.  It's the second [ that is in error.
>
> Try:
>
>  (clsql:select 'album
>           :where [ = (slot-value 'album 'id) 1 ]
>           :flatp t)
>
> Now, I don't know what syntax is processed by the reader macro for #\[
> but (slot-value 'album 'id) is a lisp form that will signal an error
> (as you've seen in  your previous post), since ALBUM is not a CLOS
> object but a mere symbol.  Perhaps you will have to write something
> else instead of (slot-value 'album 'id).  But the point is that reader
> macro for #\[ does not seem to expect square brackets inside.

Things started to look very weird now. Because yesterday I simply copy
and pasted what my Lisp returned as:

CG-USER(112): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

Today I ran AllegroCL again, ran clsql, checked that it can connect to
MySQL and retrieve some results however now enabling sql reader syntax
seems to return NIL! I don't have the slightest idea what is going on:

CG-USER(15): (clsql:enable-sql-reader-syntax)
CG-USER(16): (get-macro-character #\[ )
#<Function SQL-READER-OPEN>
NIL
CG-USER(17): (clsql:select 'album
                           :where [ = (slot-value 'album 'id) 1 ]
                           :flatp t)
Error: The slot ID is missing from the object ALBUM of class
       #<BUILT-IN-CLASS SYMBOL> during operation SLOT-VALUE
[condition type: PROGRAM-ERROR]
CG-USER(18): (clsql:locally-enable-sql-reader-syntax)
CG-USER(19): (get-macro-character #\[ )
#<Function SQL-READER-OPEN>
NIL

One day I run  enable-sql-reader-syntax and at it least returns non-
NIL for (get-macro-character #\[ ) (even though it complains for the
brackets) the other day it returns NIL for (get-macro-character #\[ )
even though I tried both (clsql:enable-sql-reader-syntax) and
(clsql:locally-enable-sql-reader-syntax).

I don't want to believe that kind of non-determinism.

--
Emre Sevinc
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <c96eb002-463c-4c98-870e-affe83724434@u18g2000pro.googlegroups.com>
On Dec 29, 6:20 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Emre Sevinc <···········@gmail.com> writes:
> > On Dec 29, 4:26 pm, ····@informatimago.com (Pascal J. Bourguignon)
> > wrote:
> >> Emre Sevinc <···········@gmail.com> writes:
> >> > Dear Lispers,
>
> >> > I have searched the archives for "Problem enabling bracket mode it
> >> > CLSQL" but the replies there did not help me.
>
> >> > As you may have guessed I have a similar problem:
>
> >> > CG-USER(104): (clsql:enable-sql-reader-syntax)
> >> > CG-USER(105): (clsql:select 'album
> >> >               :where [= [slot-value 'album 'id] 1]
> >> >               :flatp t)
>
> >> > Error: Attempt to take the value of the unbound variable `[='.
> >> > [condition type: UNBOUND-VARIABLE]
>
> >> > The clqsl manual says that "ENABLE-SQL-READER-SYNTAX — Globally enable
> >> > square bracket reader syntax." so I couldn't understand why it didn't
> >> > work.
>
> >> Try:
>
> >> (clsql:select 'album
> >>                :where [ = [ slot-value 'album 'id ] 1 ]
> >>                :flatp t)
>
> >> If that works, then it might be an error in the non-terminating-p flag
> >> in ENABLE-SQL-READER-SYNTAX...
>
> >> Otherwise, check that (get-macro-character #\[ ) doesn't return NIL.
> >> If it does, or if it doesn't return the reader function from CLSQL,
> >> then again it would mean a problem with ENABLE-SQL-READER-SYNTAX.
>
> > Here are the results:
>
> > CG-USER(112): (get-macro-character #\[ )
> > #<Function READ-TOKEN>
> > T
>
> > CG-USER(113): (clsql:select 'album
> >                             :where [ = [ slot-value 'album 'id ] 1 ]
> >                             :flatp t)
> > Error: Attempt to take the value of the unbound variable `['.
> > [condition type: UNBOUND-VARIABLE]
>
> > Should I pass some parameters to ENABLE-SQL-READER-SYNTAX?
>
> No, the reader syntax is installed ok, but that syntax doesn't know [.  It's the second [ that is in error.
>
> Try:
>
>  (clsql:select 'album
>           :where [ = (slot-value 'album 'id) 1 ]
>           :flatp t)
>

CG-USER(36): (clsql:select 'album
              :where [= [slot-value 'album 'id] 1]
              :flatp t)
(#<ALBUM @ #x720a0b3a>)

It seems to work now. Don't understand why it didn't yesterday.

--
Emre Sevinc
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <4c39bc23-fb45-4fff-a26b-ff3493d55f81@a29g2000pra.googlegroups.com>
> Try:
>
>  (clsql:select 'album
>           :where [ = (slot-value 'album 'id) 1 ]
>           :flatp t)

Things really baffle me now. I just can't understand how I was able to
have the previous situation and make [ syntax work correctly (at least
for a few seconds):

CG-USER(15): (clsql:enable-sql-reader-syntax)
CG-USER(16): (get-macro-character #\[ )
#<Function SQL-READER-OPEN>
NIL

I exited and restarted Allegro CL, loaded clsql and I simply cannot
get the same effect no matter what I tried:

CG-USER(49): (clsql-sys:enable-sql-reader-syntax)
CG-USER(50): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

CG-USER(51): (clsql-sys:locally-enable-sql-reader-syntax)
CG-USER(52): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

CG-USER(53): (clsql-sys:restore-sql-reader-syntax-state)
CG-USER(54): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

CG-USER(55): #.(clsql:locally-enable-sql-reader-syntax)
CG-USER(56): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

CG-USER(57): #.(clsql:enable-sql-reader-syntax)
CG-USER(58): (get-macro-character #\[ )
#<Function READ-TOKEN>
T

Just a few minutes ago I was able to have #<Function SQL-READER-OPEN>
and [ did not create a problem I was able to run the form which
included it. Now back to the same situation.

I also try the example from clsql-manual-latest.pdf which reads:

"Intended to be used in a file for code which uses the square bracket
syntax without changing the global state.

             #.(locally-enable-sql-reader-syntax)
             ... CODE USING SYMBOLIC SQL SYNTAX ...
             #.(restore-sql-reader-syntax-state)
"

CG-USER(61): #.(clsql:locally-enable-sql-reader-syntax)
(car (clsql:select 'album
              :where [= [slot-value 'album 'id] 1]
              :flatp t))
#.(clsql:locally-disable-sql-reader-syntax)
Error: Attempt to take the value of the unbound variable `[='.
[condition type: UNBOUND-VARIABLE]

--
Emre Sevinc
From: ······@corporate-world.lisp.de
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <ca5daabb-170b-44cf-be57-52f530fd1523@r37g2000prr.googlegroups.com>
On 30 Dez., 11:01, Emre Sevinc <···········@gmail.com> wrote:
> > Try:
>
> >  (clsql:select 'album
> >           :where [ = (slot-value 'album 'id) 1 ]
> >           :flatp t)
>
> Things really baffle me now. I just can't understand how I was able to
> have the previous situation and make [ syntax work correctly (at least
> for a few seconds):
>
> CG-USER(15): (clsql:enable-sql-reader-syntax)
> CG-USER(16): (get-macro-character #\[ )
> #<Function SQL-READER-OPEN>
> NIL
>
> I exited and restarted Allegro CL, loaded clsql and I simply cannot
> get the same effect no matter what I tried:
>
> CG-USER(49): (clsql-sys:enable-sql-reader-syntax)
> CG-USER(50): (get-macro-character #\[ )
> #<Function READ-TOKEN>
> T
>
> CG-USER(51): (clsql-sys:locally-enable-sql-reader-syntax)
> CG-USER(52): (get-macro-character #\[ )
> #<Function READ-TOKEN>
> T
>
> CG-USER(53): (clsql-sys:restore-sql-reader-syntax-state)
> CG-USER(54): (get-macro-character #\[ )
> #<Function READ-TOKEN>
> T
>
> CG-USER(55): #.(clsql:locally-enable-sql-reader-syntax)
> CG-USER(56): (get-macro-character #\[ )
> #<Function READ-TOKEN>
> T
>
> CG-USER(57): #.(clsql:enable-sql-reader-syntax)
> CG-USER(58): (get-macro-character #\[ )
> #<Function READ-TOKEN>
> T
>
> Just a few minutes ago I was able to have #<Function SQL-READER-OPEN>
> and [ did not create a problem I was able to run the form which
> included it. Now back to the same situation.
>
> I also try the example from clsql-manual-latest.pdf which reads:
>
> "Intended to be used in a file for code which uses the square bracket
> syntax without changing the global state.
>
>              #.(locally-enable-sql-reader-syntax)
>              ... CODE USING SYMBOLIC SQL SYNTAX ...
>              #.(restore-sql-reader-syntax-state)
> "
>
> CG-USER(61): #.(clsql:locally-enable-sql-reader-syntax)
> (car (clsql:select 'album
>               :where [= [slot-value 'album 'id] 1]
>               :flatp t))
> #.(clsql:locally-disable-sql-reader-syntax)
> Error: Attempt to take the value of the unbound variable `[='.
> [condition type: UNBOUND-VARIABLE]
>
> --
> Emre Sevinc

Now you are desperate and are trying random things. There is no need
to use #. in the REPL.

Check the syntax.lisp code and see what it does.

I would call disable-sql-reader-syntax first and then call enable-sql-
reader-syntax.
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <e3bf5d4b-1553-4c94-a2ba-f808a2b86642@s9g2000prg.googlegroups.com>
> Now you are desperate and are trying random things. There is no need
> to use #. in the REPL.
>
> Check the syntax.lisp code and see what it does.
>
> I would call disable-sql-reader-syntax first and then call enable-sql-
> reader-syntax.

As far as I can see my desperate situation is caused by not
understanding exactly how
Allegro CL operates and interprets Tools -> Incremental Evaluation (C-
M-v). Until that
enable-sql-reader-syntax issue, I was opening a file that I named
db.lisp and inside
it resided forms such as:

(push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
(asdf:operate 'asdf:load-op 'clsql)
.
.
.

I was selecting which forms I wanted to run and then C-M-v and seeing
results in the Debug Window (where Allegro CL puts its REPL). I
thought this was same as copying the lisp forms into the Debug Window
and pressing ENTER. Based on the evidence, I'm wrong.

However I had no problem in C-M-v'ing forms that loaded clsql, that
connected to database (using (clsql:connect ... etc. I was also able
to run some queries (as I've stated in the examples above) simply
moving the cursor to the form I wanted inside the db.lisp file and
pressing C-M-v.

However now I see that the situation with enable-sql-reader-syntax is
different (is it because of its being macro, am I running into some
namespace or package issues, I'm not sure). If, instead of going to
db.lisp window and C-M-v'ing (incremental evaluate), I copy and paste
the same lisp forms into the Debug Window (REPL) and run them there,
everything including the enable-sql-reader-syntax works as I expected.
Why I had this difference when I started to use enable-sql-reader-
syntax, I don't know exactly (why didn't I have the same sort of
problems when I simply C-M-v'ed forms within the db.lisp window, that
I don't understand).

--
Emre Sevinc
From: ······@corporate-world.lisp.de
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <3979b2ec-3abf-4bdd-a185-3b0ed3177a9e@r15g2000prh.googlegroups.com>
On 30 Dez., 12:38, Emre Sevinc <···········@gmail.com> wrote:
> > Now you are desperate and are trying random things. There is no need
> > to use #. in the REPL.
>
> > Check the syntax.lisp code and see what it does.
>
> > I would call disable-sql-reader-syntax first and then call enable-sql-
> > reader-syntax.
>
> As far as I can see my desperate situation is caused by not
> understanding exactly how
> Allegro CL operates and interprets Tools -> Incremental Evaluation (C-
> M-v). Until that
> enable-sql-reader-syntax issue, I was opening a file that I named
> db.lisp and inside
> it resided forms such as:
>
> (push #P"/usr/share/common-lisp/systems/" asdf:*central-registry*)
> (asdf:operate 'asdf:load-op 'clsql)
> .
> .
> .
>
> I was selecting which forms I wanted to run and then C-M-v and seeing
> results in the Debug Window (where Allegro CL puts its REPL). I
> thought this was same as copying the lisp forms into the Debug Window
> and pressing ENTER. Based on the evidence, I'm wrong.
>
> However I had no problem in C-M-v'ing forms that loaded clsql, that
> connected to database (using (clsql:connect ... etc. I was also able
> to run some queries (as I've stated in the examples above) simply
> moving the cursor to the form I wanted inside the db.lisp file and
> pressing C-M-v.
>
> However now I see that the situation with enable-sql-reader-syntax is
> different (is it because of its being macro, am I running into some
> namespace or package issues, I'm not sure). If, instead of going to
> db.lisp window and C-M-v'ing (incremental evaluate), I copy and paste
> the same lisp forms into the Debug Window (REPL) and run them there,
> everything including the enable-sql-reader-syntax works as I expected.
> Why I had this difference when I started to use enable-sql-reader-
> syntax, I don't know exactly (why didn't I have the same sort of
> problems when I simply C-M-v'ed forms within the db.lisp window, that
> I don't understand).
>
> --
> Emre Sevinc

One has to understand that there are three 'programs':

1) the REPL
2) the Editor
3) the user program

Each might have its own sets of values for global variables,
especially
if they run inside their own threads (Lisp processes), though they
run in a shared image.

For example if you set some IO variable, the REPL might not use it,
or bind it with its own values.

If one executes a command in the editor that might effect the
environment that the editor keeps for the file, but not the REPL.
There can also be more than one REPL.

If you ever used MCL, then you might be used to its behavior, that
it copies editor evaluations to a queue that is executed in the
(top most) REPL. It also places the results into the usual REPL
variables
(*, ...). Other Lisp IDEs necessarily don't do that. The editor
executes
its evaluations possibly directly. If you use an IDE you
have to understand where and how it evaluates.

A typical example:

there is a REPL and an editor with two Lisp files open.
Each of these three things uses a package. If you
read/evaluate something from the editor, the editor buffer's
package will be used. If you use the REPL it will use its
own package it is currently using (typically the value of *package*).
If you use the editor it looks either at its buffer value,
the top-most (in-package ...), or if it is really clever,
it has parsed the buffer and identified multiple
(in-package ) forms and chooses the package depending
from which part of the file you are evaluating the code.

If you for example change the readtable, the editor might still
be binding the readtable to some value before reading the form
from the buffer. You can easily test it, if the IDE does
use the global, changed readtable or binds it.

Another example: your code vs. the REPL.

Imagine, your code does something like:

1) (setf *print-length* 10)
2) (progn (print *long-list*) (values))
3) *long-list*

If you type that to the REPL, form 2 should print
the list using the print length.
But when you evaluate the form 3, the REPL might
have its own print-length binding and use that for its
own printing. You can imagine that this can be similar
with several global variables. For example the REPL
could have its own readtable binding. You should
think that your program is a separate program that sets
its own environment and the repl is another program
that has also some kind of environment.
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <dbc8778a-3d1d-4913-9b60-c50619f80d9f@w39g2000prb.googlegroups.com>
On Dec 30, 2:13 pm, ·······@corporate-world.lisp.de" <······@corporate-
world.lisp.de> wrote:
>  [...]
> 1) (setf *print-length* 10)
> 2) (progn (print *long-list*) (values))
> 3) *long-list*
>
> If you type that to the REPL, form 2 should print
> the list using the print length.
> But when you evaluate the form 3, the REPL might
> have its own print-length binding and use that for its
> own printing. You can imagine that this can be similar
> with several global variables. For example the REPL
> could have its own readtable binding. You should
> think that your program is a separate program that sets
> its own environment and the repl is another program
> that has also some kind of environment.


Thanks a lot for the detailed and clear explanation.

--
Emre
From: Alex Mizrahi
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <49590753$0$90273$14726298@news.sunsite.dk>
 ES> I have searched the archives for "Problem enabling bracket mode it
 ES> CLSQL" but the replies there did not help me.

 ES> As you may have guessed I have a similar problem:

 ES> CG-USER(104): (clsql:enable-sql-reader-syntax)
 ES> CG-USER(105): (clsql:select 'album
 ES>               :where [= [slot-value 'album 'id] 1]
 ES>               :flatp t)

shouldn't it be [album id] instead of [slot-value 'album 'id]? 
From: Emre Sevinc
Subject: Re: How to: clsql, select, bracket syntax problems
Date: 
Message-ID: <f368e3b3-a0d0-4ee2-ab97-6ed423c54665@o4g2000pra.googlegroups.com>
On Dec 29, 7:22 pm, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
>  ES> I have searched the archives for "Problem enabling bracket mode it
>  ES> CLSQL" but the replies there did not help me.
>
>  ES> As you may have guessed I have a similar problem:
>
>  ES> CG-USER(104): (clsql:enable-sql-reader-syntax)
>  ES> CG-USER(105): (clsql:select 'album
>  ES>               :where [= [slot-value 'album 'id] 1]
>  ES>               :flatp t)
>
> shouldn't it be [album id] instead of [slot-value 'album 'id]?

I have looked at an example file that I found in the clsql archive
file:

file:///home/cas/Documents/source/Lisp/clsql/clsql-4.0.3/examples/clsql-tutorial.lisp

In that file it reads:

(let ((new-lenin (car
                  (clsql:select 'employee
                              :where [= [slot-value 'employee 'emplid]
1]
                              :flatp t))))
  (format t "His new email is ~A"
          (employee-email new-lenin)))

and another example:

(clsql:select 'employee :where [= [slot-value 'employee 'last-name]
                                "Lenin"])


--
Emre Sevinc