FAQ
here's a part of my clojureoids-code:

(let [type-pred #()
bounds-check #()
contact #()
full-test (fn [element] (and (type-pred element) (bounds-check
element) (contact element)))]
(filter full-test (:game-elements @world-atom))

is there a way to write the full-test in a way that doesn't force me
to repeat the "function <constant text>" pattern inside the and?




--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Search Discussions

  • Timothy Baldridge at Nov 4, 2011 at 5:08 pm
    Using collections:

    (every? true? (map #(%1 %2) [func1 func2] (repeat common-argument)))

    where func1 func2 are your functions. and common-argument is the
    argument shared by them all.

    Or something like this:

    (every? true? (map #(%1 %2) [type-pred bounds-check contact] (repeat element)))

    Granted this won't be the fastest method in the world (macros would
    probably be better), as there's going to be a fair amount of object
    creation going on, and now instead of invoking 3 functions, we're
    invoking much more. But at least this code is readable, and fairly
    easy to understand.

    Timothy
    On Fri, Nov 4, 2011 at 11:51 AM, Dennis Haupt wrote:
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    here's a part of my clojureoids-code:

    (let [type-pred #()
    bounds-check #()
    contact #()
    full-test (fn [element] (and (type-pred element) (bounds-check
    element) (contact element)))]
    (filter full-test (:game-elements @world-atom))

    is there a way to write the full-test in a way that doesn't force me
    to repeat the "function <constant text>" pattern inside the and?




    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en


    --
    “One of the main causes of the fall of the Roman Empire was
    that–lacking zero–they had no way to indicate successful termination
    of their C programs.”
    (Robert Firth)

    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Benny Tsai at Nov 4, 2011 at 5:13 pm
    This is slightly shorter:

    full-test (fn [element] (every? #(% element) [type-pred bounds-check
    contact]))
    On Friday, November 4, 2011 10:51:43 AM UTC-6, HamsterofDeath wrote:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    here's a part of my clojureoids-code:

    (let [type-pred #()
    bounds-check #()
    contact #()
    full-test (fn [element] (and (type-pred element) (bounds-check
    element) (contact element)))]
    (filter full-test (:game-elements @world-atom))

    is there a way to write the full-test in a way that doesn't force me
    to repeat the "function <constant text>" pattern inside the and?



    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Paul Mooser at Nov 4, 2011 at 6:11 pm
    You could try using "every-pred" to combine your predicates, which I
    think would be equivalent:

    (let [full-test (every-pred type-pred bounds-check contact)]
    ...
    On Nov 4, 9:51 am, Dennis Haupt wrote:
    (let [type-pred #()
    bounds-check #()
    contact #()
    full-test (fn [element] (and (type-pred element) (bounds-check
    element) (contact element)))]
    (filter full-test (:game-elements @world-atom))

    is there a way to write the full-test in a way that doesn't force me
    to repeat the "function <constant text>" pattern inside the and?
    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Benny Tsai at Nov 4, 2011 at 7:32 pm
    Oh that is cool!
    On Friday, November 4, 2011 12:11:43 PM UTC-6, Paul Mooser wrote:

    You could try using "every-pred" to combine your predicates, which I
    think would be equivalent:

    (let [full-test (every-pred type-pred bounds-check contact)]
    ...
    On Nov 4, 9:51 am, Dennis Haupt wrote:
    (let [type-pred #()
    bounds-check #()
    contact #()
    full-test (fn [element] (and (type-pred element) (bounds-check
    element) (contact element)))]
    (filter full-test (:game-elements @world-atom))

    is there a way to write the full-test in a way that doesn't force me
    to repeat the "function <constant text>" pattern inside the and?
    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Dennis Haupt at Nov 4, 2011 at 8:46 pm
    my favorite :)
    thx

    Am 04.11.2011 20:32, schrieb Benny Tsai:
    Oh that is cool!

    On Friday, November 4, 2011 12:11:43 PM UTC-6, Paul Mooser wrote:

    You could try using "every-pred" to combine your predicates, which
    I think would be equivalent:

    (let [full-test (every-pred type-pred bounds-check contact)] ...
    On Nov 4, 9:51 am, Dennis Haupt wrote:
    (let [type-pred #() bounds-check #() contact #() full-test (fn
    [element] (and (type-pred element)
    (bounds-check
    element) (contact element)))] (filter full-test (:game-elements
    @world-atom))

    is there a way to write the full-test in a way that doesn't force
    me to repeat the "function <constant text>" pattern inside the
    and?
    -- 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+unsubscribe@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 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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupclojure @
categoriesclojure
postedNov 4, '11 at 4:51p
activeNov 4, '11 at 8:46p
posts6
users4
websiteclojure.org
irc#clojure

People

Translate

site design / logo © 2022 Grokbase