ns :import / reflection

2012-02-20 Thread ClusterCat

Hello,
I have two newbie questions:

First
-
(ns test (:import (java.io File)))

I can use File like this
(let [file (File. filename)])))

When using this import
(ns test (:import (java.io.File)))

I get an "Unable to resolve classname: File" which I don't understand.


Second
--
With this small piece of code
(ns test
  (:import (java.io File)))
(set! *warn-on-reflection* true)

(if (nil? *command-line-args*)
  (println "No command line arguments given.")
  (let [filename (first *command-line-args*)]
(println filename)
(let [file (File. filename)])))


I get an
"Reflection warning, X:\workspace\ClojureTest\bin\test.clj:9 - call to 
java.io.File ctor can't be resolved."

which I also don't understand.


Thanks in advance,
Marcel

--
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


"-function" special?

2012-02-25 Thread ClusterCat

Hi there,

in some clojure examples I see function names with a leading dash like
-main()
-getFoo() (in backing bean)
-setBar() (in backing bean)

Are these functions with leading dash anything special? Or is this dash 
required for some interop?

I didn't find any documentation about it.

Thanks in advance,
Marcel

--
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


Re: ns :import / reflection

2012-02-25 Thread ClusterCat

Yes, that did the trick.
Thank you.


Am 21.02.2012 02:53, schrieb Sean Corfield:

On Sat, Feb 18, 2012 at 1:29 PM, ClusterCat  wrote:

(ns test (:import (java.io File)))


This says import the File class from the package java.io


(ns test (:import (java.io.File)))


Try:

(ns test (:import java.io.File))


  (let [filename (first *command-line-args*)]
(println filename)
(let [file (File. filename)])))


I get an
"Reflection warning, X:\workspace\ClojureTest\bin\test.clj:9 - call to
java.io.File ctor can't be resolved."
which I also don't understand.


Clojure relies on type hints to avoid reflection - introspecting Java
class types to figure out calls. If you add ^String in let binding for
filename, it should remove the warning:

(let [^String filename (first *command-line-args*)] ...

HTH?


--
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


function order

2012-04-02 Thread ClusterCat
In search for a Clojure bencode implentation, I found the following 
source code.


(defn- decode-list [stream]
  (loop [result []]
(let [c (char (.read stream))]
  (if (= c \e)
result
(recur (conj result (decode stream (int c

(defn decode [stream & i]
  (let [indicator (if (nil? i) (.read stream) (first i))]
(cond
 (and (>= indicator 48)
  (<= indicator 57)) (decode-string stream indicator)
  (= (char indicator) \i) (decode-number stream \e)
  (= (char indicator) \l) (decode-list stream)
  (= (char indicator) \d) (decode-map stream

(taken from 
http://nakkaya.com/2009/11/02/decoding-bencoded-streams-in-clojure/)




The example functions do not work for me, because decode tries to call 
decode-list which tries to call decode.

This leads me to the following questions:
1. What is the (technical) reason the compiler can't just "look up" all 
functions before using them?

2. What is the standard way or best practice to work around such constructs?


Greetings,
Marcel

--
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