←back to thread

Learn Prolog Now

(lpn.swi-prolog.org)
205 points rramadass | 1 comments | | HN request time: 0s | source
Show context
zemptime ◴[] No.45902006[source]
I've recently started modeling some of my domains/potential code designs in Prolog. I'm not that advanced. I don't really know Prolog that well. But even just using a couple basic prolog patterns to implement a working spec in the 'prolog way' is *unbelievably* useful for shipping really clean code designs to replace hoary old chestnut code. (prolog -> ruby)
replies(1): >>45902088 #
ramses0 ◴[] No.45902088[source]
I keep wishing for "regex for prolog", ie: being able to (in an arbitrary language) express some functional bits in "prolog-ish", and then be able to ask/query against it.

    let prologBlob = new ProLog()
    prologBlob.add( "a => b" ).add( "b => c" )
    prologBlob.query( "a == c?" ) == True
(not exactly that, but hopefully you get the gist)

There's so much stuff regarding constraints, access control, relationship queries that could be expressed "simply" in prolog and being able to extract out those interior buts for further use in your more traditional programming language would be really helpful! (...at least in my imagination ;-)

replies(7): >>45902466 #>>45902575 #>>45902589 #>>45902735 #>>45903753 #>>45904363 #>>45904569 #
zemptime ◴[] No.45902466[source]
I've wished for the same kind of 'embed prolog in my ruby' for enumerating all possible cases, all invalid cases, etc in test suites. Interesting to know it's not just me!
replies(2): >>45902555 #>>45902588 #
dflock ◴[] No.45902588{3}[source]
There are a bunch of libraries that will do this - here's one example of a python one: https://github.com/yuce/pyswip - and a ruby one: https://github.com/preston/ruby-prolog
replies(1): >>45902772 #
1. zemptime ◴[] No.45902772{4}[source]
I did try ruby-prolog. The deeper issue is that its just not prolog. Writing in actual prolog affords a lot of clarity and concision which would be quite noisy in ruby-prolog. To me, the difference was stark enough it wasn't worth any convenience already being in ruby was worth.