Re: questions: how to load a file "inlined" inside a let, and how to reference count objects
- From: pjb@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
- Date: Thu, 31 Jan 2008 11:03:58 +0100
Michael Kohout <mwkohout@xxxxxxxxx> writes:
Hello folks, a relative noob with a couple of two questions for you.
Of late, I've been working my way through the Little Schemer, PG's
ANSI Lisp and On Lisp, and Siebel's book.
I understand lexical closures...but I'm having some trouble making
them suit my needs. Is there was any(standard) way to "inline" files
into them?
Here's my example.
In the repl, I've got this:
(let ((x 1)) (load "test-scope.lisp")
and in the file "test-scope.lisp", I've got a function that simply
returns a var named x:
(defun return-x () ( list x ))
after running the first line in the repl, I call the return-x method
but it errors, complaining x isn't bound.
Of course if I simply inline the code from the file into the repl it
works just fine:
CL-USER> (let ((x 1))(defun return-x () ( list x )))
RETURN-X
CL-USER> (return-x)
(1)
in summary, my question is if there is any standard macro or whatnot
that does this for me: inlining loaded files so the example closure
will work.
This is not really a good idea, but if you really want it, have it:
(let ((x 1)) #.(COM.INFORMATIMAGO.COMMON-LISP.UTILITY:INCLUDE "file.lisp"))
;; http://darcs.informatimago.com/lisp/common-lisp/utility.lisp
my second query is if there is any way to count references of a
variable, for the purposes of maintaining an object pool. After a
brief google search I didn't find anything.
"reference count" is taboo around here ;-)
You can use weak references, in the form of weak hash-tables or other
weak structures or pointers. That is, you don't do it yourself, you
let the garbage collect do it. Type: (apropos "WEAK") in your REPL.
--
__Pascal Bourguignon__
.
- Follow-Ups:
- References:
- Prev by Date: Re: Security
- Next by Date: Re: Security
- Previous by thread: Re: questions: how to load a file "inlined" inside a let, and how to reference count objects
- Next by thread: Re: questions: how to load a file "inlined" inside a let, and how to reference count objects
- Index(es):