This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Clojure
Bookmark "Loading a file and executing it" Watch "Loading a file and executing it" New topic
Author

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 ?

and

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: 252
    
    5

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 http://clojure.org/reader for more detail.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

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: http://aspose.com/file-tools
 
subject: Loading a file and executing it
 
Similar Threads
How to reload a JSP with request.getAttribute values
jscript problems
iterating with a scriptlet, can't get the values into js arr
Struts2 Issue with localization: Messages not picked up from properties file for forward actions.
MultiDimenaional Array sort