Oh, so instead of trying to unroll my requirements into a bunch of
conditions, just make a single condition function that checks through
the list. That helps a lot!

Thanks!
Alex

On Sat, May 19, 2012 at 2:11 PM, Jason Jackson <jasonj...@gmail.com> wrote:
> Are you trying to see if a person meets multiple requirements? Here's how:
>
>
>
> (defrel grade person course g)
> (fact grade 'Bob 'Algebra 'B)
> (fact grade 'Bob 'Art 'C)
> (fact grade 'John 'Algebra 'A)
> (fact grade 'John 'Art 'A)
> (fact grade 'Ricky 'Algebra 'D)
> (fact grade 'Ricky 'Art 'A)
>
> (defn meets-requirements [person [k & nowledge]]
>   (if-let [{:keys [course g]} k]
>     (all
>      (grade person course g)
>      (meets-requirements person nowledge))
>     succeed))
>
>
> #_ (run* [person]
>      (meets-requirements
>       person
>       [{:course 'Algebra :g 'B}
>        {:course 'Art :g 'C}]))
>
>
> On Saturday, 19 May 2012 15:07:47 UTC-4, Alex Robbins wrote:
>>
>> Hmm, I didn't explain it very well. What if I had more knowledge?
>> Maybe I knew two grades sometimes. That could cut down on the list of
>> possible students (assuming there are more than the three in my
>> example).
>>
>> How could I write a function that worked for both of these cases?
>> (matches [{:course 'Algebra :g 'B}])
>> (matches [{:course 'Algebra :g 'B} {:course 'Art :g 'C}])
>>
>>
>> On Sat, May 19, 2012 at 2:02 PM, David Nolen <dnolen.li...@gmail.com>
>> wrote:
>> > I don't think you need to generate goals for something as
>> > straightforward as
>> > this:
>> >
>> > (defrel grade person course g)
>> > (fact grade 'Bob 'Algebra 'B)
>> > (fact grade 'Bob 'Art 'C)
>> > (fact grade 'John 'Algebra 'A)
>> > (fact grade 'John 'Art 'A)
>> > (fact grade 'Ricky 'Algebra 'D)
>> > (fact grade 'Ricky 'Art 'A)
>> >
>> > (defn matches [{:keys [course g]}]
>> >   (run* [q]
>> >     (fresh [p]
>> >       (grade p course g)
>> >       (== q [p course g]))))
>> >
>> > (matches {:course 'Algebra :g 'B})
>> >
>> > On Sat, May 19, 2012 at 2:12 PM, Alex Robbins
>> > <alexander.j.robb...@gmail.com> wrote:
>> >>
>> >> I'm just getting started with logic programming, and it is entirely
>> >> possible I'm just approaching this incorrectly.
>> >>
>> >> Is it possible to use dynamically generated goals in run* ?
>> >>
>> >> For example,
>> >>
>> >> (defrel grade person course g)
>> >> (fact grade 'Bob 'Algebra 'B)
>> >> (fact grade 'Bob 'Art 'C)
>> >> (fact grade 'John 'Algebra 'A)
>> >> (fact grade 'John 'Art 'A)
>> >> (fact grade 'Ricky 'Algebra 'D)
>> >> (fact grade 'Ricky 'Art 'A)
>> >>
>> >> (def knowledge
>> >>  {:course 'Algebra :g 'B})
>> >>
>> >> (defn generate-goals [knowledge]
>> >>  (map
>> >>    (fn [{:keys [course g]}] (list 'grade 'person course g))
>> >>    knowledge))
>> >>
>> >> I want to do something like this (but valid clojure):
>> >> (run* [person]
>> >>  ~@(generate-goals knowledge))
>> >>
>> >> It should give me back a list of people who match my current
>> >> knowledge. If I have more knowledge about the person, it will generate
>> >> more conditions, less knowledge fewer conditions. However, since run*
>> >> and run are macros, I can't apply them to a list. I can't splice in
>> >> because I'm not in a quotes list. Any ideas?
>> >>
>> >> Thanks!
>> >>
>> >> --
>> >> 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 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 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 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

Reply via email to