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:

> <snip.>
>
>
> 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
> <snip>
>

-- 
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.

Reply via email to