Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading a file and executing it  RSS feed

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 312
14
Clojure Linux Mac OS X Monad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a side note, just keep in mind to use list syntax to call functions in Clojure.
(func param) not func param
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!