10 ms·
Scryer Prolog: A modern Prolog implementation written mostly in Rust
- codetrotter 5y agoI was hoping that this would allow one to use the underlying libraries and algorithms directly from Rust, without using Prolog syntax, and that the Prolog syntax part was sitting on top of everything else. But it looks like this implementation consists of a parser written in Rust and then pretty much everything else looks to be written in Prolog itself.
- triska 5y agoScryer Prolog does delegate a lot of the work to Rust libraries and crates. For example, see the cryptographic functionality from library(crypto): https://github.com/mthom/scryer-prolog/blob/master/src/lib/crypto.pl https://github.com/mthom/scryer-prolog/blob/master/src/lib/c... Note that many of these predicates are only wrappers for internal implementations that use the Rust crates. In fact, these existing Rust crates (notably ring) made it especially easy and convenient to add this functionality. library(sgml) is another example of this approach: https://github.com/mthom/scryer-prolog/blob/master/src/lib/sgml.pl https://github.com/mthom/scryer-prolog/blob/master/src/lib/s... On a general note, it is often an advantage to implement functionality in Prolog, because it helps to improve robustness and efficiency of the underlying engine, and makes changes easier.
- moffkalast 5y agoRust is like the graphene of programming languages. So many articles of people doing something profound with it, it is supposedly better than all the rest in every way, but it still can't leave the "lab". Has anyone actually replaced one of the major ones (i.e. Java, C++, Node, C#) in a large production project with it yet? What's holding people back?
- willbw 5y agoI have only briefly dabbled in Rust so I might be mistaken here - it seems hard to replace the major languages when there is so much tooling (ides, profiling tools) and such a developed ecosystem with the incumbent languages. C#, Java and Node are also a lot easier to write than Rust in my opinion. C++ is what it should replace, except it’s not clear that Rust is as fast for performance-oriented applications, and if that’s what you care about and c++ has a greater ecosystem… maybe it’s a hard sell. Though I would say it’s easier that C++ to deal with and would expect this would help it win a larger share in systems programming. Eventually
- adwn 5y ago> C++ is what it should replace, except it’s not clear that Rust is as fast for performance-oriented applications I don't think that's true, at least not in a way that matters in practice. Sure, from time to time there's an article about a micro-benchmark in which carefully optimized C++ is 10% faster than carefully optimized Rust. Well, my users don't run micro-benchmarks, they run applications, and with Rust it's much easier and faster to experiment with macro-scale optimizations, which have a real impact on performance. Case in point, recently I took a single-threaded CLI program and made it multi-threaded by spawning some threads and adding a work queue. There, instant 300% speedup, just add water. Yes, I could have done the same with C++, but it would have taken much longer to make sure I didn't introduce some concurrency bug in my code – and only on the condition that the libraries I was using could be used from multiple threads simultaneously, which is far from certain in the C and C++ ecosystems.
- froh 5y agoWould the Firefox migration of parts to rust count as "leaving the lab"? If not so: what's your criterion? https://4e6.github.io/firefox-lang-stats/ https://4e6.github.io/firefox-lang-stats/
- adwn 5y ago> but it still can't leave the "lab" What makes you think this is the case? That's not my impression at all (for reference, I develop software in Rust professionally).
- dthul 5y agoI agree. I use software written (at least partially) in Rust all day every day and it's only getting more. Obvious examples include Firefox, ripgrep (which powers VSCode's search) or librsvg which renders SVG images in Gnome.
- sidkshatriya 5y agoThe firecracker VMM ( https://firecracker-microvm.github.io/ https://firecracker-microvm.github.io/ ) is an example of a Rust project that has truly left the lab. I believe Firecracker powers significant aspects of AWS lambda.
- mark_l_watson 5y agoNice project, good to see it appear occasionally on HN. For me, SWI Prolog has always been the elephant in the room because there is a ton of good software written in SWI. That said, since it is such an ancient system (but still under active development and supported), I am not surprised if there isn’t cruft/technical debt in its implementation.
- dejj 5y agoDoes Scryer have: - FFI to C or Java - “unique”, i.e. linear type declarations - modes, i.e. data-flow direction-dependent overloading of predicates These are my favorite features in Mercury Prolog [1], and I would be delighted to find them in Scryer too. [1] http://mercurylang.org/ http://mercurylang.org/
- mthom 5y agoNo FFI yet, no. I'll first try to adapt LispWork's Foreign Language Interface by writing a compatibility layer for Rust. If that goes well, I'll begin to explore writing a Common Lisp FFI to Scryer, which may give insights on how to interface Scryer to languages like C and Java.
- triska 5y agoAs a contributor to Scryer Prolog (I designed the logo!), I find this project to be one of the most exciting current developments in the logic programming community, and one of the most promising new Prolog systems in many years. Notably, Scryer Prolog is currently the only free Prolog system that aims for full conformance to the Prolog ISO standard, supports constraints such as dif/2, CLP(B) and CLP(ℤ), includes the most recent declarative features such as if_/3 and and the ..._si/1 family of predicates, provides support for sound unification and an alternative execution strategy called SLG resolution, and also implements a very efficient internal representation of lists of characters and partial strings, thus making it the first Prolog system in decades with the potential to efficiently support the use case Prolog was developed for: efficient and convenient text processing. On top of this, it is the first Prolog system ever implemented in Rust, making it especially exciting for fans of this language while also benefiting from many of its innovations. Here are a few interesting applications of Scryer Prolog: The precautionary package by David C. Norris, using Scryer Prolog for safety analysis of phase 1 dose-escalation trials in clinical oncology: https://github.com/dcnorris/precautionary https://github.com/dcnorris/precautionary A Prolog library to connect to PostgreSQL databases by Adrián Arroyo Calle: https://github.com/aarroyoc/postgresql-prolog https://github.com/aarroyoc/postgresql-prolog The Retina chainer, targeting EYE Reasoning via Scryer and Trealla by Jos de Roo: https://josd.github.io/retina/ https://josd.github.io/retina/ Thank you Mark and everyone who contributed for all your work on Scryer Prolog, keep up the great work! Some of these innovations have already spread to other Prolog systems, such as Trealla and Tau Prolog, and I hope that Scryer serves as an inspiration for many more systems. Exciting times ahead! Regarding the name of the project: "Scrying" is the practice of looking into a suitable medium in the hope of detecting significant messages or visions: https://en.wikipedia.org/wiki/Scrying https://en.wikipedia.org/wiki/Scrying What a fitting name for a Prolog system!
- nitrix 5y agoI ask this as a completely outsider to Prolog who has found some of the design choices in SWI-Prolog to be very arbitrary while I was trying to learn it. Some predicates were rather unsafe/error prone/not pure and didn't sit quite right with me. Is that a result of the Standard and will Scryer follow those footsteps or are we going to see something closer to Mercury? I really enjoy your channel and indirectly heard a lot of positive things about Scryer, so of course I'm super interested and would prefer if they don't get too stuck on trying to meet the "status quo". The "status quo" has a lot of room for improvement.
- iddan 5y agoIs someone working on a more modern syntax to Prolog? like how ReasonML is for OCaml but for Prolog
- xvilka 5y agoReasonML is not a modern syntax for OCaml, it's just JavaScript-like syntax. Nothing modern about it. Notably, latest OCaml versions have more modern syntax - some additional sugar, shorter monadic binding syntaxes, upcoming special syntax for effects, and many other small things that compound in overall better experience.
- agumonkey 5y agoWhat would you wish to see changed ?
- horsh1 5y agoLess repetitions. Instead of roo(X, W) :- zut(X, Z), pum(Z, Y), tos(Y, W) we could write something like roo/2 :- zut . pum . tos
- triska 5y agoYou can do this with definite clause grammars (DCGs), which are available in virtually all Prolog systems: roo --> zut, pum, tos. Note the use of (-->)/2 to define a grammar rule. Use phrase/3 to invoke the DCG. DCGs are currently being drafted for inclusion in the Prolog ISO standard: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/#dcg https://www.complang.tuwien.ac.at/ulrich/iso-prolog/#dcg
- lrem 5y agoAre there some corners of the industry where Prolog is beneficial? Or is this mostly an academic endeavour?
- tcoff91 5y agoOne big usage in industry of prolog is in airline logistics software.
- tunnuz 5y agoWhat’s the main reason for that?
- mjul 5y agoHistorically, airlines had a lot of computing power. In Jim Grays 1984 article about getting to "1000 transactions per second" (TPS), an "ordinary" system ran at 50 TPS and airlines were pushing above 800 TPS. So, they had capacity and competence. Second, airlines are expensive beasts to run so solving hard problems is worth a lot of money. Third, there are a lot of rules in aviation that suit themselves nicely to combinatorial optimisation. Think crew scheduling: if there is a delay on an inbound flight the crew may not be allowed to fly the aircraft on its next leg since they would exceed their maximum working hours for the day. But then you need to find another crew and a good rescheduling to perhaps a shorter or earlier flight for the original crew. And then you have to think about rescheduling passengers to their connecting flights or holding those flights back a bit to allow the passengers to make the connection. And you have twenty minutes to do it before they land. Handling these "catastrophes" pop up again and again in the daily operations and are well suited for the kind of combinatorial search provided by logic programming in combination with optimisation engines. There are specialist companies in this area. For example, PDC's Turbo Prolog and Visual Prolog products have been used extensively in aviation since the 90s.
- capableweb 5y agoYes, every (type of) language has it's corner, no language is best for absolutely everything. Since Prolog is a logic-based and declarative programming language, if you're dealing with goal reduction or backwards chaining, then Prolog is a excellent fit and will probably be easier to both write and maintain compared to other languages. Theorem proving, automated scheduling and querying data stores are also excellent use cases for Prolog and Prolog-like languages.
- mjul 5y agoLogic programming is extremely powerful in offering the option to essentially run your program in reverse, asking “given this output, which inputs would cause that?” Even if you don’t use it as your principal application language it is a great addition to the development toolbox. Running in reverse is great for testing, where you can generate test cases that hit interesting variant flows. For example, I have used it to generate input pension payout requests that would hit the interesting special cases for the bespoke bookkeeping rules for each tenant or subsidiary like “for X, the third dimension is always 930, but for Y they have 930 or 931, but then the fourth dimension is 4,6 or 10 depending on the historical subsidiary of the account origin…” Another great use of logic programming in the daily toolbox is with respect to compliance documentation where you want to document and verify how data points flow across systems or the variables going into aggregates calculated on the way. This allows you to answer questions like, “our provider for X data delivered bad data for last month, which customer transactions may have been impacted?”, or “this value looks wrong, where did it come from?” It also allows you to generate exact documentation for this, or even checking the model vs the actual APIs, schemas or data flow or change notifications.
- MrBuddyCasino 5y agoI have no experience with either one, but isn’t this essentially what a SAT solver does? Is there a difference?
- harperlee 5y agoIn SAT you are using propositional logic (“0th order” logic), whereas in prolog normally* you use predicate logic (1st order logic) so you can use existential and universal quentifiers, use variables, etc. * There’s also lambda prolog which enables higher order logic (set logic).
- mynameisash 5y ago> This allows you to answer questions like, ... I hadn't considered that. I've always done bespoke analyses for this. Do you have any suggestions for a practical intro for someone that wants to add Prolog to their toolbox? I'd love to learn not just how to use it but also how to know when to use it.
- JoshTriplett 5y agoThere's also a Datalog implementation at https://github.com/rust-lang/datafrog https://github.com/rust-lang/datafrog . The Polonius reimplementation of the Rust borrowchecker uses Datafrog: https://github.com/rust-lang/polonius/ https://github.com/rust-lang/polonius/
- leandot 5y agoCould someone knowledgable in the topic explain in simple terms what can be done in Prolog and not in other mainstream languages? Thanks.
- alfiedotwtf 5y agoMost languages we use these days are imperative - we tell the compiler the steps to take in order to complete a goal. Prolog is a declarative, logic language - we tell the compiler what the goal is, and the compiler works out the steps to take in order to complete that goal.
- triska 5y agoAs I see it, the most striking feature of Prolog that sets it apart from all other languages, mainstream or not, is its ability to write concise meta-interpreters in it. A Prolog meta-interpreter is a Prolog program that interprets Prolog programs. With this facility, you can dynamically extend your programs, by reading code and executing it as if it were part of the original program. But not only that, you can also reason about it, and execute it in different ways than a regular Prolog engine would do it. You can analyze it, and execute only safe parts. You can remove fragments, and show explanations why specific phenomena occur. You can debug it declaratively by constructing generalizations and specializations. You can add features to the language that are not present in its actual implementation, but only in the programs you interpret. No other programming language provides this ability to such an extreme extent as Prolog. For example, how much C++ code would it take to write an interpreter for a sensible subset of C++? How much Lisp code would it take to interpret the most essential aspects of Lisp? It takes only 3 lines of Prolog code to interpret the essence of Prolog. Most programmers may currently not "miss" this ability, because what they think of when they think of a "program" is in comparison quite static: The idea that they could interpret external code dynamically as part of their programs is alien to them because the languages they are using either does not allow it, or only allows it in a sense "blindly", by not truly looking into the code and interpreting it in flexible ways, or by making the analysis of given code too hard. Yet, the ability to conveniently adapt and augment the logic of an existing program is a fundamental necessity for truly general and flexible programs that must dynamically take into account changing requirements.
- oolonthegreat 5y agoI have no idea how people solve constraint problems without prolog and clpfd/z. these types of problems seem to be everywhere, and yet prolog still has a very small user base, how come?
- sidkshatriya 5y agoA lot of constraint problems can be solved by SAT/SMT solvers. Many other problems can be solved via Linear/Integer Programming Algorithms. Then are large fields of Combinatorics, Operations Research and Graph Theory with many other kinds of Algorithms. Prolog uses backtracking search. Backtracking search is quite a good and generic approach. Its not the only approach. Depending on your problem space you can probably totally avoid Prolog.
- AlexanderTheGr8 5y agoCan you give me any real life examples where we see constraint problems? I thought that it was a purely academic thing.
- ibejoeb 5y agoUI Layout
- all2 5y agoAny kind of multi-component mechanical modeling will require the use of constraints. Single components in mechanical modeling literally use dimensional constraints.
- gneray 5y agoAuthorization is one use case, e.g., "Can this user do this thing given these constraints?" or even "Show me all the things this user can do given these constraints" Our team is solving for this use case. While we focus a lot on abstractions, APIs, etc. that are appropriate for our use case, under the hood everything is driven by an embeddable logic language that we write in Rust, called Polar: https://docs.osohq.com/reference/polar.html https://docs.osohq.com/reference/polar.html
- 5y ago
- syntaxfree 5y agoI use Rust a little these days but still find the “wizzgrep just like grep but in mother-frakking (party horn) ruuuuuust” off-putting. I think advertising the language is useful in two contexts only. - it’s JavaScript (so available on the client end) - it’s a library FOR x_lang. I mean — a mini-kanren written in Prolog would be droll, as would a REST API framework for NetLogo, but anything that’s useful is useful.
- option_greek 5y agoAdding "using library X or language Y" helps in discovering the content during future searches. It also drives people to checkout the code to see if some parts are reusable. There is nothing wrong with mentioning the language and I'm happy to see submissions for other languages and frameworks also mention this these days (Go submissions are really interesting). It helps discover use cases that you might not have thought possible in that language or framework. Compiling prolog to abstract code and running it on a VM written in Rust? Yeah its probably close to the language's target use cases of Rust but it lets people see if such functionality is reusable as a library (in this case found out its not) and how its implemented. I don't know what's with all the Rust hate these days. It's just another language nothing to get fired up about a tag line appended to the title.
- AYBABTME 5y agoI'm not super versed in Rust and the readme didn't seem to mention: can this be used as a pure library/package, i.e embedded in a Rust host program and used to execute arbitrary code in isolation?
- coliveira 5y agoIs there any comparison in terms of performance between this implementation and SWI-Prolog?
- anshul 5y agoOne of the more interesting real world places where I have seen prolog being used is yarn v2. In your yarn workspaces monorepo, you can define the constraints between your package.jsons as a prolog script[1]. It's quite impressive and fast. It can auto fix all your package.jsons too and is quite fast at it! Being completely new to prolog, I couldn't figure out how to write a not member of list predicate that would work but other than it saved me a days worth of work! [1] https://yarnpkg.com/cli/constraints https://yarnpkg.com/cli/constraints
- nestorD 5y agoDoes anyone know a good Prolog course / introduction that focuses on exercices? I would be interested in becoming used to identify problems that can be solved with Prolog.
- gneray 5y agoI recall Annie Ogborn having some good resources. Here's one I just found when looking around: https://www.oreilly.com/library/view/oscon-2014-complete/9781491910795/oreillyvideos2098535.html https://www.oreilly.com/library/view/oscon-2014-complete/978...
- kkjjkgjjgg 5y agoNever got around to learning Prolog, even though I was always interested. what would be a good excuse to do so now?
- mikelevins 5y agoWriting a compiler or a rules engine are fairly obvious use cases. If you have occasion to implement a simple version of either of those kinds of things, it should be a pretty decent excuse to learn some Prolog.
- tlack 5y agoI've identified many cases in my employer's codebase that are something like: items = fetch_list_from_db() for item in items: if item.match(param): .. elif item.whatever > param2 || item.override: .. else: some_default_behavior() return custom_sort_thing(results) In each instance, the logic is critical to business function and frequently evolving, but often underspecified, hard to audit, and each case has its own little missing features. Prolog allows me to very easily state these rules in a way others can understand at a glance and keep them separate from the operational code. Best of it all, it solves for all possible answers (or all inputs for a given answer) without implicitly stating very much looping or recursion - even less so than functional languages in some cases.
- jlg23 5y agoI prototype business logic in prolog by turning client requirements into predicates. This allows me to formalize their prose and to verify I understand it correctly by asking the client for expected results for a given input/scenario. These programs never make it to production, though; I rather see them as a shadow spec. EDIT: IMHO one should learn it just to get introduced into the mindset of declarative programming. You can implement a sufficiently fast and complete prolog easily in any language if that allows for a clearer solution to a specific problem than explicit specification of control flow.
- openfuture 5y agoAre you no longer tagging releases? The last one is 3. August 2020 and for a while they were getting tagged regularly but now it's been 500 commits with no tag? Sorry if my question can be answered in the issue tracker I was just curious.. Edit; ah indeed https://github.com/mthom/scryer-prolog/issues/640 https://github.com/mthom/scryer-prolog/issues/640
- mthom 5y agoI'm planning version 0.9.0 soon. From there I hope to get back to a regular release schedule.
- Tomte 5y agoI don't know if "more users" is currently desirable or maybe a distraction, but if so, please provide binaries for common operating systems like Windows and Mac. No, Docker is not a substitute.
- tytrdev 5y agoThis is wonderful. I’ve recently been very obsessed with Datalog implementations like Datomic, Datascript, Datalevin, and XTDB. Hopefully learning prolog can be a good next step. It’s nice to see the rust community jumping into that space.