6 ms·
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 u
by zemptime 10mo ago
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)
- ramses0 10mo agoI 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 ;-)
- zemptime 10mo agoI'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!
- naasking 10mo agoMaybe try a Ruby Kanren implementation: https://minikanren.org/ https://minikanren.org/ uKanren is conceptually small and simple, here's a Ruby implementation: https://github.com/jsl/ruby_ukanren https://github.com/jsl/ruby_ukanren
- dflock 10mo agoThere are a bunch of libraries that will do this - here's one example of a python one: https://github.com/yuce/pyswip https://github.com/yuce/pyswip - and a ruby one: https://github.com/preston/ruby-prolog https://github.com/preston/ruby-prolog
- zemptime 10mo agoI 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.
- dragonwriter 10mo agoPorolog might be more to your liking. https://www.rubydoc.info/gems/porolog#porolog-wiki https://www.rubydoc.info/gems/porolog#porolog-wiki
- dflock 10mo agoThere are a bunch of libraries that will do this - here's one example of a python one: https://github.com/yuce/pyswip https://github.com/yuce/pyswip - and a ruby one: https://github.com/preston/ruby-prolog https://github.com/preston/ruby-prolog
- ramses0 10mo agoThanks for the reference! `pyswip` is the closest I've seen so far: pl.consult("some-facts.pl") pl.assertz("new(fact)") while pl.Query(...).nextSolution(): print( X.value ) ...will definitely keep it in my back pocket!
- dragonwriter 10mo agopyswip is a one-way python-to-SWI-prolog interface; there's also a first-party (maintained as part of SWI-prolog), two-way one called janus-swi. https://pypi.org/project/janus-swi/ https://pypi.org/project/janus-swi/ https://www.swi-prolog.org/pldoc/man?section=janus-call-prolog https://www.swi-prolog.org/pldoc/man?section=janus-call-prol...
- dragonwriter 10mo agoWhile usually using native syntax rather than strings, somethign like that exists for most languages of any popularity (and many obscure ones), in the form of miniKanren implementations. https://minikanren.org/ https://minikanren.org/
- dragonwriter 10mo agoIf you really want something that takes Prolog strings instead (and want the full power of prolog), then there are bindings to prolog interpreters from many languages, and also SWI-Prolog specifically provides a fairly straightforward JSON-based server mode "Machine Query Interface" that should be fairly simple to interface with any language. https://www.swi-prolog.org/pldoc/man?section=mqi-overview https://www.swi-prolog.org/pldoc/man?section=mqi-overview
- svieira 10mo agoYou might be interested in Flix: https://play.flix.dev/?q=PQgECUFMBcFcCcB2BnUBDUBjA9gG15JtAJbaKjYBmolaRyAdAFAAmk1A5jAGJ3TIAKAJQAuUAGIA3qAAKaeJETQA8pQEBlaPGKIOAGlCbtuoQYCCiTJGTRs8VRq079hpydABfUAF4JkpqCBsvKKKmoARDLYALYADpAAnuEG4UZoAEbY4ULMQcEKSg7hAOKIaJCwyMmgkTHxSTkBQXIFYQK1cZDEaNUd9dm5zSGFEeqQAB5wVSlRnQ3MHkxMIMAQMAgo6Fh4BESk5FSg8LAEqLbbcbDQkOiW1rbwjKzsoFzQ4CfWwmJS+aEORmcBkBJnMdxsdgBbhcII4Qk8Pj8TUCFisEPsanGBgS8JEAFo-iMBFjQDjBijwQ8HCSAF64gmo+6QzHY0ygRnohwJAx0hZLFagADCdWwyGsoGgAAsbrR6LcWEdPsgDGhEAqcJdrmdpaBcJRYsw2NRomgdN9QABVRDEaCgAA6oAAksofMjQABHWCQeAJV48PiCNlvD6nYRuvJi3a24msmjwGLsynMmOk+EAHwAfKBYsZoLhEEwgA https://play.flix.dev/?q=PQgECUFMBcFcCcB2BnUBDUBjA9gG15JtAJb... is an embedded Datalog DB and query in a general-purpose programming language. More examples on https://flix.dev/ https://flix.dev/
- shawn_w 10mo agoYou can do that in Racket, with the Racklog library¹. There's also Datalog² and MiniKanren and probably some other logic languages available. [1] https://docs.racket-lang.org/racklog/index.html https://docs.racket-lang.org/racklog/index.html [2] https://docs.racket-lang.org/datalog/index.html https://docs.racket-lang.org/datalog/index.html
- jll29 10mo agoWhat you mean is not "regex for Prolog" but an embedded PROLOG interpreter, which exists. Ironically, the most common way I have seen people do this is use an embedded LISP interpreter, in which a small PROLOG is easily implemented. https://www.metalevel.at/lisprolog/ https://www.metalevel.at/lisprolog/ suggests Lisprolog (Here are some embedded LISPs: ECL, PicoLisp, tulisp) SWI-Prolog can also be linked against C/C++ code: https://stackoverflow.com/questions/65118493/is-there-any-reasonable-way-to-embed-a-prolog-interpreter-inside-of-a-c-program https://stackoverflow.com/questions/65118493/is-there-any-re... https://sourceforge.net/p/gprolog/code/ci/457f7b447c2b9e90a09956ff15fd277d269b1d98/tree/examples/ExamplesC/ https://sourceforge.net/p/gprolog/code/ci/457f7b447c2b9e90a0... Racklog is an embedded PROLOG for Racket (Scheme): https://docs.racket-lang.org/racklog/ https://docs.racket-lang.org/racklog/
- tejtm 10mo agoYou could try picat [0] https://picat-lang.org/ https://picat-lang.org/
- elxr 10mo agoI wonder if there's examples of whole product architectures done in Prolog, seems like an elegant solution if done right. I've been looking for a concise way to model full architectures of my various projects, without relying on having a typical markdown file. Which is separate from the actual types in the code. Which is separate from the deployment section of the docs.