2

On my Windows XP box with sbcl-1.4.14 I've installed the ASDF using

(load "C:\\Program Files\\clisp-2.49\\asdf\\asdf.lisp")
(require :asdf)
(push "C:\\Documents and Settings\\mayhem\\lisp\\iterate\\" asdf:*central-registry*)

On SLIME

(require :iterate)
(iterate (for i from 1 to 5) (collect (* i i)))

gives The variable I is unbound error

If I do (in-package :iterate), the code above works fine but this time familiar functions such as exit and other functions which I've defined in .sbclrc cease to work, they give The function ITERATE::EXIT is undefined type of errors, for example.

If I do (use-package :iterate), then it gives [Condition of type NAME-CONFLICT] error.

So I began to use the package like this: (iterate:iterate (iterate:for i from 1 to 5) (iterate:collect (* i i))) But I think you'll agree that it's a bad style.

How to use the iterate correctly?

Note: I've seen the post about the very similar problem but it didn't help. There aren't many posts or articles about this particular problem.

Lars Malmsteen
  • 738
  • 4
  • 23
  • For sbcl see http://www.sbcl.org/manual/#Package-Variance to have additional errors and restarts on package variance – coredump Feb 06 '21 at 11:44

1 Answers1

5

You need to say (use-package :iterate) before you try to refer to unqualified symbols from the iterate package.

What has happened in your case is this.

  1. You've loaded the iterate system into the running Lisp, creating a package called "ITERATE".
  2. In the "CL-USER" package you've typed (iterate ...), and the reader has worked out that it needs to find or create a symbol whose name is "ITERATE" and which is accessible in the "CL-USER" package.
  3. There is no such symbol, so it creates a new one, CL-USER::ITERATE.
  4. This is not ITERATE:ITERATE so you get an error from the evaluator as it's trying to evaluate the arguments to a function (which doesn't exist, but it doesn't know that yet). In fact the error you're getting is while it's evaluating the first argument in the (for i ...) subform.
  5. Now you say (use-package :iterate) to tell the system to add the "ITERATE" package to "CL-USER"'s search list.
  6. Now there's a conflict: should iterate refer to the existing CL-USER::ITERATE or the newly-accessible ITERATE::ITERATE? (And there are some other conflicts too, probably).
  7. So the system signals an error, and there should be some useful ways to proceed from that, one of which is probably 'unintern all the conflicting "CL-USER" symbols', but you didn't take that option, I suppose.
  8. So now everything is messed up.

And the answer is: use the packages you want to refer to unqualified symbols from before you try to refer to those symbols unqualified.

(Also: Windows XP? I'm impressed by your retroness.)

  • When I enter `(require :iterate) (use-package :iterate)` befohand and then evaluate the code, dit it finally work. I wouldn't guess the order was important here. And yes I love and use Windows XP but for this particular problem I haven't uses it by preference. I've used it because my Windows 7 had issues loading `ASDF` and I post a question about it too: https://stackoverflow.com/q/66061146/12212606 – Lars Malmsteen Feb 07 '21 at 16:35