Why does this core.logic program never terminate if you ask for too many results?

71 views
Skip to first unread message

Laurens Van Houtven

unread,
Oct 29, 2019, 7:06:54 PM10/29/19
to clo...@googlegroups.com
Hi,

I'm trying to divide a list into 3 lists such that (= my-list (concat a b c)). I guess you could say I'm writing concato :-)

(l/run n
  [a b c]
  (l/fresh [A B] ;; uppercase are internal accumulators
    (l/appendo a b A)
    (l/appendo A c B)
    (l/== B '(p q r s))))

... running this program with small n (let's say 5) works fine. Ask for more answers than there are (e.g. 20) and it ostensibly runs forever.

1. Why?
2. How do I fix that? (I've tried reordering the goals.)

thanks
lvh

Marc Limotte

unread,
Oct 31, 2019, 12:18:59 PM10/31/19
to clo...@googlegroups.com
At first glance, I'd guess that the empty list is causing your problem.  You can always come up with one more path (which may not create a unique solution, but a path to explore) that has one more empty list appended.


--
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/CAE_Hg6Z20Hy45myrkarywUCEVa%2B%3Dr8nf2TH2E0wSJe9n%2BQCjPA%40mail.gmail.com.

Satyam Ramawat

unread,
Oct 31, 2019, 12:24:05 PM10/31/19
to Clojure
On a very simple way, you can restrict by using if statement by crossing checking the count/length of the list, 
https://clojuredocs.org/clojure.core/if

Laurens Van Houtven

unread,
Oct 31, 2019, 12:28:53 PM10/31/19
to clo...@googlegroups.com
Satyam: you're suggesting limiting the answers asked from run, or something else?

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

Satyam Ramawat

unread,
Oct 31, 2019, 12:33:16 PM10/31/19
to clo...@googlegroups.com
I mean you can limit the answer according to need, by running into loop until end users value satisfy, will can be either 5,20 or N. so it will throw output according to run of a loop.

Laurens Van Houtven

unread,
Oct 31, 2019, 5:44:34 PM10/31/19
to clo...@googlegroups.com
I always need all of them. Figuring out how many that are combinatorially is surprisingly tricky!

Satyam Ramawat

unread,
Oct 31, 2019, 6:23:52 PM10/31/19
to clo...@googlegroups.com

Laurens,


Have you tried checking up to what extent it goes?



Laurens Van Houtven

unread,
Nov 1, 2019, 9:08:17 AM11/1/19
to clo...@googlegroups.com
Sure: I'm saying figuring out the formula from a handful of examples is tricky. But I can do that, and I already know Clojure has conditionals. I'm trying to learn something about how the logic engine works.

lvh

Satyam Ramawat

unread,
Nov 1, 2019, 2:11:08 PM11/1/19
to clo...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages