permaculture playing cards
The moose likes Clojure and the fly likes Loading a file and executing it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Clojure
Bookmark "Loading a file and executing it" Watch "Loading a file and executing it" New topic

Loading a file and executing it

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hi guys : Making some progress w/ clojure. Ran into a wall though :

I'm trying to simply (1) load a file, and then (2) execute a method in that file. However, the method is not seen ?

So I have two questions

1) How can I know what methods have been loaded and defined by my file ?


2) How can I execute the hello() function in the aforementioned script from REPL ?

and finally,

3) This is unrelated, but.... What is the "#" in the '#"\W+"' function (see below) doing ? I always assumed that # sign's were for anonymous functions, but #"\W+" seems more like a regex, i.e. it shouldnt need a pound before it ?

(filter #(> (count %) 2) (re-split #"\W+" "A day"))

Thanks ..........
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 269

If you're using a namespace in your Example1.clj, you'll need to switch to that namespace in the REPL in order to access those functions - or qualify them with the namespace you just loaded. Something like:

assuming the namespace matches your file path name, or:

To get a list of public vars in a namespace, use:

That will show everything in the user namespace (where the REPL is by default) and everything in your test.Example1 namespace. (vals (ns-publics ...)) might prove easier to read.

# identifies a "reader macro" called dispatch and there are several forms, including #(anonymous function), #"regex", #{a set} - see for more detail.
Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

On a side note, just keep in mind to use list syntax to call functions in Clojure.
(func param) not func param
I agree. Here's the link:
subject: Loading a file and executing it