Thanks Alex!

I am beginning to move away from design by interface. Actually making
progress now.

Cheers,
Jack

On Sun, Jul 18, 2021 at 12:34 PM Alex Miller <alex.mil...@thinkrelevance.com>
wrote:

> definterface is generally considered a low-level tool in Clojure and
> typically Clojure developers do not create interfaces directly like this.
>
> The two primary means of function abstraction/polymorphism are
> multimethods (can dispatch on any aspect of any of the parameters to a
> function) and protocols (which dispatch on the type of the first parameter
> to the function). There are tradeoffs between these - the former is very
> flexible, the latter is very similar to interfaces (and does use them under
> the hood) so is limited to type-based dispatch but gets all the JVM
> performance of that operation.
>
> On Saturday, July 17, 2021 at 7:44:18 PM UTC-5 jack...@topicquests.org
> wrote:
>
>> Tanya,
>>
>> That did help, swapping  ie4clj.api.Inferrable for its import.
>> That, of course, got me into the next coding bug, about which I shall ask
>> next (I am attempting to use doseq to walk a list and AND its Inferrable
>> members)
>>
>> Meanwhile, I am truly surprised that you said
>>
>> I don't think it is the right way to use interfaces in clojure.
>>>
>> It's likely a result of dyslexia that I did not see that coming after
>> studying all the online banter about interfaces and protocols.. I chose
>> definterface because the examples showed how to specify the return values,
>> and programming by interface is how I do Java. I'd like to discover what,
>> precisely, to read and get past dyslexic events to learn how to use
>> interfaces.
>>
>> Many thanks
>> Jack
>>
>> On Sat, Jul 17, 2021 at 4:10 PM Tanya Moldovan <tanya.m...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> I don't think it is the right way to use interfaces in clojure. Take a
>>> look at  this
>>> <https://medium.com/@ujjawaldixit099/implementing-java-interfaces-in-clojure-3e5f0b80ba14>
>>>  and this
>>> <https://stackoverflow.com/questions/8614734/how-do-i-implement-a-java-interface-in-clojure/8615002>
>>> .
>>> You could create a java project with the interfaces you need and import
>>> that instead.
>>>
>>> I think the issue is that this setup requires AOT and it might be
>>> missing from your configuration.
>>> To fix it try adding this to project.clj file:
>>>
>>> :profiles {:dev {:aot [ie4clj.api]}}
>>>
>>> It can be tricky If you want to do lein uberjar and generate a jar file.
>>>
>>> Alternatively, you can use compile-files
>>> <https://clojuredocs.org/clojure.core/*compile-files*> (then you don't
>>> need import statement).
>>> (note that in your gist you had some errors when defining AndList, I've
>>> fixed it)
>>> (also take a look at the clojure style guide
>>> <https://github.com/bbatsov/clojure-style-guide>, as AndList is not
>>> really the way to name things in clojure )) )
>>>
>>> (ns ie4clj.api)
>>>
>>> (definterface Inferrable
>>>   (^boolean eval [])
>>>   (^boolean evalMembers [members]))
>>>
>>> (ns ie4clj.AndList)
>>>
>>> (when *compile-files*
>>>   (require 'ie4clj.api))
>>>
>>> (def AndList
>>>   (reify
>>>    ie4clj.api.Inferrable
>>>    (eval [_] true)
>>>    (evalMembers [_ m] true)))
>>>
>>> Hope this helps,
>>>
>>>
>>>
>>> On Sat, 17 Jul 2021 at 21:06, Jack Park <jack...@topicquests.org> wrote:
>>>
>>>> I created a gist
>>>> https://gist.github.com/KnowledgeGarden/39742ae9ae641f0d8facb31b288ece4c
>>>>
>>>> which explains a ClassNotFoundException when I am importing and
>>>> reifying a particular interface in another clj file.
>>>>
>>>> It's really baffling because, in the load order, core calls a test in a
>>>> test file - getting that to compile landed on the solution of an (:import
>>>> ...) statement; once that worked, then the code in that test calls another
>>>> file AndList.clj which happens to have several places where it reifies the
>>>> same interface. Except, with the same import statement, on that file, I get
>>>> the error.  Difficult to even find a decent StackOverflow because one such
>>>> StackOverflow appears to be very similar, and the suggested fix is what I
>>>> have now.
>>>>
>>>> Thanks in advance for ideas.
>>>> Jack
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send
>>>> an email to clojure+u...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/clojure/ffb09a94-5aa4-4600-8c9a-e0d00901df72n%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/clojure/ffb09a94-5aa4-4600-8c9a-e0d00901df72n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/clojure/CADBYUPvwWc0UqGZ-WdgtvAmkzH0RZ34_0EbbLs3QshFC2%2B3BGw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/clojure/CADBYUPvwWc0UqGZ-WdgtvAmkzH0RZ34_0EbbLs3QshFC2%2B3BGw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/5896bb81-7540-4116-baea-4d039db09d5dn%40googlegroups.com
> <https://groups.google.com/d/msgid/clojure/5896bb81-7540-4116-baea-4d039db09d5dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CAH6s0fxR-sr%2BUR8r%2B526Ht8E%2BAz8tTzaLbbZz8G9r5EUfk0DkA%40mail.gmail.com.

Reply via email to