First-class namespaces and more

58 views
Skip to first unread message

Rich Hickey

unread,
Jan 29, 2008, 6:48:46 PM1/29/08
to Clojure
The wait is over, Clojure now has first-class namespaces (in SVN).

I've made several breaking changes, mostly renames, in an effort to
bundle these up in a single release, and am thinking about
subsequently moving from an alpha to a beta designation.

Renamed eql? to =
= does number value equivalence now, e.g. (= 1 1.0), (= (int 1) (long
1)), etc -> true
added not=
renamed sym to symbol
renamed appl to partial
instance? takes args in opposite order now - (instance? class x), so
it can be partially applied.
identical? is a fn, not a special op

Lots of namespace stuff either new or renamed:

in-namespace renamed in-ns, will create the namespace if it doesn't
exist
*current-namespace* renamed to *ns*, and is a Namespace object, not a
symbol
import has same syntax as before, but creates mappings from names to
Class objects, not strings

find-ns [sym]
create-ns [sym]
remove-ns [sym]
all-ns []
ns-name [ns]
ns-unmap [ns sym], removes the mapping from the namespace, whether an
interned var, referred var, or imported class

ns-map [ns], a map of all mappings in the namespace, union of interns/
imports/refers.
ns-exports [ns], a map of the exported vars
ns-imports [ns], a map of the imported classes
ns-refers [ns], a map of the referred-to vars from other namespaces
ns-interns [ns], all of the internal vars of the namespace, exported
or not

ns-resolve [ns sym], returns the object to which the symbol refers in
the namespace.
resolve [sym] -> (resolve *ns* sym)

export [syms], sets the vars named, by the syms, which must be
interned in *ns*, to be exported
refer [ns-symbol & filters]
refers to all exported vars of ns, subject to filters
filters can include at most one each of (CL keyword arg style):
:exclude list-of-symbols
:only list-of-symbols
:rename map-of-fromsymbol-tosymbol

You can find the above by diffing boot.clj against itself at rev 615

Other changes:

No need to load boot.clj, now included and loaded from the jar
But you must build with Ant, which you can do in IntelliJ.
Go to Ant build window and add build.xml
Take any launching configurations (e.g. Repl) and add -cp
clojure.jar to the VM parameters
Take src/boot.clj off the program parameters
Under Before launch
deselect Make
select run Ant target, push ... and select jar
If someone could send me the changes needed for the Maven script I'd
appreciate it.

added Class literals, you can just use fully.qualified.Classname or
any imported Classname, no need for (class Classname), and get the
Class object - the class special op is gone

A new namespace doesn't refer to or intern anything (but imports
java.lang), so you'll need to
(clojure/refer 'clojure)
to get the built-ins from boot.clj (the Repl already does this for
user namespace)

Added:

take-nth [n coll], lazy seq of every nth item
interleave [& colls], lazy seq of one item from each collection etc
filter-key [keyfn pred amap], a lazy seq of those items for which
(pred (keyfn item)) is logical true

array-map [keyval*] ,a map implementation on an array of alternating
keys and values. Linear lookup time, so only good for very small maps.
Has the property that keys stay in the order they are supplied.

For use of non-interned vars:

var-get [#^clojure.lang.Var x]
var-set [#^clojure.lang.Var x val]
macro with-local-vars [name-vals-vec & body]

Added some simple emit and emit-element functions to src/xml.clj to go
back to XML

Added simple GUI inspector capability in src/inspector.clj:

inspect-tree [x], will load the data structure into a JTree
inspect-table [x], will load the data structure into a JTable. The
data structure must be a seq of uniform vectors or maps

Many under-the-hood improvements.

For intrepid souls interested in any or all of the above, I'd
appreciate if you'd kick the tires.

Thanks again for all the input and feedback,

Rich

Toralf

unread,
Jan 30, 2008, 4:16:46 AM1/30/08
to Clojure
This looks all very good to me. Especially the export stuff and that
it creates a real interface now, i.e. only exported symbols can be
accessed from other namespaces. Many thanks!

- Toralf

Stuart Sierra

unread,
Jan 30, 2008, 10:04:03 PM1/30/08
to Clojure
On Jan 29, 6:48 pm, Rich Hickey <richhic...@gmail.com> wrote:
> The wait is over, Clojure now has first-class namespaces (in SVN).
>
> I've made several breaking changes, mostly renames, in an effort to
> bundle these up in a single release, and am thinking about
> subsequently moving from an alpha to a beta designation.

Amazing, fantastic, awesome. The inspect-tree & inspect-table
functions really show off the utility of Clojure + Swing.
-Stuart

Tatu Tarvainen

unread,
Jan 31, 2008, 11:40:47 AM1/31/08
to Clojure


On 30 tammi, 01:48, Rich Hickey <richhic...@gmail.com> wrote:

Great release!

> If someone could send me the changes needed for the Maven script I'd
> appreciate it.
Here is a minimal version that works:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jvm.clojure</groupId>
<artifactId>clojure-lang</artifactId>
<name>clojure-lang</name>
<version>1.0-SNAPSHOT</version>
<url>http://clojure.sourceforge.net/</url>
<build>
<sourceDirectory>src/jvm</sourceDirectory>
<scriptSourceDirectory>src</scriptSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/</directory>
</resource>
</resources>
</build>
</project>


I removed everything that wasn't used (the asm lib which seems to be
included as source, junit tests and surefire plugin).
Added the resources to include the .clj files from the source into the
generated jar file.


> Rich

Rich Hickey

unread,
Jan 31, 2008, 12:11:48 PM1/31/08
to Clojure


On Jan 31, 11:40 am, Tatu Tarvainen <tatu.tarvai...@mac.com> wrote:
> On 30 tammi, 01:48, Rich Hickey <richhic...@gmail.com> wrote:
>
> Great release!
>
> > If someone could send me the changes needed for the Maven script I'd
> > appreciate it.
>
> Here is a minimal version that works:
> ...
> I removed everything that wasn't used (the asm lib which seems to be
> included as source, junit tests and surefire plugin).
> Added the resources to include the .clj files from the source into the
> generated jar file.
>

Thanks! In SVN now.

Rich
Reply all
Reply to author
Forward
0 new messages