Cora and Alex, I think you are both hitting some nails on their heads. Yes, the java mentality creates a kind of flow and patterns which clearly do not apply to clojure (eliding jokes like "what must they be smoking").
In java, I can make a list structure and do whatever I want with it - *because it's not immutable*. Now that we're not in Kansas anymore, I must get over relying on changing variable objects at will, but then, declaring atoms seems to have its own issues. So, try to avoid those. "Let" declares its own context but it might be creating a result you want to return in the outer context - that crops up from time to time. So, where am I now? I really want to build a set of classes which, in a weak sense (the java way) of extending sequence to give it new behaviors. But, the lesson today is that I am trying to build a *class* which evals as if it is a method, so I must ditch those classes and migrate those behaviors to a collection of functions. That's the work in progress, and it includes ditching the api interface altogether. That's work in progress (painful but fun). I'll report back. It's strange - to me - that the issues I face are non-issues for others here, mostly because of my deep java biases. Thanks Jack On Sun, Jul 18, 2021 at 12:47 PM Cora Sutton <c...@sutton.me> wrote: > Oh! I just saw your post from earlier and Alex's response, I strongly > believe we have an XY problem here. In Clojure you most likely wouldn't use > interfaces like this. We can move this discussion over there since Alex has > kicked it off. > > On Sun, Jul 18, 2021 at 2:37 PM Cora Sutton <c...@sutton.me> wrote: > >> And for what it's worth, I haaaate how condescending that site ( >> https://xyproblem.info/) is. It could be so much kinder. >> >> On Sun, Jul 18, 2021 at 2:34 PM Cora Sutton <c...@sutton.me> wrote: >> >>> No worries! Deep Java experience is such a huge asset when it comes to >>> Clojure, there's nothing to be ashamed of! >>> >>> So, for reify, if I understand what you're attempting, I think you'd >>> have something like: >>> >>> (reify >>> ie4clj.api.Inferrable >>> (evalMembers [members] >>> (every? evalSelf members)))) >>> >>> Tha is, if evalSelf is really what you want there. >>> >>> But, Jack, and I mean this in the kindest way possible, do you think >>> it's possible we have an XY situation going on here? >>> https://xyproblem.info/ >>> >>> It's possible we're helping you solve the wrong thing and I'd love to be >>> sure we're pointing you down the best path possible. So, can I ask what >>> problem you're solving? Can you share more code somewhere, maybe in a >>> GitHub gist? >>> >>> I just worry that maybe you're solving a problem the "Java way" when >>> there's an easier way to go about it in the "Clojure way". >>> >>> Hope this is helpful! >>> Cora >>> >>> >>> On Sun, Jul 18, 2021 at 2:14 PM Jack Park <jackp...@topicquests.org> >>> wrote: >>> >>>> Thank you, Cora. That's awesome, and it opens new issues for me. Here >>>> is my revised code from your first level comment >>>> (defn AndList >>>> [members] >>>> (reify >>>> ie4clj.api.Inferrable >>>> (every? evalSelf members) >>>> >>>> )) >>>> Which opens new issues: >>>> >>>> - Right at "(reify" I get this error message >>>> >>>> Syntax error (IllegalArgumentException) compiling at >>>> (ie4clj/AndList.clj:8:3). >>>> Don't know how to create ISeq from: clojure.lang.Symbol >>>> It's as if the ability to reify an interface is not recognized >>>> Notice there is an interface call which, itself, is not :require'd >>>> evalSelf, which leads to >>>> >>>> - evalSelf is not recognized >>>> >>>> That one is beginning to suggest to me that I should, instead, not use >>>> an interface, but just write code which can use clojure's eval. >>>> But, I've been creating classes, not functions. If I modify my code >>>> such that the members sequence contains functions, then perhaps that would >>>> work. >>>> >>>> I confess, I'm saddled with a deep java experience. >>>> Your coaching is extremely helpful. >>>> Many thanks >>>> Jack >>>> >>>> On Sun, Jul 18, 2021 at 11:23 AM Cora Sutton <c...@sutton.me> wrote: >>>> >>>>> Hi Jack! >>>>> >>>>> I could be wrong but I think this could just be: (every? eval members) >>>>> >>>>> I see a few things here that seem strange to me so I wanted to share a >>>>> few points that might be helpful (or might not, let me know either way) >>>>> for >>>>> future code. >>>>> >>>>> * So typically you don't want to def or defn within another function >>>>> call since that will define a new value at the top level. >>>>> >>>>> (defn foo [] >>>>> (def bar 1) >>>>> (println (inc bar)) >>>>> >>>>> (foo) >>>>> ;; ^^ calling foo will define bar at the top level >>>>> >>>>> bar >>>>> ;; => 1 >>>>> ;; whoops, didn't mean to have that at the top level like that >>>>> ;; imagine if two different threads called that in parallel ::grimace:: >>>>> >>>>> Instead, you usually want to use the let function: >>>>> https://clojuredocs.org/clojure.core/let >>>>> >>>>> So in your code you might use this something like: >>>>> >>>>> (let [result (atom true)] >>>>> ....) >>>>> >>>>> The error you're seeing is from the (defn result ...) in your code, >>>>> you're missing the argument vector [] after result -- so it would >>>>> look like (defn result [] (atom true)) -- but you really don't want >>>>> to defn like that, I think. >>>>> >>>>> * To update an atom's value you don't want to assign like that, you >>>>> want to use swap! https://clojuredocs.org/clojure.core/swap! >>>>> >>>>> (swap! f >>>>> (fn [cur-val new-val] (and cur-val new-val)) >>>>> (eval member)) >>>>> >>>>> * You probably don't want to use an atom here. Atoms are usually for >>>>> data that you intend to have multiple threads accessing. In this case it's >>>>> just a value that changes during a single thread's execution here. >>>>> >>>>> How else could you solve this if not for the very convenient every? >>>>> function? There are a bunch of ways! Here are a few, with things written >>>>> out pretty explicitly so they're more clear. >>>>> >>>>> loop/recur: >>>>> >>>>> (loop [result true >>>>> remaining-members members] >>>>> (let [member (first remaining-members) >>>>> remaining-members (rest members) >>>>> new-result (eval member)] >>>>> (if new-result >>>>> (recur true remaining-members) >>>>> false))) >>>>> >>>>> reduce v1: >>>>> >>>>> (reduce (fn [result member] >>>>> (and result >>>>> (eval member))) >>>>> true >>>>> members) >>>>> >>>>> reduce v2.0, that will now stop iterating once one of the members >>>>> evals to false: >>>>> >>>>> (reduce (fn [_ member] >>>>> (or (eval member) >>>>> (reduced false))) >>>>> true >>>>> members) >>>>> >>>>> My point with sharing these is that in clojure usually the best way to >>>>> solve these problems is to pass new values to the next iteration while >>>>> accumulating a result instead of changing a variable on each iteration. Or >>>>> to use one of these sweet built-in functions. >>>>> >>>>> Does that make sense? >>>>> >>>>> * I thiiiiiiink you might not mean eval but I'm interested in what >>>>> kind of problem you're solving! :) >>>>> >>>>> Hope that helps! >>>>> Cora >>>>> >>>>> On Sun, Jul 18, 2021 at 12:41 PM Jack Park <jackp...@topicquests.org> >>>>> wrote: >>>>> >>>>>> I have a class which treats a sequence as a conjunctive list of >>>>>> objects which, when evaluated, return a boolean. It is an attempt to use >>>>>> doseq to walk along that list, evaluating each entry, and anding that >>>>>> result with boolean atom. It fails. A sketch of the code is this - taken >>>>>> from the error message: >>>>>> >>>>>> inside (defn AndList... >>>>>> >>>>>> (reify >>>>>> ie4clj.api.Inferrable >>>>>> (defn evalMembers >>>>>> [members] >>>>>> (defn result (atom true)) >>>>>> (doseq [x members] >>>>>> (result = (and result (eval x)))) >>>>>> (println (clojure.core/deref result)) >>>>>> (result))) - *failed: vector? at: [:fn-tail :arity-1 :params] >>>>>> spec: :clojure.core.specs.alpha/param-list* >>>>>> >>>>>> It could be that my Java background is clouding my use of clojure. >>>>>> Any comments will be appreciated. >>>>>> >>>>>> Thanks >>>>>> Jack >>>>>> >>>>>> -- >>>>>> 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/f67cfcd0-8e1e-4780-bc00-f6993979e7afn%40googlegroups.com >>>>>> <https://groups.google.com/d/msgid/clojure/f67cfcd0-8e1e-4780-bc00-f6993979e7afn%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/CAMZDCY3BWybiXzgoYaKK958z%2BWqTKf0o_5p9fq-huwutco9onw%40mail.gmail.com >>>>> <https://groups.google.com/d/msgid/clojure/CAMZDCY3BWybiXzgoYaKK958z%2BWqTKf0o_5p9fq-huwutco9onw%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/CAH6s0fywhEidRkLx8DytqEs5wtXOaFtULCkBWgW%2BRVpmSfQvjg%40mail.gmail.com >>>> <https://groups.google.com/d/msgid/clojure/CAH6s0fywhEidRkLx8DytqEs5wtXOaFtULCkBWgW%2BRVpmSfQvjg%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/CAMZDCY1wAQiG3MNdBCLy-1TiRprduMN7rWDmYE0MRvZ%3D_spYjA%40mail.gmail.com > <https://groups.google.com/d/msgid/clojure/CAMZDCY1wAQiG3MNdBCLy-1TiRprduMN7rWDmYE0MRvZ%3D_spYjA%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/CAH6s0fycXwBmfHdz3irnCxU03q71pMKsTX5GU5gY%2BUjY-HyePg%40mail.gmail.com.