12 ms·
A “Hello World” Server in Prolog
- jdp23 11y agoGreat to see ongoing interest in Prolog. I did my Master's thesis in Prolog back in the "Fifth Generation" days [1] ... obviously the hype was waaaaay overstated but it still significantly influenced my thinking. I really think of it as one of those languages like Lisp or ML that opens your mind even if you don't wind up using it in your day-to-day job. Plus, I thought it was entertaining to see this on the front page at the same time as "Hello, declarative world" :) [1] https://en.wikipedia.org/wiki/Fifth-generation_programming_language https://en.wikipedia.org/wiki/Fifth-generation_programming_l... [2] https://news.ycombinator.com/item?id=10219780 https://news.ycombinator.com/item?id=10219780
- deleted 11y ago[deleted]
- samuell 11y agoAnd I did mine more recently (2010) [1] :) (Mostly semantic web stuff ... showing how it can far outperform Java based SPARQL implementations for some stuff). It was a real joy to work with semantic web data in SWI-prolog! Prolog lets you raise your level of abstraction so quickly, as defining prolog rules basically is a form of creating "named queries", something that is not possible e.g. in SPARQL (the canonical semweb query language). I can't understand why this feature of prolog is not implemented more widely in more recent systems. The only example I know of that does, is Datomic [2], by Rich Hickey. [1] http://www.diva-portal.org/smash/record.jsf?pid=diva2%3A398839&dswid=-8767 http://www.diva-portal.org/smash/record.jsf?pid=diva2%3A3988... [2] http://www.datomic.com http://www.datomic.com
- timothycrosley 11y agoFor comparison: Here's the same thing in modern Python: https://news.ycombinator.com/item?id=10221707 https://news.ycombinator.com/item?id=10221707
- cronjobber 11y agoThis reminded me of O'Keefe's Prolog Well-formed Pages, one of the cleanest templating approaches. http://www.cs.otago.ac.nz/staffpriv/ok/pwp.pl http://www.cs.otago.ac.nz/staffpriv/ok/pwp.pl
- mindcrime 11y agoIf anybody is interested in Prolog, you might find this old blog post of mine useful. I cataloged a number of pretty useful online (freely available, legal) Prolog learning resources: http://fogbeam.blogspot.com/2013/05/prolog-im-going-to-learn-prolog.html http://fogbeam.blogspot.com/2013/05/prolog-im-going-to-learn... Sadly I've only just now finally gotten around to investing some time in to trying to learn Prolog myself. I got as far as creating myself a Github repo[1] and writing "Hello, World" and figuring out how to run Prolog programs at least. It's not much, but ya gotta start somewhere. [1]: https://github.com/mindcrime/LearningProlog https://github.com/mindcrime/LearningProlog
- nitrogen 11y agoI'm glad to know I'm not the only person who creates "learning_xyz" repositories that may or may not progress very far, though I've yet to share any of mine online.
- mindcrime 11y agoI only recently started sharing mine. I decided there was no real reason not to, and possibly some advantages in doing so. For one, it lets anyone looking at my GitHub profile know what kinds of things I'm into, beyond my "primary" projects. And it opens up the possibility of collaborating with friends and acquaintances (or, as far as that goes, total strangers) on some interesting stuff. I also find it motivational, especially when I work on increasing length of my "streak" of activity on GitHub.
- nitrogen 11y agoEasiest way to have a long streak: run daily backups that push to GitHub via cron ;-)
- mindcrime 11y agoYeah, but that kinda defeats the point. What I've been trying to do is focus on making at least one commit a day that at least fixes something trivial, like replacing a "println" statement with a "log.debug" or "log.info" or whatever (in some Grails code). This way I'm both slowly and steadily improving the code, and I get to push my streak. Still, my long streak is only 14 days so far. :-(
- debacle 11y agoAnyone have a mirror?
- eatonphil 11y agoIs it down for you? https://web.archive.org/web/20150913080629/http://www.swi-prolog.org/howto/http/HelloText.html https://web.archive.org/web/20150913080629/http://www.swi-pr...
- penetrarthur 11y agoI like how posts about Prolog get populular very fast, but have little to no comments. People have heard that this language is special but have never actually used it in production, so they hope that someone will shed the light on it. Unfortunatelly it usually ends with a copypasted list of 15 projects(including Watson) where Prolog is used and thats it. Maybe someone can share his/her production level experience with it this time...
- mark_l_watson 11y agoIBM Watson uses Prolog? That is interesting. I have been helping a friend for a year integrate IBM Watson into his product, but I don't know much about how Watson is implemented.
- mindcrime 11y agoIBM Watson uses Prolog? Yep. Watson has been described as "mostly written in Java, with some chunks in C++ and some in Prolog"[1]. The Prolog is apparently mainly used for language parsing[2]. Also the open source UIMA[3] project is heavily used by Watson. UIMA started out as an IBM project called OmniFind (IIRC) and was later donated to the ASF. [1]: http://www.drdobbs.com/jvm/ibms-watson-written-mostly-in-java/229300226 http://www.drdobbs.com/jvm/ibms-watson-written-mostly-in-jav... [2]: http://learning.acm.org/webinar/lally.cfm http://learning.acm.org/webinar/lally.cfm [3]: http://uima.apache.org http://uima.apache.org
- mjn 11y agoSome background on why Prolog for parsing: That was traditionally a popular use of Prolog, because something similar to BNF-style grammar rules can be written almost literally as Prolog clauses, and you get a parser for "free". Very easy to prototype, plus since it's just Prolog clauses that can be used by the rest of the Prolog program and vice versa (not black-box tables generated by YACC), you can muck with edge cases, integrate error reporting, call out to information-extraction heuristics where relevant, etc. The technique is "definite clause grammars" (DCGs), and can either be written directly in normal Prolog, or with some syntactic sugar that most Prolog implementations include. Here's a tutorial: http://www.pathwayslms.com/swipltuts/dcg/ http://www.pathwayslms.com/swipltuts/dcg/ Compared to when DCG parsing was most popular ('70s-'90s), there are now more alternatives for easily working with grammars, though, including non-black-box approaches nicely integrated into languages, like combinator parsers in Haskell and LPeg in Lua. So it's not quite as unique today, though it's still a nice way to prototype parsers.
- mark_l_watson 11y agoI think one of Swi-Prolog's great advantages is the large library, especially tools for the semantic web. I have not had any consulting work using Prolog in at least 8 years and don't do much for-fun Prolog programming either. I used to find Prolog especially good for hacking together quick prototypes.
- chollida1 11y agoWe're a pretty heavy user of Prolog for several systems. We use it for doing end of day allocations to prime brokers to determine the optimum allocations, basically a constraint solver. I had it in the trading system for some time but I had to pull it out as I couldn't find a way to make its runtime deterministic enough. Most of the time it would be great and then on occasion I'd get 100 millisecond pauses:( I could never figure out if it was me doing something, the C bindings we were using or if Prolog just has a mind of its own:) If anyone has any pointers on how to reason about the run time efficiency and performance of your prolog code I'd be willing to buy you a coffee! http://www.amazon.com/Programming-Artificial-Intelligence-International-Computer/dp/0321417461 http://www.amazon.com/Programming-Artificial-Intelligence-In... Awesome book, can usually be found in any used university book store!
- jamii 11y agoDepending on how you are using it, you could look into an actual constraint solver like Gecode or a more deterministic logic language like Dyna. The latter would probably require some implementation work - the only production-quality implementations I know of are proprietary. http://www.gecode.org/ http://www.gecode.org/ https://github.com/nwf/dyna https://github.com/nwf/dyna
- tom_mellior 11y ago> on occasion I'd get 100 millisecond pauses As a first guess, this sounds like garbage collection pauses. Details of what to do about them depend on the particular implementation. In SWI you can use the profiler to see if the garbage collector is in fact being called when you don't expect it. Then: (a) change the default (veeery low) garbage collector settings to use more memory before collection is triggered; (b) make sure you're not leaving unnecessary choice points around (listed as "redo" by the profiler, fix with correctly placed green cuts); (c) call garbage_collect/0 yourself at well-defined points when you're currently not doing low-latency stuff; (d) possibly (but I have no personal experience with this) turn off the garbage collector completely for certain sections of the code.
- userbinator 11y ago
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- Kutta 11y agoI had a Prolog class in university and also fiddled with it a bit extracurricularry. My biggest gripe was that (aside from being untyped and having poor support for higher-order programming, but that's probably remedied in more modern logic programming languages such as Mercury) for more complex use cases and computations the system degrades into functional programming with poor syntax: logical relations become deterministic functions with designated inputs and output, at which point I would be just better off with FP + backtracking (for example, the list monad in Haskell).
- 0xFFC 11y agoI am OS guy . so I don't have so much experience in other than C. Yesterday I was watching youtube video about prolog , and I amazed by Logic Programming concept.Maybe for most of you it is ordinary concept , but for it was wonderful and I have plan to continue it in my spare time.
- webnrrd2k 11y agoA suggestion to anyone who's interested in logic languages, like prolog: Give The Reasoned Schemer by Daniel P. Friedman a try. It's an easy, fun book, with surprising depth if you give it some effort and thought. .
- pbowyer 11y agoWhen I used Prolog at university, we built really cool constraint solvers using hardcoded predicates, but is it possible to create the predicates dynamically? To be useful, if a user has a GUI where they can define rules, they've got to be loaded into the program somehow... hopefully not through code generation?