Hi Telman,

Thanks, I got it.

-sun


On Jan 29, 9:58 pm, Telman Yusupov <use...@yusupov.com> wrote:
> Clojure sets the value of this var. If you call this var from REPL it
> will evaluate to nil:
>
> user=> *file*
> nil
>
> If you pass a file to Clojure on the command line, Clojure will set it
> to the location of this file.
>
> For example, create a simple file called test.clj with one line in it:
>
> (println *file*)
>
> Now, go to your shell/command prompt and run this from the directory
> where test.clj is:
>
> java clojure.main test.clj
>
> or run this
>
> java clojure.lang.Script test.clj
>
> - the output will be the value of *file* in both cases.
>
> I assume that your CLASSPATH contains path to clojure.jar, otherwise
> you will have to provide it:
>
> java -cp /path/to/clojure.jar clojure.main test.clj
>
> Cheers,
>
> Telman
>
> On Jan 29, 9:23 pm, wubbie <sunj...@gmail.com> wrote:
>
> > Hi Telman,
>
> > I know *file* is a built-in global. My question is that how
> > the value of *file* is set in the program.  It is in the first line
> > of the program so I don't know how it's set.
>
> > -sun
>
> > On Jan 29, 7:44 pm, Telman Yusupov <use...@yusupov.com> wrote:
>
> > > Hi Sun,
>
> > > *file* seems to be one of the built-in global vars (there is more -
> > > vars like *command-line-args*, *compile-path* and others in core.clj
> > > file).
>
> > > If you really need to see the source of it, look for SOURCE_PATH in
> > > Compiler.java in Clojure's source code in jvm/clojure/lang directory.
>
> > > Cheers,
>
> > > Telman
>
> > > On Jan 29, 1:00 pm, wubbie <sunj...@gmail.com> wrote:
>
> > > > again I don't know how *file* gets current dir value. Maybe some
> > > > magic?
>
> > > > -sun
>
> > > > On Jan 29, 12:30 pm, Telman Yusupov <use...@yusupov.com> wrote:
>
> > > > > I had the same question, that was answered by typing this into REPL:
>
> > > > > user=> (doc *file*)
>
> > > > > Output:
>
> > > > > -------------------------
> > > > > clojure.core/*file*
> > > > > nil
> > > > >   The path of the file being evaluated, as a String.
> > > > >   Evaluates to nil when there is no file, eg. in the REPL.
>
> > > > > On Jan 29, 7:03 am, wubbie <sunj...@gmail.com> wrote:
>
> > > > > > Hello,
>
> > > > > > As you see, java.io.File. construct takes path argument but it is 
> > > > > > the
> > > > > > first line of code and I don't know how *file* gets value of current
> > > > > > directory.
>
> > > > > > #!/usr/bin/env clj
>
> > > > > > (add-classpath (str "file://" (.getParent (java.io.File. *file*))
> > > > > > "/"))
>
> > > > > > (ns mire
> > > > > >   (:use [mire commands player rooms])
> > > > > >   (:use [clojure.contrib server-socket duck-streams]))
> > > > > > ....
>
> > > > > > thanks,
> > > > > > sun
>
> > > > > > On Jan 28, 8:05 pm, wubbie <sunj...@gmail.com> wrote:
>
> > > > > > > Hi,
>
> > > > > > > I see
> > > > > > > (add-classpath (str "file://" (.getParent (java.io.File. *file*))
> > > > > > > "/"))
> > > > > > > in mire.clj.
> > > > > > > What value of *file* is it? I failed to see *file* is assigned at 
> > > > > > > all.
>
> > > > > > > -thanks
> > > > > > > sun
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to