On 14 Aug 2020, at 02:24, Jack Park <jack...@topicquests.org> wrote:
--
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/3e2ffc86-0e4f-4c0c-92c3-58e0848d5ba7o%40googlegroups.com.
Maybe your objects could be defined by a map containing functions and objects.So exampleAndList = {:fn and, :coll [a b c]}And then eval goes through your objects recursively, using(def eval [o](apply (:fn o) (map eval (:coll o))))- with a special case that if o is not a map but say a Boolean you just return itself
On Fri, Aug 14, 2020 at 7:51 AM Alexandre Almosni <alexandr...@gmail.com> wrote:Maybe your objects could be defined by a map containing functions and objects.So exampleAndList = {:fn and, :coll [a b c]}And then eval goes through your objects recursively, using(def eval [o](apply (:fn o) (map eval (:coll o))))- with a special case that if o is not a map but say a Boolean you just return itselfA slight problem with that approach is that clojure.core/and is not a function, but a macro: the reason being is that it stops evaluating forms as soon as it hits a falsey value (similar for "or").A smart implementation of And/OrList would like to short-circuit as well I guess, so you'll need to express that somehow.Of the clojure.core library that property is satisfied by transducers: https://clojure.org/reference/transducers#_early_termination
--
--
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/CACACo5TDpMg_CEhE2ytwZv9R1L3%3DifayFLYTs6KC80vON59hiw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAO9z-97N15E_17FRkDN_gbneXfkMkrS615RV5UwGMf3%2Bos%3DSLQ%40mail.gmail.com.
-------- Original Message --------
Subject: Re: First post: how to mimic a Java List with types?
From: Jack Park <jack...@topicquests.org>
Date: Fri, August 14, 2020 11:34 am
To: clo...@googlegroups.com
Mapping and transducers seems appropriate, though I'm still wrapping my head around how to make this work.From the "class with functions" mindset, I need an ArrayList into which I can:a) add members to the list from time to timeb) run eval() on it; a conjunctive list will exit false on first false firing of any member, or default exit true otherwise; a disjunctive list will exit true on first true firing of a member, and default false.When I read the code here, I am not yet clear (sorry, it's on me, not the code) how to make such a "class-like" object.I am still exploring this avenue, as well as looking at java-interop or something about a proxy.Many thanks.
Jack
The problem:In Java, I have an interface IInferrable which is basically boolean eval();Any Java object which extends IInferrable, no matter what it is, will answer to eval() and return a boolean.The idea lies at the heart of an inference engine.But, I also define a class AndList which implements IInferrable and extends java.util.ArrayList<Inferrable>So, AndList, and its sibling OrList behave just like a List object, but also will answer to eval() by running the collection and dealing with what each element returns when it, too, is eval()'d.I'd really love to discover how to pull that off in Clojure.
--
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/CACACo5TDpMg_CEhE2ytwZv9R1L3%3DifayFLYTs6KC80vON59hiw%40mail.gmail.com.
--
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/CAH6s0fyqVFdbv0K3%2B5RA1xw0EU9VHVOJ_b%3DC34EG5igXqVWqhQ%40mail.gmail.com.
This idea shows up early in Clojure text books. This concept comes to mind rather quickly:(def and_list (ArrayList.)...)But, in the end it is an ArrayList which has an interface-defined behavior, e.g. boolean eval(); (from Java)Thus far, in a tiny VSCode project, I defined(definterface IEvaluable(^boolean runIt []))and defined a simple object which will return false and one which will return true. I'll use those to populate a conjunctive and a disjunctive list.Now I must define a list object which runs that interface.Still digging and experimenting, but, on the surface, this approach appears to be possible.From above, as a sketch:(def and_list (ArrayList.)IEvaluable(runIt [this]<some code to conditionally walk the list>)))Meanwhile, I found this https://clojuredocs.org/clojure.core/proxy-superwhich is now on the table to explore.
--
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/CACACo5Rj3U1CJdEy431j7EBpR4oOVccKoGtLjCRPdiKd%3DvgLTQ%40mail.gmail.com.
<snip.>
<snip>
Another option would be to do what Alex is suggesting and define and
as a function. Just because it’s a macro in clojure.core doesn’t mean you can’t write your own :)
(defn eval' [x]
(if (map? x)
(apply (:fn x) (:coll x))
x))
(defn and-list [& items]
(let [if? (fn [x] (if x true false))
and' (fn [& args] (every? if? args))]
{:fn and' :coll items}))
(eval' true) ;=> true
(eval' false) ;=> false
(eval' (and-list 1 2 3)) ;=> true
(eval' (and-list 1 2 3 false)) ;=> false
Ditto with or
.
--
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/cfac729f-b8e4-4f95-94b0-78345d10f457n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/5B42B3BC-E20D-446E-82EF-0D1BFC36DA5F%40assum.net.
Members in such lists can be either other evaluable lists, or they can be evaluable objects which perform computations
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAH6s0fxkuHFOnWkJxAOytk5xHpYNR0FxvT0aF7A-783kTa3UmQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAB_6y6GYJxQznBw8E6rxAjGoCvp9eh67OKuv2Z6v54FzA6-pRg%40mail.gmail.com.
Syntax error macroexpanding clojure.core/defn at (cljtest/core.clj:123:1).
- failed: vector? at: [:fn-tail :arity-1 :params] spec: :clojure.core.specs.alpha/param-list
- failed: (or (nil? %) (sequential? %)) at: [:fn-tail :arity-n :bodies] spec: :clojure.core.specs.alpha/params+body
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAB_6y6GYJxQznBw8E6rxAjGoCvp9eh67OKuv2Z6v54FzA6-pRg%40mail.gmail.com.