From: Paulo J. Matos aka PDestroy
Subject: Closure
Date: 
Message-ID: <3B1958B5.5EBF34DF@netcabo.pt>
Hi,
I'm defining a closure as follows:
(defun set-all-var-prob (file)
  (setf get-prob-info (probfun file)))

When compiling, each time I it sees:
(funcall get-prob-info)

it issues a warning:
GET-PROB-INFO is neither declared nor bound,
it will be treated as if it were declared SPECIAL.

Anyway, it compiles and everything works fine, but I'm not understanding
what the compiler is saying. Can you pls help me solve this situation?

Best regards,
-- 
+------------------Paulo J. Matos aka PDestroy--------------------+
|  ICQ # 361853  |  http://www.pdestroy.net | ········@netcabo.pt |
|  http://iascp.sourceforge.net  |  http://mega.ist.utl.pt/~pocm  |
|  "Fixed width font LIVEZ!"     |  "Portability came to rule!"   |
+-----------------------------------------------------------------+

I name my wife: Gala, Galuska, Gradiva; Oliva, for the oval shape of her
face and the colour of her skin; Oliveta, diminutive for Olive; and its
delirious derivatives Oliueta, Oriueta, Buribeta, Buriueteta, Suliueta,
Solibubuleta, Oliburibuleta, Ciueta, Liueta. I also call her Lionette,
because when she hets angry she roars like the Metro-Goldwyn-Mayer Lion.
           - Dali, Salvador

From: Barry Margolin
Subject: Re: Closure
Date: 
Message-ID: <EgBS6.5$5t5.515@burlma1-snr2>
In article <·················@netcabo.pt>,
Paulo J. Matos aka PDestroy <········@netcabo.pt> wrote:
>Hi,
>I'm defining a closure as follows:
>(defun set-all-var-prob (file)
>  (setf get-prob-info (probfun file)))

That's not a closure, you're just setting a global variable.

>When compiling, each time I it sees:
>(funcall get-prob-info)
>
>it issues a warning:
>GET-PROB-INFO is neither declared nor bound,
>it will be treated as if it were declared SPECIAL.
>
>Anyway, it compiles and everything works fine, but I'm not understanding
>what the compiler is saying. Can you pls help me solve this situation?

Use DEFVAR to declare that get-prob-info is a global variable:

(defvar get-prob-info)

That will suppress the warning.

Note: by convention, global variables are named with *'s around them,
e.g. *get-prob-info*.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Pierre R. Mai
Subject: Re: Closure
Date: 
Message-ID: <87zobpm6cw.fsf@orion.bln.pmsf.de>
"Paulo J. Matos aka PDestroy" <········@netcabo.pt> writes:

> Hi,
> I'm defining a closure as follows:
> (defun set-all-var-prob (file)
>   (setf get-prob-info (probfun file)))

You are not defining a closure here.  A (lexical) closure is a
function that was defined in a non-null lexical environment, and that
closes over some part of that environment, by referencing said part.
E.g.

(defun generate-demo-closure (var1 var2)
  #'(lambda (x y) (+ x y var1)))

Here calling generate-demo-closure will create and return a closure,
because the inner anonymous function closes over var1, which it
references, but that is part of the outer functions lexical
environment.

You are doing something completely different, and it is difficult to
deduce what exactly you are intending to do.

> When compiling, each time I it sees:
> (funcall get-prob-info)
> 
> it issues a warning:
> GET-PROB-INFO is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.

This is expected, because you are changing the variable get-prob-info,
which is neither part of the lexical environment (there was no binding
form enclosing set-all-var-prob that bound that variable), nor has it
been declared special (e.g. by defvar/defparameter, or some
stand-alone special declaration/proclamation currently in-scope).
It is undefined what happens in such an instance, but most
implementations assume you really just missed the proper special
declaration, and will therefore assume you wanted to change the global
special variable of that name.

In reality you don't want to do that.  If you really want a global
special variable, declare it as such, e.g. by

(defvar *get-prob-info*)

[ Note that I put * around the name, since you should name all your
  special variables in this manner, to prevent interactions with
  non-special variables ]

Now you could write your code as 

(defun set-all-var-prob (file)
  (setf *get-prob-info* (probfun file)))

and your invocations as

(funcall *get-prob-info*)

But it still seems to me that you really don't want to do it this way.

If you could provide more details what you are really trying to
achieve, we might offer you advice on how best to do that.

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein
From: Paulo J. Matos aka PDestroy
Subject: Re: Closure
Date: 
Message-ID: <3B1B5802.9249732F@netcabo.pt>
Thanks for the help...
I'm confused then...
My ideia is, I'm reading info from a file and I want to put that info
into a structure and that structure should be something like a static
variable since teachers at college don't like global variables much
(*grin*).
So I decided I'd be reading the info and return it in a list and I would
define the following:
(defun set-all-var-prob (file)
  (setf get-prob-info (probfun file)))

(defun probfun (file)
  (let* ((probdim (set-prob-dim file))
	(lestados (set-prob-estados file))
	(estado-prob (make-estadoprob :dprob probdim
				      :iestado (first lestados)
				      :festado (second lestados)
				      :notab (third lestados))))
    #'(lambda ()
	estado-prob)))

Like this I'm able to get the element dprob of estado-prob as
(estado-prob-dprob (funcall get-prob-info)) :)
Any ideas to remove the warning and/or improve this?

Best regards,

"Paulo J. Matos aka PDestroy" wrote:
> 
> Hi,
> I'm defining a closure as follows:
> (defun set-all-var-prob (file)
>   (setf get-prob-info (probfun file)))
> 
> When compiling, each time I it sees:
> (funcall get-prob-info)
> 
> it issues a warning:
> GET-PROB-INFO is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
> 
> Anyway, it compiles and everything works fine, but I'm not understanding
> what the compiler is saying. Can you pls help me solve this situation?
> 
> Best regards,
> --
> +------------------Paulo J. Matos aka PDestroy--------------------+
> |  ICQ # 361853  |  http://www.pdestroy.net | ········@netcabo.pt |
> |  http://iascp.sourceforge.net  |  http://mega.ist.utl.pt/~pocm  |
> |  "Fixed width font LIVEZ!"     |  "Portability came to rule!"   |
> +-----------------------------------------------------------------+
> 
> I name my wife: Gala, Galuska, Gradiva; Oliva, for the oval shape of her
> face and the colour of her skin; Oliveta, diminutive for Olive; and its
> delirious derivatives Oliueta, Oriueta, Buribeta, Buriueteta, Suliueta,
> Solibubuleta, Oliburibuleta, Ciueta, Liueta. I also call her Lionette,
> because when she hets angry she roars like the Metro-Goldwyn-Mayer Lion.
>            - Dali, Salvador

-- 
+------------------Paulo J. Matos aka PDestroy--------------------+
|  ICQ # 361853                  |            ········@netcabo.pt |
|  http://iascp.sourceforge.net  |  http://mega.ist.utl.pt/~pocm  |
|  "Fixed width font LIVEZ!"     |    "Portability came to rule!" |
+-----------------------------------------------------------------+

Heroin, cocaine, drunkography, opium and pederasty were sure vehicles to
ephemeral success. The freemasonry of vice buoyed all its members...
Gala's and my strenght was that we always lived a healthy life in the
midst of all the physical and moral promiscuity, taking no part in it
without smoking, without taking dope, without sleeping around.
           - Dali, Salvador