Re: [Chicken-users] New Egg: miniKanren
Hallo, On 20/02/16 21:06, Jeremy Steward wrote: > Note to the mailing list: apologies for the really long email ahead. > If this is too long please let me know and I won't do it again. I also > assume some knowledge of the Reasoned Schemer / miniKanren for my > response below, so if you do not know either then the following > descriptions may be sparse. > I am sorry for the late reply. I just wanted to thank you for taking the time and effort to write such an informative email. It was much appreciated! Cheers, -- -alex http://unendli.ch/ ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] New Egg: miniKanren
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Note to the mailing list: apologies for the really long email ahead. If this is too long please let me know and I won't do it again. I also assume some knowledge of the Reasoned Schemer / miniKanren for my response below, so if you do not know either then the following descriptions may be sparse. Hi Alex, On 17/02/16 01:03 AM, Alex Silva wrote: | Sorry for veering off-topic, but: As someone who has read the | Reasoned Schemer, how would I go about learning this improved | language? No worries, I was also confused at first that the language had changed as much as it had. All things considered these aren't "large" changes but the style of code you write becomes very different on it's own as well. If you want a deep explanation of how things work internally, I can only suggest William Byrd's dissertation: Original: http://gradworks.umi.com/33/80/3380156.html Single-spaced: https://github.com/webyrd/dissertation-single-spaced Nonetheless, to adapt to the latest version of miniKanren, you only need to consider what I mentioned above in list form, since otherwise pretty much all semantics are the same. I'll try to break it down and go through it, if the mailing list will forgive me. | 1. condi no longer exists 2. conde now behaves like condi Basically, you just need to retrain yourself to think of using conde wherever you would use condi before. The main difference between these was more or less "how you search": whether you performed a depth first search along a single branch (old conde) or depth first search interleaved between branches (condi). Here's an example from The Reasoned Schemer that should (hopefully) illustrate what's gone on here: OLD MINIKANREN == ~(run 5 (q) ~ (conde ~((== #f q) alwayso) ~((== #t q) alwayso) ~(else fail)) ~ (== #t q)) This runs forever, because the first conde line succeeds, but the outer (== #t q) fails. Since alwayso will succeed an infinite number of times, conde will try again, the first line will succeed, the outer (== #t q) will fail, and so on and so on. Instead, they introduce condi, which doesn't test the same branch in order every time: ~(run 5 (q) ~ (condi ~((== #f q) alwayso) ~((== #t q) alwayso) ~(else fail)) ~ (== #t q)) Here condi will still fail on the first branch, but instead of trying the first branch again from scratch, will instead switch to the second branch. This will succeed, which gives you a result. This behaviour in general means that if an answer logically exists, miniKanren will find it and return it eventually. This means it has better termination guarantees, since the original conde just searches down the first branch forever. Instead consider the latest miniKanren LATEST MINIKANREN = ~(run 5 (q) ~ (conde ~((== #f q) alwayso) ~((== #t q) alwayso)) ~ (== #t q)) The extraneous else statement is removed, more on that below. However, this runs exactly like the condi version above. My understanding is that William Byrd found the stronger termination guarantees more useful in practice than the Prolog-like behaviour of searching a single branch again and again and again. **NOTE** As an aside, since condi is gone, so are all, alli, etc that were present in The Reasoned Schemer, as they are also no longer needed (their primary use was to implement condi, IIRC). | 3. else is removed as syntax from conde, conda, and condu At first this one bothered me too, but I sort of warmed up to it. It means you can't have an (else expr ...) branch in a conde, conda, or condu expression. This makes it a little different from Scheme's cond, however consider that "else" doesn't make much semantic sense in the context of logic/relational programming anyways. I mean, you're just performing a search down a set of branches in a conde expression, and unlike cond, the else branch of a conde expression doesn't mean that every other branch failed (this is implicit in cond, but in conde you'll find that may not be true). So instead of writing else branches, just write the expressions as you would normally for any other branch. As an example, consider the following (note I'm going to try and assume no other procedures are defined other than unification). Instead of: ~(define (appendo l s out) ~ (conde ~((== '() l) (== s out)) ~(else ~ (fresh (a d res) ~(== `(,a . ,d) l) ~(== `(,a . ,res) out) ~(appendo d s res) You could just write: ~(define (appendo l s out) ~ (conde ~((== '() l) (== s out)) ~((fresh (a d res) ~ (== `(,a . ,d) l) ~ (== `(,a . ,res) out) ~ (appendo d s res) Even in the old miniKanren, both of these would have worked the same. Adding "else" as syntax is kind of redundant and makes for visual noise. This is made somewhat worse by the
Re: [Chicken-users] New Egg: miniKanren
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hallo, On 16/02/16 21:30, Jeremy Steward wrote: > > The latest implementation of miniKanren (found > https://github.com/miniKanren/miniKanren) is unfortunately both > very different and incompatible with the language of the same name > used in The Reasoned Schemer. Although they are both similar, there > are some notable change s: > > 1. condi no longer exists 2. conde now behaves like condi (to > provide stronger termination guarantees) 3. else is removed as > syntax from conde, conda, and condu 4. the latest version > introduces disequality constraints (=/=) as well as some > type-constraint operators (absento, numero, symbolo, booleano). > Sorry for veering off-topic, but: As someone who has read the Reasoned Schemer, how would I go about learning this improved language? Thanks, - -- - -alex http://unendli.ch/ -BEGIN PGP SIGNATURE- Version: GnuPG v1 iQIcBAEBAgAGBQJWxCk3AAoJED2K1tOOAcTfGO4P/2zJ16VPxpdg65o4LFYZrnOK FROSpz0WVtz9YcedlKYBPiFguNbtIwqAgdEtb4oQ3smosyU9n4737/0fnbccRkjz Fl+yCv9GcjzkShf/BPRdmt6x4Z9FYOJi3BwBQOc/9WtpkN4/cbXxCn61huhky788 v1kyvkgdiL+5rDd9bc3tAS8YQQ/Aw4s/fnSnsJ9SgAtvf4KRXdL+rkPcXt0jtqK5 QzpqA/0SVNmGNWs+zk9JFjd2b3tHnabcQ6OG1+TEeaPux161weNgjtrL7d5Gc7lz xgzb44j6hCnSRIrGMsibTYvL4M5E8m/m5nFc/42OkQbURI/xvPaWyxSZQVkJv0vy A3NR4Oy6bcu2QK90iCEIgL8bW2r+Dah3k0yJJbeb/4rtlghf+oSmItq8EK8mdX1K MqHCDP/ReC4Yq8//s1uQa3MlNvNvosX76wUYb7oHiz6zJZy9Zt6CvM9e+Z3Vhh0D i6EF9JQNFXNe7IcPLZJB9Voqi+A4VqnteKNSYyAFWM0JNu/kpGNpk2wUaY7Dp6f+ idZNhAcvkH/lQ1xrVLrox5V4bf1BwGbM32FomaWgDge5YxcQLNImxusHirAWE5O5 67oqTo3Hn/0qSJYBIPPIVq3/FXbe3Pm/9McLL0BRViTTWw2hzldEuLiSHVP9iqcc kKjurIhAeZxfX9qmDz5k =ylSd -END PGP SIGNATURE- ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] New Egg: miniKanren
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Hello all, Hope you all find yourselves well. I am sending this today to announce the 1.0 release of the latest miniKanren implementation. There's a bit of history here, so I'll try to summarize. However, if you're interested in seeing the implementation use the following link: https://bitbucket.org/ThatGeoGuy/chicken-minikanren We already have the "Kanren" egg, which provides the old Kanren language as well as the miniKanren implementation from "The Reasoned Schemer" (Dan Friedman, William Byrd, Oleg Kiselyov, MIT Press.). While this egg is great for working through the examples in the book, it does not provide the latest implementation of the miniKanren language (as it has evolved over the years). The latest implementation of miniKanren (found https://github.com/miniKanren/miniKanren) is unfortunately both very different and incompatible with the language of the same name used in The Reasoned Schemer. Although they are both similar, there are some notable change s: 1. condi no longer exists 2. conde now behaves like condi (to provide stronger termination guarantees) 3. else is removed as syntax from conde, conda, and condu 4. the latest version introduces disequality constraints (=/=) as well as some type-constraint operators (absento, numero, symbolo, booleano). After some discussion with the current maintainer (Alex Shinn), we have both decided it is probably better to packaged the canonical implementation as a separate miniKanren egg, while he has agreed to rename the mini-kanren module in the "Kanren" egg to `reasoned-schemer` or some such. This means that people working through The Reasoned Schemer can still use the implementation that works with the book, while users coming from Clojure's core.logic or Racket's miniKanren implementation can still use all the facilities that they'll be used to in the latest version of the language. I would be happy to answer any questions if there are any. Mario, could this be added to the coop, or are there additional steps I must take first? Best regards, - -- Jeremy Steward -BEGIN PGP SIGNATURE- Version: GnuPG v2 iQIcBAEBCAAGBQJWw4bUAAoJEHVwwAZUeZnZ0p8QAKJH2MeT5E9vT2/2seuT0gex tbq8XFyzNWaKTUO9t97Dew4vcKLCKL9iFOZPep4OihAb3FskjfxqYSCQxTdgK0PC EBsDHNqaBdaZ7O3Olt9xLZ1MUb0cAtYsg1A2FHE6WPlPaT5tqGptOmcnJpRrSkx8 gnV5i5yCdwUxlaW8YXNOy8ZbJyuxF5DdGgBEirhkevyfYVDcYKcmAEf8WtXiXOS0 5VXYajS3LLyIGRi7TFo5sCBeqmd4rEKyNdF6eQK1Q9wGidA7Zh8Y469xqa/s03Y9 gccM8Njc9x7SId3TF7VQuIdKyfGNAY5pOKLPSTsEhzzB5tEEV7nJj4Jy7Ka+FgcU NWBEINnj46Bkxk0bVi3azddDf1W8p0K3K0Jo5X3z+O7ekeXA3MnKUOAyGk1+6Sfl fbDw2e7HhzYpgjaayWJ4Qb/aHq44uqBF/xtvUTBlGj9ZSrvwb8h8FzgpZulaW5+u 9yEtr5Qj7I/slW3u66ZpulzhkvgdJrzgg6OL/fsOcFvEI0vPUjMHxLA6AAO90ub+ IFcpGIf+kH2gmQHxs/nFE4CgrFm4J5DqaGb4+dRHkTmkfPFQFKauWYmFUxrOtFYl 1RZ4uzYZnYUgRCgsSnSHczrmLzlhDkj15X+xr+bNXNKxE6bFqVi8PD8tzdixtToK In3tGWjUAN82WEAE/sKp =5zJu -END PGP SIGNATURE- ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users