From: Barry Jones
Subject: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <42d9dee0$0$3598$8f2e0ebb@news.shared-secrets.com>
I'm new to Lisp, and I decided to add a test framework to my project. I 
put the code at the bottom of chapter 9 (PCL) in a file. I then added 
the form:

(load ";Unit-test.lisp") to my project file, and it loads correctly.

I then evaluate:

(deftest test-+ ()
  (check
    (= (+ 1 2) 3)
    (= (+ 1 2 3) 6)
    (= (+ -1 -3) -4)))

and I get an error: "EVAL: variable RESULT has no value
          [Condition of type SYSTEM::SIMPLE-UNBOUND_VARIABLE]

I don't see anything obviously wrong. Here's the Unit-test.lisp code:
........................................................................................................
(defvar *test-name* nil)

(defmacro deftest (name parameters &body body)
  "Define a test function. Within a test function we can call
   other test functions or use 'check' to run individual test
   cases."
  `(defun ,name ,parameters
    (let ((*test-name* (append *test-name* (list ',name))))
      ,@body)))

(defmacro check (&body forms)
  "Run each expression in 'forms' as a test case."
  `(combine-results
    ,@(loop for f in forms collect `(report-result ,f ',f))))

(defmacro combine-results (&body forms)
  "Combine the results (as booleans) of evaluating 'forms' in order."
  (with-gensyms (result)
    `(let ((,result t))
      ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
      ,result)))

(defun report-result (result form)
  "Report the results of a single test case. Called by 'check'."
  (format t "~:[FAIL~;pass~] ... ~a: ~a~%" result *test-name* form)
  result)
...............................................................................................
Any help?
Thanks

Barry

From: Eric Lavigne
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <1121579705.312043.93040@g47g2000cwa.googlegroups.com>
>I'm new to Lisp, and I decided to add a test framework to my project. I
>put the code at the bottom of chapter 9 (PCL) in a file. I then added
>the form:
>
>(load ";Unit-test.lisp") to my project file, and it loads correctly.
>...
>and I get an error: "EVAL: variable RESULT has no value
>          [Condition of type SYSTEM::SIMPLE-UNBOUND_VARIABLE]
>...
>   (with-gensyms (result)

I suspect that your lisp doesn't have the with-gensyms macro, which is
defined in chapter 8. Find the with-gensyms definition in chapter 8 and
paste that into your code also.
From: Barry Jones
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <42d9fd74$0$3569$8f2e0ebb@news.shared-secrets.com>
Eric Lavigne wrote:

>>I'm new to Lisp, and I decided to add a test framework to my project. I
>>put the code at the bottom of chapter 9 (PCL) in a file. I then added
>>the form:
>>
>>(load ";Unit-test.lisp") to my project file, and it loads correctly.
>>...
>>and I get an error: "EVAL: variable RESULT has no value
>>         [Condition of type SYSTEM::SIMPLE-UNBOUND_VARIABLE]
>>...
>>  (with-gensyms (result)
>>    
>>
>
>I suspect that your lisp doesn't have the with-gensyms macro, which is
>defined in chapter 8. Find the with-gensyms definition in chapter 8 and
>paste that into your code also.
>  
>
Thanks Eric. That nails it. However, when I load the Unit-test.lisp, 
which now includes with-gensyms, I get an error message, with an option 
to continue anyway. When I do, the Unit tests work. The message is:

DEFUN/DEFMACRO(WITH-GENSYMS: #<PACKAGE EXT> is locked

Does this strike a bell?

Barry
From: M Jared Finder
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <s_2dnXXf19bTHUffRVn-gg@speakeasy.net>
Barry Jones wrote:
> Eric Lavigne wrote:
> 
>>> I'm new to Lisp, and I decided to add a test framework to my project. I
>>> put the code at the bottom of chapter 9 (PCL) in a file. I then added
>>> the form:
>>>
>>> (load ";Unit-test.lisp") to my project file, and it loads correctly.
>>> ...
>>> and I get an error: "EVAL: variable RESULT has no value
>>>         [Condition of type SYSTEM::SIMPLE-UNBOUND_VARIABLE]
>>> ...
>>>  (with-gensyms (result)
>>
>> I suspect that your lisp doesn't have the with-gensyms macro, which is
>> defined in chapter 8. Find the with-gensyms definition in chapter 8 and
>> paste that into your code also.
>>
> Thanks Eric. That nails it. However, when I load the Unit-test.lisp, 
> which now includes with-gensyms, I get an error message, with an option 
> to continue anyway. When I do, the Unit tests work. The message is:
> 
> DEFUN/DEFMACRO(WITH-GENSYMS: #<PACKAGE EXT> is locked
> 
> Does this strike a bell?

That's telling you that your lisp already has a with-gensyms and you are 
redefining it.  What implementation are you using?  You could read the 
documentation for your implementation; for example CLisp's with-gensyms 
is described at <http://clisp.cons.org/impnotes/macros3.html>.

   -- MJF
From: Paul F. Dietz
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <9oadnV37ctWtHEffRVn-rg@dls.net>
M Jared Finder wrote:

> That's telling you that your lisp already has a with-gensyms and you are 
> redefining it.  What implementation are you using?  You could read the 
> documentation for your implementation; for example CLisp's with-gensyms 
> is described at <http://clisp.cons.org/impnotes/macros3.html>.

It's also an example of why working in the CL-USER package can
be a bad idea -- all sorts of implementation-specific stuff
can be imported into there.

	Paul
From: Peter Seibel
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <m264v9guuj.fsf@gigamonkeys.com>
"Paul F. Dietz" <·····@dls.net> writes:

> M Jared Finder wrote:
>
>> That's telling you that your lisp already has a with-gensyms and you
>> are redefining it.  What implementation are you using?  You could
>> read the documentation for your implementation; for example CLisp's
>> with-gensyms is described at
>> <http://clisp.cons.org/impnotes/macros3.html>.
>
> It's also an example of why working in the CL-USER package can be a
> bad idea -- all sorts of implementation-specific stuff can be
> imported into there.

Yes. Unfortunately the test framework code comes before the discussion
of packages in the book. FWIW, I tried to mitigate this some in the
Lispbox distribution (no, still not available on Windows but inching
closer) by running this bit of code as part of the Lispbox initialization:

  ;;; Clean up CL-USER package
  (loop with cl = (find-package :cl)
     for p in (package-use-list :cl-user) 
     unless (eql p cl) do (unuse-package p :cl-user))
  (use-package :asdf :cl-user)
  (use-package :com.gigamonkeys.asdf-extensions :cl-user)

This makes CL-USER free of implementation specific packages (which are
still, of course, available to be reused by those who know that
they're about) and then puts back some Lispbox specific bits such as
ASDF and a few extensions to ASDF.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Barry Jones
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <42dab1ae$0$3628$8f2e0ebb@news.shared-secrets.com>
Peter Seibel wrote:

>"Paul F. Dietz" <·····@dls.net> writes:
>
>  
>
>>M Jared Finder wrote:
>>
>>    
>>
>>>That's telling you that your lisp already has a with-gensyms and you
>>>are redefining it.  What implementation are you using?  You could
>>>read the documentation for your implementation; for example CLisp's
>>>with-gensyms is described at
>>><http://clisp.cons.org/impnotes/macros3.html>.
>>>      
>>>
>>It's also an example of why working in the CL-USER package can be a
>>bad idea -- all sorts of implementation-specific stuff can be
>>imported into there.
>>    
>>
>
>Yes. Unfortunately the test framework code comes before the discussion
>of packages in the book. FWIW, I tried to mitigate this some in the
>Lispbox distribution (no, still not available on Windows but inching
>closer) by running this bit of code as part of the Lispbox initialization:
>
>  ;;; Clean up CL-USER package
>  (loop with cl = (find-package :cl)
>     for p in (package-use-list :cl-user) 
>     unless (eql p cl) do (unuse-package p :cl-user))
>  (use-package :asdf :cl-user)
>  (use-package :com.gigamonkeys.asdf-extensions :cl-user)
>
>This makes CL-USER free of implementation specific packages (which are
>still, of course, available to be reused by those who know that
>they're about) and then puts back some Lispbox specific bits such as
>ASDF and a few extensions to ASDF.
>
>-Peter
>  
>
Hi Peter. Thanks for the info. I renamed the with-gensyms macro to 
my-with-gensyms to avoid the problem. I don't know what things I'd be 
removing with that loop. Are they all broken?

Do most people set up there own user space?

I think this installation of Lispbox and CLisp is a bit of a mess. I 
believe I did the right stuff when I installed it, but none of the help 
files show up, if I type (defun   , slime replies (defun -- <not 
available>). At my stage of Lispness, I don't know enough to get in 
there and straighten it out.

I've been using MCL for a few weeks on OSX, but I need to use the PC for 
about a week. I really haven't been able to find where the equivalent of 
init.lisp is, and I can't find information about the commands available 
in SLIME, or the correct directory tree and files for a good installation.

Is there a better way to set this up? A different implementation perhaps?

Barry
From: Pascal Bourguignon
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <87br51b275.fsf@thalassa.informatimago.com>
Barry Jones <········@acm.org> writes:
> Do most people set up there own user space?

Of course, this is entirely mandatory of you want to avoid such problems.
That's why you see so many:

(defpackage "MY-PACKAGE" (:use "COMMON-LISP"))
(in-package "MY-PACKAGE)
...


> I think this installation of Lispbox and CLisp is a bit of a mess. 

Lispbox should definitely clean up the COMMON-LISP-USER package.



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
You're always typing.
Well, let's see you ignore my
sitting on your hands.
From: Peter Seibel
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <m2slydexzo.fsf@gigamonkeys.com>
Barry Jones <········@acm.org> writes:

> Peter Seibel wrote:
>
>>"Paul F. Dietz" <·····@dls.net> writes:
>>
>>  
>>
>>>M Jared Finder wrote:
>>>
>>>    
>>>
>>>>That's telling you that your lisp already has a with-gensyms and you
>>>>are redefining it.  What implementation are you using?  You could
>>>>read the documentation for your implementation; for example CLisp's
>>>>with-gensyms is described at
>>>><http://clisp.cons.org/impnotes/macros3.html>.
>>>>      
>>>>
>>>It's also an example of why working in the CL-USER package can be a
>>>bad idea -- all sorts of implementation-specific stuff can be
>>>imported into there.
>>>    
>>>
>>
>>Yes. Unfortunately the test framework code comes before the discussion
>>of packages in the book. FWIW, I tried to mitigate this some in the
>>Lispbox distribution (no, still not available on Windows but inching
>>closer) by running this bit of code as part of the Lispbox initialization:
>>
>>  ;;; Clean up CL-USER package
>>  (loop with cl = (find-package :cl)
>>     for p in (package-use-list :cl-user)     unless (eql p cl) do
>> (unuse-package p :cl-user))
>>  (use-package :asdf :cl-user)
>>  (use-package :com.gigamonkeys.asdf-extensions :cl-user)
>>
>>This makes CL-USER free of implementation specific packages (which are
>>still, of course, available to be reused by those who know that
>>they're about) and then puts back some Lispbox specific bits such as
>>ASDF and a few extensions to ASDF.
>>
>>-Peter
>>  
>>
> Hi Peter. Thanks for the info. I renamed the with-gensyms macro to
> my-with-gensyms to avoid the problem. I don't know what things I'd be
> removing with that loop. Are they all broken?

It's not that they're broken. It's just that they're implementation
dependent and thus get in the way when you're just trying to learn
standard Common Lisp. They can be quite useful once you have a better
idea what's going on--when you'll be doing most of your real
programming in your own packages (as others have suggested) it's nice
to have some of the implementation dependent conveniences readily
available in CL-USER.

> Do most people set up there own user space?

Yes, see the chapter on Packages for more info.

> I think this installation of Lispbox and CLisp is a bit of a mess. I
> believe I did the right stuff when I installed it, but none of the
> help files show up, if I type (defun   , slime replies (defun -- <not
> available>). At my stage of Lispness, I don't know enough to get in
> there and straighten it out.

Is that the Lispbox installation from my web site (gigamonkeys.com) or
Matthew Danish's version? (If it's on Windows, it must be Matthew's.)

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Barry Jones
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <42db1ab1$0$3551$8f2e0ebb@news.shared-secrets.com>
Peter Seibel wrote:

>Barry Jones <········@acm.org> writes:
>
>  
>
>>I think this installation of Lispbox and CLisp is a bit of a mess. I
>>believe I did the right stuff when I installed it, but none of the
>>help files show up, if I type (defun   , slime replies (defun -- <not
>>available>). At my stage of Lispness, I don't know enough to get in
>>there and straighten it out.
>>    
>>
>
>Is that the Lispbox installation from my web site (gigamonkeys.com) or
>Matthew Danish's version? (If it's on Windows, it must be Matthew's.)
>
>-Peter
>
>  
>
I'll try to  retrace my steps. The download and installation took place 
in early May, I think.

On the gigamonkeys site there is a link for downloads:

http://www.gigamonkeys.com/book/lispbox/download.html

It says "windows: not yet available."

So, I think I googled "Lisp in a box" and got to:

http://common-lisp.net/project/lispbox/#windows

which is where I think I downloaded it from.

Barry

-- 
Heisenberg may have been here.
From: Pascal Bourguignon
Subject: Re: Help with Peter Seibel's Unit test framework.
Date: 
Message-ID: <87vf39bc9h.fsf@thalassa.informatimago.com>
"Paul F. Dietz" <·····@dls.net> writes:

> M Jared Finder wrote:
>
>> That's telling you that your lisp already has a with-gensyms and you
>> are redefining it.  What implementation are you using?  You could
>> read the documentation for your implementation; for example CLisp's
>> with-gensyms is described at
>> <http://clisp.cons.org/impnotes/macros3.html>.
>
> It's also an example of why working in the CL-USER package can
> be a bad idea -- all sorts of implementation-specific stuff
> can be imported into there.

And it's the reason why I have this in my ~/.common.lisp:

(defpackage "COM.INFORMATIMAGO.PJB")
;; Clean the packages imported into COMMON-LISP-USER:
(MAPC (LAMBDA (COM.INFORMATIMAGO.PJB::USED)
        (UNUSE-PACKAGE COM.INFORMATIMAGO.PJB::USED "COMMON-LISP-USER"))
      (REMOVE (FIND-PACKAGE "COMMON-LISP")
              (COPY-SEQ (PACKAGE-USE-LIST "COMMON-LISP-USER"))))


Another good reason to clean-up CL-USER, is to avoid using non
portable stuff obliviously.


Note that since LOAD resets *PACKAGE* to what it was before LOAD,  you
cannot change the initial package in the startup files, so it's either
clean up COMMON-LISP-USER, or manually start your sessions with
(IN-PACKAGE "MY-SCRATCH-PACKAGE").



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Small brave carnivores
Kill pine cones and mosquitoes
Fear vacuum cleaner