How do I call a class property?

53 views
Skip to first unread message

Aleksandar Simic

unread,
May 24, 2019, 3:42:33 AM5/24/19
to clojure-clr
Hello ClojureCLR users and developers!

First of all, thank you for your work on ClojureCLR.
It opens a whole new ecosystem and great opportunities for Clojure developer.
I've been playing with the project and I'm very excited about the possibilities.

While I've been able to make great headway in using some C# libraries, I'm coming
up against a minor issue:

how do I call a class property?


For example, I've tried this:

(ConfigureApp/Android)

and while that works just fine at the REPL, it complains when I try to
compile the program, with the error:

"System.InvalidOperationException: Unable to find static field: Android"

This is the documentation on the above class:

https://docs.microsoft.com/en-us/dotnet/api/xamarin.uitest.configureapp?view=xamarin-uitest-sdk


Looking at this email:

https://groups.google.com/d/msg/clojure/SxR_XzbUAUg/PJezCXTxYSgJ

it seems that:

"In essence, fields, properties and zero-arity methods are referenced in
the same way, and are checked in this order."


Am I right in thinking that the above class, ConfigureApp, tries to
look up a field and since it fails to find it, it bombs out?

What do I need to do in order to call it?


For completeness sake, here is how the code would be used in C#:

IApp app = ConfigureApp
    .Android
    .AppBundle("/path/to/my.app")
    .StartApp();

and here is what works at the REPL:


(-> ^IApp (ConfigureApp/Android)
   (.ApkFile "/path/to/my.app")
   (.StartApp 0))

The compilation command that I use, is invoked via lein-clr, as:

lein clr compile foo.core

which in turn runs:

/usr/local/bin/mono target/clr/clj/Release 4.0/Clojure.Compile.exe foo.core

The above executable and directory do exist.

Thank you
Alex

Aleksandar Simic

unread,
May 25, 2019, 4:09:05 AM5/25/19
to clojure-clr


On Friday, May 24, 2019 at 7:42:33 AM UTC, Aleksandar Simic wrote:

--- 8< --- snip ---- 8< ---

While I've been able to make great headway in using some C# libraries, I'm coming
up against a minor issue:

how do I call a class property?


For example, I've tried this:

(ConfigureApp/Android)

and while that works just fine at the REPL, it complains when I try to
compile the program, with the error:

"System.InvalidOperationException: Unable to find static field: Android"

This is the documentation on the above class:

https://docs.microsoft.com/en-us/dotnet/api/xamarin.uitest.configureapp?view=xamarin-uitest-sdk


As a workaround, I've done this:

(eval '(^IApp ConfigureApp/Android))

and that allows the program to compile.

I'm guessing that this is a dirty hack, so would love to hear from somebody
about the correct way to do it.

Thanks
Alex
Reply all
Reply to author
Forward
0 new messages