Hi,

Clojure doesn't read files. It reads, compiles and executes a stream of 
toplevel expressions. Hence the file is compilable, but not readable.

If you do not want to execute the forms contained in a file, you have to avoid 
any dynamic feature. In particular aliased keywords with :: since those can 
only be handled after the require is executed.

Sincerely
Meikel

-----Ursprüngliche Nachricht-----
Von: Jonas <jonas.enl...@gmail.com>
An: clojure@googlegroups.com
Gesendet: So, 11 Mrz 2012, 07:26:28 MEZ
Betreff: Compilable clojure program, but unreadable?

Hi

If I have the following short Clojure program:

    ;; unread.clj
    (require '[clojure.string :as s])
    (prn ::s/kwd)

The second form can't be read by the clojure reader:

    user=> (def reader (java.io.PushbackReader. (clojure.java.io/reader 
"unread.clj")))
    #'user/reader
    user=> (read reader)
    (require (quote [clojure.string :as s]))
    user=> (read reader)
    java.lang.Exception: Invalid token: ::s/kwd (NO_SOURCE_FILE:0)

But if I load the file, prior to reading it, it works fine:

    user=> (load-file "unread.clj")
    :clojure.string/kwd
    nil
    user=> (def reader (java.io.PushbackReader. (clojure.java.io/reader 
"unread.clj")))
    #'user/reader
    user=> (read reader)
    (require (quote [clojure.string :as s]))
    user=> (read reader)
    (prn :clojure.string/kwd)

Can anyone think of a way to read the file without loading/compiling it?

Thanks,
Jonas

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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