3 ms·
Prolog.c: a simple Prolog interpreter written in 200 LOC of C++ (2000)
- stirner 10y agoPedantic: C++ code should generally have a .cpp extension.
- cheez 10y agoLooks like it was written in the year 2000 so it is more than likely it was written on a UNIX system and used the .C suffix. I can't really tell though.
- bbayer 10y agoAuthor Alan Mycroft is co-founder of Raspberry Pi foundation. I assume, he was aware what he was doing back in the day.
- kchoudhu 10y agoYou're right: that is pedantic -- in the worst sense of the word.
- stirner 10y agoActually, worse: there are actually lots of C++ file extensions and .cpp doesn't even seem to be the most popular. I was mistaken, apologies.
- the_trapper 10y agoFor the record, .C (uppercase "C" on case sensitive file systems like *NIXen), .cxx, and .cc are also fairly common and perfectly acceptable.
- johndubchak 10y agoAgreed, but I would take this further. To call this C++ and be using character arrays for strings rather than std::string and performing manual memory management suggests this is "C with Classes" at best, notwithstanding the fact that it HEAP allocates a bunch of stuff that it never reclaims. I understand this isn't a code review and I'm not trying to be critical but it's saddens me to see poor C++ code being shown online because that's partly responsible for the bad rap of the language - I know there are other reasons, but this doesn't help.
- vowelless 10y agoWould love to see it in C++11 or later.
- hellofunk 10y agoIt wouldn't necessary be much different if using C++11. Maybe using unique_ptr instead of new, etc. It certainly _could_ be a lot different, using a more functional approach, but it likely wouldn't be, and would remain a basic OO program dressed in new syntax.
- dmytrish 10y agoC++202x would be good too.
- fspeech 10y agoI found Paul Tarau's work the easiest to follow on making a functional Prolog without WAM, for example: https://code.google.com/archive/p/kernel-prolog/ https://code.google.com/archive/p/kernel-prolog/ He also has theory papers explaining the architecture. For example: http://logic.cse.unt.edu/tarau/research/NewJinniPapers/fluents.html http://logic.cse.unt.edu/tarau/research/NewJinniPapers/fluen...
- B1FF_PSUVM 10y agoWAM: "an abstract machine for the execution of Prolog" https://en.wikipedia.org/wiki/Warren_Abstract_Machine https://en.wikipedia.org/wiki/Warren_Abstract_Machine (a couple of others in the Wikipedia disambiguation page are worrisome ...)
- dbcurtis 10y agoIs there a good reason to still be using Prolog? I used Prolog back in the day, but is it still the tool of choice for some projects?
- justusw 10y agoUsing DCGs (https://en.wikipedia.org/wiki/Definite_clause_grammar https://en.wikipedia.org/wiki/Definite_clause_grammar), you can easily create grammars for automated document parsing and generation. You could even write a compiler (http://comjnl.oxfordjournals.org/content/34/1/64.full.pdf http://comjnl.oxfordjournals.org/content/34/1/64.full.pdf) or disassembler (http://www.dtic.mil/dtic/tr/fulltext/u2/a242987.pdf http://www.dtic.mil/dtic/tr/fulltext/u2/a242987.pdf) in Prolog fairly easy. All thanks to the really smooth support of tree-like structures. I do wonder why all this seems to be a little forgotten. Granted, the syntax and semantics are a bit unusual, but the expressive power can hardly be matched.
- agumonkey 10y agoThanks for these links. Another DCG tutorial http://www.pathwayslms.com/swipltuts/dcg/index.html http://www.pathwayslms.com/swipltuts/dcg/index.html
- dbcurtis 10y agoYour link lightly addresses one of my questions about using DCGs for parsing. How hard is it to get a sensible error message out of a DCG parser? I've basically written off LALR parsers because getting a reasonable error message out of them is about as much fun as repeatedly poking yourself in the eye with a sharp stick. Good old recursive decent using precedence climbing for expressions seems to be more maintainable in the long run for production parsers.
- infradig 10y agoProlog is my scripting language of choice for personal projects. Like HN uses a custom Lisp, I prefer doing stuff with my custom Prolog. But then, i'm a curmudgeonly old fart.
- timmytokyo 10y agoIt leaks memory all over the place. Is it intended for tiny, short-lived programs that don't generate a lot of garbage?
- sitkack 10y agoprogram termination is a valid reclamation strategy