Hi

2009/7/1 mmwaikar <mmwai...@gmail.com>:
> Hi,
>
> I am learning clojure these days, but on .Net. I have the following
> code -

I only have a tiny bit to add to what Daniel's already said.

[...]
> (defn GetSubfolderName [filename]
>        ((def name-wo-extn (Path/GetFileNameWithoutExtension filename))

First, def creates basically global variables (or something similar).
You want let instead.
Second, you can't just add parentheses as you see fit. :)

(def name-wo-extn "something")

is defining name-wo-extn as the string "something".

((def name-wo-extn "something"))

is trying to define name-wo-extn as the string "something" and then
call it as a function.  Since "something" is a String and not a
function (or something that acts as a function), this will fail.

So, for ((def name-wo-extn (Path/GetFileNameWithoutExtension
filename)) ...) implies that (Path/GetFileNameWithoutExtension
filename) returns a Clojure function (or something that can be used as
one, like a map/set/etc.).  I suppose Path/GetFileNameWithoutExtension
is a .Net method, in which case it is unlikely to work as a Clojure
function.  Java methods can't be used in place of Clojure functions
and I assume it's the same for the .Net port.

>         (def first-char (aget (.ToCharArray (.ToString name-wo-extn)) 0))
>         (if (Char/IsDigit first-char) (Convert/ToInt32 first-char) (if
> (starts-with-hmorx first-char) (.ToLower (.ToString first-char))
> "other"))))
>
> But when I call (GetSubfolderName "D:\\CsEx\\Manoj.cs"), I get this
> exception -
>
> System.InvalidCastException: Unable to cast object of type
> 'System.String' to type 'clojure.lang.IDeref'.

I think the extra parentheses are the reason for this exception.

>   at lambda_method(Closure , Object )
>   at AFunction_impl.invoke(Object )
>   at lambda_method(Closure , Object )
>   at AFunction_impl.invoke(Object )
>   at lambda_method(Closure )
>   at AFunction_impl.invoke()
>   at REPLCall(Closure )
[...]

-- 
Michael Wood <esiot...@gmail.com>

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