21

Or do I have to specifically enumerate every class that I import?

I'm just learning Clojure now, and it seems useful to be able to do something like this in the REPL:

(import '(java.io *))

Not that this is valid syntax, but it would be nice to have something that does the equivalent. It would save some typing, especially when tinkering around. In actual production code I always enumerate each class that I'm importing, regardless of the language, but it's pretty convenient not to have to do so.

Jeff
  • 14,831
  • 15
  • 49
  • 59

3 Answers3

21

Rich Hickey explains why it is not possible.

miaubiz
  • 837
  • 5
  • 6
  • 4
    Bummer. I appreciate his thinking on why it's not a good idea, but I'd prefer not to have the language constrain me like that, particularly when playing around in the REPL. – Jeff Jan 03 '10 at 01:26
  • 3
    Note this is an explanation of why it is not possible to do efficiently at runtime. At compile time it can be made to work (obviously, since this is why you can do it in Java.....) – mikera Dec 07 '10 at 14:08
2

Unless I missed an update, there is no way to wild card include packages into a namespace in Clojure currently.

Runevault
  • 1,492
  • 9
  • 16
1

There seems to be no ways of doing that currently. The import macro is only there to import the specified classes into the current namespace. I've tried to write another macro to do what you want, but it doesn't appear to be possible with the class loader used by Clojure as it doesn't let us access package resources.

Nicolas Buduroi
  • 3,565
  • 1
  • 28
  • 29