[HN Gopher] Demo of a WAM Prolog Implementation in Python ___________________________________________________________________ Demo of a WAM Prolog Implementation in Python Author : triska Score : 65 points Date : 2021-10-01 15:50 UTC (7 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | emmanueloga_ wrote: | Very cool! This seems like a natural follow up to [1], a nice | tutorial on building a simple prolog interpreter with Python. | | 1: https://www.openbookproject.net/py4fun/prolog/prolog1.html | tehnub wrote: | This looks like a good codebase to learn modern Python style and | features from. I found it quite readable despite not being very | familiar with this sort of programming. | platz wrote: | But is it Detotated WAM? | mhh__ wrote: | Hah. That was the intrusive thought in my head reading about | the WAM | triska wrote: | The WAM is _Warren 's Abstract Machine_, introduced by David H. | D. Warren in his 1983 paper _An abstract Prolog instruction set_ | : | | http://www.ai.sri.com/pubs/files/641.pdf | | This invention showed conclusively, and for the first time, that | Prolog code can be very efficiently executed, and is even more | efficient than Lisp in many cases of practical relevance due to | its efficient reclamation of memory on backtracking which does | not require garbage collection: | | http://www-public.int-evry.fr/~gibson/Teaching/CSC4504/Readi... | | The WAM has since become a popular target architecture for | efficient Prolog execution, analogous to the BEAM in Erlang etc.: | | https://en.wikipedia.org/wiki/Warren_Abstract_Machine | | Several popular Prolog systems, including GNU Prolog, Scryer | Prolog and SICStus Prolog, compile Prolog code to WAM code and | then interpret the abstract machine code for good efficiency. | | One interesting feature of the WAM is that it is register-based, | not stack-based. Hassan Ait-Kaci's tutorial is a nice | introduction to the WAM: | | http://wambook.sourceforge.net/ | | There are several other used and proposed abstract machine | architectures for Prolog, such as the ZIP, TOAM and the Vienna | Abstract Machine (VAM). Andreas Krall's paper contains many | interesting implementation techniques: | | https://www.complang.tuwien.ac.at/andi/papers/wlp_94.pdf | melony wrote: | Are there any recent advances in Prolog | compilation/implementation post-Y2K? Or has GOFAI development | stalled in general? | triska wrote: | Yes, definitely, there are several recent advances in Prolog | implementation techniques! | | For example, _just-in-time (JIT) compilation_ , i.e., | compilation to native code. Quoting from the SICStus | documentation | https://sicstus.sics.se/sicstus/docs/latest4/pdf/sicstus.pdf | : | | _" Since release 4.3, on 32 and 64 bit x86 platforms running | Windows, OS X, and Linux, SICStus Prolog has the ability to | compile predicates from virtual machine code to native code. | This process, known as Just In Time (JIT) compilation, is | controlled by a couple of system properties (see Section | 4.17.1 [System Properties and Environment Variables], page | 224), but is otherwise automatic. JIT compilation is seamless | wrt. debugging, profiling, coverage analysis, etc. JIT | compiled code runs up to 4 times faster than virtual machine | code, but takes more space."_ | | As another example, one of the most recent and also very | significant innovations in Prolog implementations happened in | 2020, when Scryer Prolog became the first Prolog system to | implement a very compact internal representation of lists of | characters, internally storing them as sequences of raw bytes | in UTF-8 encoding instead of compound terms, while Prolog | code "sees" them as lists and can therefore reason about them | with conventional predicates over lists. | | Trealla Prolog took up this idea and now already allows the | efficient application of Prolog definite clause grammars | (DCGs) to entire files (using phrase_from_file/2) by | _mmapping the entire file to memory_ , i.e., using the | operating system to transparently process the file as if it | were loaded, without having to load it in its entirety into | memory. This paves the way for the use case Prolog was | designed for: efficient and convenient reasoning about large | amounts of text. | maweki wrote: | I wonder how Tauprolog with all the JS jit-stuff compares. | e12e wrote: | Thanks for mentioning traella - doesn't look like it gained | much traction last time it was brought up: | | https://news.ycombinator.com/item?id=26313792 | sigstoat wrote: | thanks for the references, and the followup comment. | [deleted] | memco wrote: | If you're interested in implementing languages in Python, I've | been enjoying watching the development of Porth[0], a stack- | based, forth-like* language on Twitch. | | * See readme disclaimer that there's no actual connection to | Forth other than the stack-based design. | | [0]: https://github.com/tsoding/porth ___________________________________________________________________ (page generated 2021-10-01 23:01 UTC)