From: Brad Anderson
Subject: Object instantiation issue in let
Date: 
Message-ID: <d82l4d$3r3$1@newsdbm05.news.prodigy.com>
Hi all,

I'm trying to create some object instances and use them to define other
objects.  Here's my code:

(defun join-test ()
  (let (
        (f (make-instance 'table :name "factSales" :alias "f"))
        (s (make-instance 'table :name "dimStores" :alias "s"))
        (i (make-instance 'table :name "dimItems" :alias "i"))
        (j1 (make-instance 'join
                           :type :inner
                           :left-table f
                           :right-table s))
        (j2 (make-instance 'join
                           :type :inner
                           :left-table f
                           :right-table i)))
    (format t "~{~a ~}" (mapcar #'get-sql (j1 j2)))))


In SBCL, I'm receiving warnings on F, S, and I are undefined variables.
 At the REPL, when running (join-test) I receive:

The variable F is unbound.
   [Condition of type UNBOUND-VARIABLE]


In other code, I'm able to do this by defparameter and then setf'ing the
variable to the make-instance form.  However, I just want to use these
objects in the let scope.

Am I trying to do the right thing here, or missing something about
assignment/binding and make-instance?

I'm a newb, so any other comments on the code are welcome, too.  By the
way, this is just a test function.  The tables, fields, and joins will
be coming from a metadata structure held in a database, and will be
variable in length, so will not be so hard-coded.

Yes, I have looked at CL-SQL, but we want more control over the code
(for now).  We may still use it in the future as a layer just below our
objects to talk to all the different databases CL-SQL can chat with.

Thanks,
Brad

From: Wade Humeniuk
Subject: Re: Object instantiation issue in let
Date: 
Message-ID: <SO4pe.44523$9A2.473@edtnps89>
Brad Anderson wrote:
> Hi all,
> 
> I'm trying to create some object instances and use them to define other
> objects.  Here's my code:
> 
> (defun join-test ()
>   (let (

Change the above let to let* .

See

http://www.lispworks.com/documentation/HyperSpec/Body/s_let_l.htm#letST

Wade

>         (f (make-instance 'table :name "factSales" :alias "f"))
>         (s (make-instance 'table :name "dimStores" :alias "s"))
>         (i (make-instance 'table :name "dimItems" :alias "i"))
>         (j1 (make-instance 'join
>                            :type :inner
>                            :left-table f
>                            :right-table s))
>         (j2 (make-instance 'join
>                            :type :inner
>                            :left-table f
>                            :right-table i)))
>     (format t "~{~a ~}" (mapcar #'get-sql (j1 j2)))))
> 
From: Brad Anderson
Subject: Re: Object instantiation issue in let
Date: 
Message-ID: <W77pe.1423$I14.115@newssvr12.news.prodigy.com>
Wade Humeniuk wrote:
> Brad Anderson wrote:
> 
>> Hi all,
>>
>> I'm trying to create some object instances and use them to define other
>> objects.  Here's my code:
>>
>> (defun join-test ()
>>   (let (
> 
> 
> Change the above let to let* .
> 
> See
> 
> http://www.lispworks.com/documentation/HyperSpec/Body/s_let_l.htm#letST
> 
> Wade

Bah,

I knew that from a c.l.l. post the other day.  Oh well, added to the 
list of mistakes I hope to not make again.

Thanks Wade and Edi.  Any chance I could get you two to stand behind me 
while I type?  For relatively no cost?

BA
From: Robert Uhl
Subject: Re: Object instantiation issue in let
Date: 
Message-ID: <m3d5qyr7mz.fsf@4dv.net>
Brad Anderson <····@dsource.dot.org> writes:
>
> (defun join-test ()
>   (let (
>         (f (make-instance 'table :name "factSales" :alias "f"))
>         (s (make-instance 'table :name "dimStores" :alias "s"))
>         (i (make-instance 'table :name "dimItems" :alias "i"))
>         (j1 (make-instance 'join
>                            :type :inner
>                            :left-table f
>                            :right-table s))
>         (j2 (make-instance 'join
>                            :type :inner
>                            :left-table f
>                            :right-table i)))
>     (format t "~{~a ~}" (mapcar #'get-sql (j1 j2)))))
>
>
> In SBCL, I'm receiving warnings on F, S, and I are undefined variables.

LET binds all variables at once; your binding of j1 references f & s;
your binding of j2 references f & i.

LET* binds variables in a left-to-right fashion; it should do the trick
for your.

-- 
Robert Uhl <http://public.xdi.org/=ruhl>
Come, all ye faithful, and let us worship the holy Resurrection of
Christ.  For, lo! by the Cross hath joy come to all the world.
From: Matthias Buelow
Subject: Re: Object instantiation issue in let
Date: 
Message-ID: <3h1fcaFenu82U1@news.dfncis.de>
Robert Uhl wrote:

> LET* binds variables in a left-to-right fashion; it should do the trick
> for your.

Hmm, I have a very general question concerning the naming terminology of
(Common) Lisp. Does the asterisk in LET* stand for something like prime,
since LET' is invalid syntax? Because, if the asterisk stood for the
closure operator, as it often does, then I'd argue that all bindings
should be reciprocally visible, like in Scheme's letrec. Does anyone
know the origin of such naming conventions?

mkb.
From: drkm
Subject: Re: Object instantiation issue in let
Date: 
Message-ID: <wkhdg42tug.fsf@fgeorges.org>
Matthias Buelow <···@incubus.de> writes:

> Hmm, I have a very general question concerning the naming terminology of
> (Common) Lisp. Does the asterisk in LET* stand for something like prime,

  It stands for an alternative version.  The two operators do the
same thing, but a little difference...

--drkm
From: Edi Weitz
Subject: Re: Object instantiation issue in let
Date: 
Message-ID: <u64wrgjr5.fsf@agharta.de>
On Mon, 06 Jun 2005 18:10:05 -0500, Brad Anderson <····@dsource.dot.org> wrote:

> Am I trying to do the right thing here, or missing something about
> assignment/binding and make-instance?

Use LET* instead of LET.

  <http://www.gigamonkeys.com/book/variables.html>

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")