I always wanted to know more about functional programming and lisp – so I thought why not use Clojure. It runs on the JVM and I can try out some real-world problems with it.
This is the first part of a series of post’s I’m going to make to log my progress.
In this part I’ll show how to authenticate and search in Windchill using Clojure.
I use a mac, so installing Clojure is quite easy for me – YMMV::
Running the Clojure REPL
That’s easy, too:
1 2 3 4
Installing Clojure in Windchill
This is quite easy, too. Just drop the Clojure jar file to
$WT\_HOME/codebase/WEB-INF/lib. Then, when starting the REPL, be sure to
CLASSPATH set up correctly.
First Steps using Windchill
The first Task I wanted to solve is:
- authenticate against Windchill using the
- search for a named
EPMDocumentusing a custom-built
This is what I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
The code is also on github.
Things To Note
The first few lines (1..4) import Classes from the named packages to the current namespace.
(doto instance expr)special form saves quite some typing. (line 7)
It took a while until I figured out how to convert the enumeration from the
QueryResultto a Clojure sequence. It’s the
(enumeration-seq expr)special form. This is quite cool, as this probably means that the results from the search would be processed lazily, too. (line 23)
I had quite some problems getting the
(let [...] expr)special form right. For some reason I had one pair of parens too much and it kept evaluating a
nilresult from Java which caused a dreaded
Null Pointer Exception.
I started to put the
(authenticate ...)and the imports in a
user.clj, such that the REPL has these aitomatically loaded.
Things to explore: