Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Oleksandr Shulgin
On Fri, Aug 14, 2020 at 7:51 AM Alexandre Almosni <
alexandre.almo...@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 itself
>

A 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

Regards,
--
Alex

On 14 Aug 2020, at 02:24, Jack Park  wrote:
>
> 
> 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
>
> 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 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/CACACo5SqECEzLU-4VBBvB8J6xdi%3DqRpoqLjR4urhq7TBiB3mXA%40mail.gmail.com.


Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Oleksandr Shulgin
On Fri, Aug 14, 2020 at 9:05 AM Oleksandr Shulgin <
oleksandr.shul...@zalando.de> wrote:

> On Fri, Aug 14, 2020 at 7:51 AM Alexandre Almosni <
> alexandre.almo...@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 itself
>>
>
> A 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
>

I came up with the following:

;; and-transducer with early termination:
 (defn xand [rf]
   (fn
 ([] (rf))
 ([res] (rf res))
 ([res inp] (if inp
  (rf res inp)
  (reduced inp)

;; reducing function implementing and:
  (defn andr
   ([] true)
   ([i] i)
   ([r i] (and r i)))

;; noisy variant of get:
 (defn noisy-get
  ([k]
   (fn [m]
 (noisy-get m k)))
  ([m k]
   (println "noisy-get" m k)
   (get m k)))

;; all in action:
user> (def xf (comp (map (noisy-get :data))
xand))
#'user/xf
user> (transduce xf andr [{:data 1} {:data false} {:no-data 3}])
noisy-get {:data 1} :data
noisy-get {:data false} :data
false
user> (transduce xf andr [{:data 1} {:data 2} {:no-data 3} {:data 4}])
noisy-get {:data 1} :data
noisy-get {:data 2} :data
noisy-get {:no-data 3} :data
nil
user> (transduce xf andr [{:data 1} {:data 2} {:data 3} {:data 4}])
noisy-get {:data 1} :data
noisy-get {:data 2} :data
noisy-get {:data 3} :data
noisy-get {:data 4} :data
4

It does feel a bit redundant to have the reducing function on top of a
transducer that accomplishes mostly the same, but I haven't found a way to
make it shorter.

Cheers,
--
Alex

> On 14 Aug 2020, at 02:24, Jack Park  wrote:
>>
>> 
>> 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
>>
>> 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 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/CACACo5TDpMg_CEhE2ytwZv9R1L3%3DifayFLYTs6KC80vON59hiw%40mail.gmail.com.


Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Jesús Gómez
Why not to Java-Interop with that Interface and those Classes directly, the
same way you use them in Java?

El jue., 13 ago. 2020 a las 22:54, Jack Park ()
escribió:

> 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
>
> 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.
>
> Many thanks in advance. -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/3e2ffc86-0e4f-4c0c-92c3-58e0848d5ba7o%40googlegroups.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
--- 
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/CAO9z-97N15E_17FRkDN_gbneXfkMkrS615RV5UwGMf3%2Bos%3DSLQ%40mail.gmail.com.


Re: Clojure tools-deps Docker image versions & stable releases

2020-08-14 Thread Wes Morgan
OK, thanks Alex!

The reversion to 1.10.1.561 for un-versioned tools-deps images (and the 
publishing of that tag at all) is now live on Docker Hub.

Stable releases only moving forward.

On Thursday, August 13, 2020 at 7:30:44 PM UTC-6 Alex Miller wrote:

> On Thursday, August 13, 2020 at 10:32:45 AM UTC-5 cap10...@gmail.com 
> wrote:
>
>> I was recently made aware in a separate thread in this group* that, until 
>> very recently, the tools-deps versions that were being installed via the 
>> main Homebrew tap's clojure installer included some versions considered 
>> unstable. As of the day I'm writing this, the latest stable version is 
>> 1.10.1.561.
>>
>> I had been updating the official clojure:tools-deps (& :latest since it 
>> includes all three build tools we support) Docker image when that Homebrew 
>> build updated, but am now planning to take steps to revert back to stable 
>> versions only.
>>
>> So, I have a couple of questions:
>>
>> 1. For Alex Miller or other Cognitect folks: What's the best place to 
>> monitor for new stable tools-deps releases (to trigger Docker image 
>> updates)? Are updates to Cognitect's clojure/tools/clojure Homebrew tap 
>> sufficient?
>>
>
> To answer the last question first, no - we update prerelease versions 
> there all the time and those generally shouldn't be used to build new 
> images (and sometimes there are manual changes too).
>
> For current stable version, you can watch either:
>
> https://github.com/clojure/homebrew-tools/blob/master/Formula/clojure.rb 
> (the actual formula) or
> https://github.com/clojure/brew-install/blob/1.10.1/stable.properties 
> (the data file)
>  
>
>> 2. Does anyone have a need for Docker images with unstable tools-deps 
>> versions? I'm not planning on building them unless the community has a need 
>> for them. If I do build them, they would be available under 
>> version-specific tags (e.g. clojure:tools-deps-1.10.1.619) but the 
>> clojure:tools-deps tag would get you the latest stable release.
>>
>
> I don't think it's relevant to have every one of them for sure. I 
> sometimes release multiple per day even. People might occasionally need a 
> prerelease version, don't know. I'm hoping not to make the gaps too large 
> between stable versions. The goal of the prereleases is really tire kicking 
> and feedback on imminent stuff, but don't I expect it to get too for off of 
> stable.
>  
>
>> It's also worth pointing out that the unstable versions we've already 
>> released won't disappear, so if you're using them, feel free to continue. 
>> If you want to ensure you stay on that version, be sure to specify it in 
>> your image tag (e.g. in the FROM line of your Dockerfile).
>>
>> * Classpath bug re Clojure 1.10.1.645 when using Figwheel.Main 
>> 
>>
>

-- 
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/59dd0431-26b1-4fd0-aec5-e8448ccd348bn%40googlegroups.com.


Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Jack Park
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 time
b) 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

On Fri, Aug 14, 2020 at 1:25 AM Oleksandr Shulgin <
oleksandr.shul...@zalando.de> wrote:

> On Fri, Aug 14, 2020 at 9:05 AM Oleksandr Shulgin <
> oleksandr.shul...@zalando.de> wrote:
>
>> On Fri, Aug 14, 2020 at 7:51 AM Alexandre Almosni <
>> alexandre.almo...@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 itself
>>>
>>
>> A 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
>>
>
> I came up with the following:
>
> ;; and-transducer with early termination:
>  (defn xand [rf]
>(fn
>  ([] (rf))
>  ([res] (rf res))
>  ([res inp] (if inp
>   (rf res inp)
>   (reduced inp)
>
> ;; reducing function implementing and:
>   (defn andr
>([] true)
>([i] i)
>([r i] (and r i)))
>
> ;; noisy variant of get:
>  (defn noisy-get
>   ([k]
>(fn [m]
>  (noisy-get m k)))
>   ([m k]
>(println "noisy-get" m k)
>(get m k)))
>
> ;; all in action:
> user> (def xf (comp (map (noisy-get :data))
> xand))
> #'user/xf
> user> (transduce xf andr [{:data 1} {:data false} {:no-data 3}])
> noisy-get {:data 1} :data
> noisy-get {:data false} :data
> false
> user> (transduce xf andr [{:data 1} {:data 2} {:no-data 3} {:data 4}])
> noisy-get {:data 1} :data
> noisy-get {:data 2} :data
> noisy-get {:no-data 3} :data
> nil
> user> (transduce xf andr [{:data 1} {:data 2} {:data 3} {:data 4}])
> noisy-get {:data 1} :data
> noisy-get {:data 2} :data
> noisy-get {:data 3} :data
> noisy-get {:data 4} :data
> 4
>
> It does feel a bit redundant to have the reducing function on top of a
> transducer that accomplishes mostly the same, but I haven't found a way to
> make it shorter.
>
> Cheers,
> --
> Alex
>
>> On 14 Aug 2020, at 02:24, Jack Park  wrote:
>>>
>>> 
>>> 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
>>>
>>> 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 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/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 clojure@googlegroups.com

Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Jack Park
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]
  ))
)

Meanwhile, I found this https://clojuredocs.org/clojure.core/proxy-super
which is now on the table to explore.

Many thanks
Jack

On Fri, Aug 14, 2020 at 3:41 AM Jesús Gómez  wrote:

> Why not to Java-Interop with that Interface and those Classes directly,
> the same way you use them in Java?
>
> El jue., 13 ago. 2020 a las 22:54, Jack Park ()
> escribió:
>
>> 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
>>
>> 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.
>>
>> Many thanks in advance. -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/3e2ffc86-0e4f-4c0c-92c3-58e0848d5ba7o%40googlegroups.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
> ---
> 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/CAO9z-97N15E_17FRkDN_gbneXfkMkrS615RV5UwGMf3%2Bos%3DSLQ%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 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/CAH6s0fxiGQiZ4gUgEs42ScKWmxhQDtEd_N8bfgcbr2TObu7gww%40mail.gmail.com.


RE: First post: how to mimic a Java List with types?

2020-08-14 Thread Sam Hahn
Jack - I'll call you :)  Cheers - Sam


 Original Message 
Subject: Re: First post: how to mimic a Java List with types?
From: Jack Park 
Date: Fri, August 14, 2020 11:34 am
To: clojure@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.JackOn Fri, Aug 14, 2020 at 1:25 AM Oleksandr Shulgin  wrote:On Fri, Aug 14, 2020 at 9:05 AM Oleksandr Shulgin  wrote:On Fri, Aug 14, 2020 at 7:51 AM Alexandre Almosni  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_terminationI came up with the following:;; and-transducer with early termination: (defn xand [rf]   (fn     ([] (rf))     ([res] (rf res))     ([res inp] (if inp                  (rf res inp)                  (reduced inp);; reducing function implementing and:  (defn andr   ([] true)   ([i] i)   ([r i] (and r i)));; noisy variant of get: (defn noisy-get  ([k]   (fn [m]     (noisy-get m k)))  ([m k]   (println "noisy-get" m k)   (get m k)));; all in action:user> (def xf (comp (map (noisy-get :data))                    xand))#'user/xfuser> (transduce xf andr [{:data 1} {:data false} {:no-data 3}])noisy-get {:data 1} :datanoisy-get {:data false} :datafalseuser> (transduce xf andr [{:data 1} {:data 2} {:no-data 3} {:data 4}])noisy-get {:data 1} :datanoisy-get {:data 2} :datanoisy-get {:no-data 3} :dataniluser> (transduce xf andr [{:data 1} {:data 2} {:data 3} {:data 4}])noisy-get {:data 1} :datanoisy-get {:data 2} :datanoisy-get {:data 3} :datanoisy-get {:data 4} :data4It does feel a bit redundant to have the reducing function on top of a transducer that accomplishes mostly the same, but I haven't found a way to make it shorter.Cheers,--AlexOn 14 Aug 2020, at 02:24, Jack Park  wrote: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.ArrayListSo, 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 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/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 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 

Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Oleksandr Shulgin
On Fri, Aug 14, 2020 at 8:44 PM Jack Park  wrote:

> 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]
>   ))
> )
>
> Meanwhile, I found this https://clojuredocs.org/clojure.core/proxy-super
> which is now on the table to explore.
>

Nevermind transducers: I've just realized that reduced can be used with the
normal reduce.  E.g. here's short-circuiting AND-reduction fn:

(defn andr
  ([] true)
  ([i] i)
  ([r i] (let [o (and r i)]
   (if o
 o
 (reduced o)

When it comes to the actual lists, it depends how you'd like to represent
them.  E.g. I could imagine something like the following can be a useful
notation:

[:and 1 2 [:or 3 4] 5]

or even more direct:

(quote (and 1 2 (or 3 4) 5))

If you really want an interface-like look and feel, then protocols might be
the right answer:

(defprotocol Evaluable
  (evaluate [this]))

(defrecord AndList [items]
  Evaluable
  (evaluate [this]
(reduce andr (:items this

user> (evaluate (->AndList [1 2 3]))
3
user> (evaluate (->AndList [1 false 3]))
false

To complete it, you'll need to add the OrList and sneak (map evaluate) in
the reduce call in both And- and OrList.

Cheers,
--
Alex

On Fri, Aug 14, 2020 at 3:41 AM Jesús Gómez  wrote:
>
>> Why not to Java-Interop with that Interface and those Classes directly,
>> the same way you use them in Java?
>>
>> El jue., 13 ago. 2020 a las 22:54, Jack Park ()
>> escribió:
>>
>>> 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
>>>
>>> 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.
>>>
>>> Many thanks in advance. -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/CACACo5Rj3U1CJdEy431j7EBpR4oOVccKoGtLjCRPdiKd%3DvgLTQ%40mail.gmail.com.


Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Jack Park
Wow!

I say that because that might be getting closer to what I have in mind but
still not there yet.
I'm really trying to develop a type which honors two interfaces, one for
the list object, and one for the IEvaluable object.

As a type, I invoke it, then add objects to it, then place it, as an
IEvaluable object inside another such collection. Perhaps it is the first -
root - which begins an and/or network of IEvaluable objects, some of which
are the workers which go outside and make computations before returning
their boolean.

But, I have been wandering down another rabbit hole, the one where I ignore
list comprehensions and proxy an ArrayList.

I have code which almost runs, but which is far from perfect.
I created a gist which exposes my current experiment - which is close, but
no cigars yet.

https://gist.github.com/KnowledgeGarden/004fd93a78e2238c878b585f158759f9

Thanks
Jack

On Fri, Aug 14, 2020 at 1:38 PM Oleksandr Shulgin <
oleksandr.shul...@zalando.de> wrote:

> On Fri, Aug 14, 2020 at 8:44 PM Jack Park 
> wrote:
>
>> 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]
>>   ))
>> )
>>
>> Meanwhile, I found this https://clojuredocs.org/clojure.core/proxy-super
>> which is now on the table to explore.
>>
>
> Nevermind transducers: I've just realized that reduced can be used with
> the normal reduce.  E.g. here's short-circuiting AND-reduction fn:
>
> (defn andr
>   ([] true)
>   ([i] i)
>   ([r i] (let [o (and r i)]
>(if o
>  o
>  (reduced o)
>
> When it comes to the actual lists, it depends how you'd like to represent
> them.  E.g. I could imagine something like the following can be a useful
> notation:
>
> [:and 1 2 [:or 3 4] 5]
>
> or even more direct:
>
> (quote (and 1 2 (or 3 4) 5))
>
> If you really want an interface-like look and feel, then protocols might
> be the right answer:
>
> (defprotocol Evaluable
>   (evaluate [this]))
>
> (defrecord AndList [items]
>   Evaluable
>   (evaluate [this]
> (reduce andr (:items this
>
> user> (evaluate (->AndList [1 2 3]))
> 3
> user> (evaluate (->AndList [1 false 3]))
> false
>
> To complete it, you'll need to add the OrList and sneak (map evaluate) in
> the reduce call in both And- and OrList.
>
> Cheers,
> --
> Alex
>
> On Fri, Aug 14, 2020 at 3:41 AM Jesús Gómez  wrote:
>>
>>> Why not to Java-Interop with that Interface and those Classes directly,
>>> the same way you use them in Java?
>>>
>>> El jue., 13 ago. 2020 a las 22:54, Jack Park ()
>>> escribió:
>>>
 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

 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.

 Many thanks in advance. -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/CACACo5Rj3U1CJdEy431j7EBpR4oOVccKoGtLjCRPdiKd%3DvgLTQ%40mail.gmail.com
> 
> .
>

-- 
You received this message beca

Re: First post: how to mimic a Java List with types?

2020-08-14 Thread Jack Park
Alex,

I plan to explore this idea.
Many thanks!

Jack

On Fri, Aug 14, 2020 at 1:38 PM Oleksandr Shulgin <
oleksandr.shul...@zalando.de> wrote:

> 
>
>
> Nevermind transducers: I've just realized that reduced can be used with
> the normal reduce.  E.g. here's short-circuiting AND-reduction fn:
>
> (defn andr
>   ([] true)
>   ([i] i)
>   ([r i] (let [o (and r i)]
>(if o
>  o
>  (reduced o)
>
> When it comes to the actual lists, it depends how you'd like to represent
> them.  E.g. I could imagine something like the following can be a useful
> notation:
>
> [:and 1 2 [:or 3 4] 5]
>
> or even more direct:
>
> (quote (and 1 2 (or 3 4) 5))
>
> If you really want an interface-like look and feel, then protocols might
> be the right answer:
>
> (defprotocol Evaluable
>   (evaluate [this]))
>
> (defrecord AndList [items]
>   Evaluable
>   (evaluate [this]
> (reduce andr (:items this
>
> user> (evaluate (->AndList [1 2 3]))
> 3
> user> (evaluate (->AndList [1 false 3]))
> false
>
> To complete it, you'll need to add the OrList and sneak (map evaluate) in
> the reduce call in both And- and OrList.
>
> Cheers,
> --
> Alex
> 
>

-- 
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/CAH6s0fwVA5zhAJVdUaEMZN%2BhzThM8XMU1VtEWcej3PogPmxoLg%40mail.gmail.com.


Re: First post: how to mimic a Java List with types?

2020-08-14 Thread matthew...@gmail.com


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. 
On Friday, August 14, 2020 at 4:27:19 PM UTC-5 jack...@topicquests.org 
wrote:

> Alex,
>
> I plan to explore this idea.
> Many thanks!
>
> Jack
>
> On Fri, Aug 14, 2020 at 1:38 PM Oleksandr Shulgin  
> wrote:
>
>> 
>>
>>
>> Nevermind transducers: I've just realized that reduced can be used with 
>> the normal reduce.  E.g. here's short-circuiting AND-reduction fn:
>>
>> (defn andr
>>   ([] true)
>>   ([i] i)
>>   ([r i] (let [o (and r i)]
>>(if o
>>  o
>>  (reduced o)
>>
>> When it comes to the actual lists, it depends how you'd like to represent 
>> them.  E.g. I could imagine something like the following can be a useful 
>> notation:
>>
>> [:and 1 2 [:or 3 4] 5]
>>
>> or even more direct:
>>
>> (quote (and 1 2 (or 3 4) 5))
>>
>> If you really want an interface-like look and feel, then protocols might 
>> be the right answer:
>>
>> (defprotocol Evaluable
>>   (evaluate [this]))
>>
>> (defrecord AndList [items]
>>   Evaluable
>>   (evaluate [this]
>> (reduce andr (:items this
>>
>> user> (evaluate (->AndList [1 2 3]))
>> 3
>> user> (evaluate (->AndList [1 false 3]))
>> false
>>
>> To complete it, you'll need to add the OrList and sneak (map evaluate) in 
>> the reduce call in both And- and OrList.
>>
>> Cheers,
>> --
>> Alex
>>
> 
>>
>

-- 
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/cfac729f-b8e4-4f95-94b0-78345d10f457n%40googlegroups.com.