5 ms·
I don’t think prolog does itself any favours by advertising as a general purpose programming language. I tried to learn it and it really screams “I’m not a gen
by usgroup 4y ago
I don’t think prolog does itself any favours by advertising as a general purpose programming language.
I tried to learn it and it really screams “I’m not a general purpose programming language”.
If you take away the use cases more suitable for datalog or MiniZinc the only remaining strong use case I see is recursive parsers.
It’d be good to hear about how others see it.
- ausudhz 4y agoWell, luckily what prolog screams is irrelevant. Most programming language are Turing complete and if so they're also general purpose by definition. You can use them to build anything. That said of course our definition might be different and if you don't have plenty of layers of abstraction that speed your development you won't consider that programming language compared to another. After all, we are running JavaScript in the servers now and you can find an npm module for nearly everything. Probably someone 20 years ago would've said that "JavaScript is not a general purpose language" Don't get me wrong, prolog may never be the next JavaScript, but is just fun how people would define something is "general purpose" or not (no hate, just a pure comment seeing things from a different angle)
- xupybd 4y agoI think many people understand general purpose to mean it's a good language choice for many different and common uses. It has little to do with how Turing complete the language is. Just how well it suits a variety of problem domains.
- eadler 4y agoagreed. For example C is considered general purpose despite not being Turing complete.
- bmitc 4y agoIs it really not? Do you have a reference for that? I can’t find anything that says C isn’t Turing complete.
- ogogmad 4y agoIt's a troll. But not wrong. C treats computer memory as an array of bytes indexed by a pointer type that can take only finitely many values. If the pointer type can be cast losslessly to `long int` - which is usually understood to be 64 bit - then this byte array has precisely 2^64 entries. That implies that C programs have an absolute limit on the amount of memory they can use (2^64 bytes). That's obviously true, because each call to `malloc` fills up another entry of this finite byte array. C therefore can't simulate a Turing Machine, because a Turing Machine can use an unbounded amount of memory. If you use a file system, or another source of external memory or storage, then the above argument no longer applies.
- avmich 4y agoA long time ago computers with limited RAM address space - and problems which didn't fit - used various tricks to deal with that. Overlays, paged memory, virtual memory - all that could effectively address more memory than address space allows. So I'd argue C-as-specification (not as existing implementation, I don't know) is _theoretically_ Turing complete. Yes I agree it's a troll.
- Jorengarenar 4y agoIn strict sense of being Turing-Complete, noting is TC, because of physical world limitations (infinity doesn't really exists). If we use "useful" definition of being Turing-Complete, then even `printf()` alone is already TC.
- ausudhz 4y agoI think C is Turing complete for sure.
- naasking 4y ago> For example C is considered general purpose despite not being Turing complete. Actually, C fails the general purpose language criterion too, because it's simply not a good choice for many different and common uses. It's a good choice for very specific uses at this point.
- cultofmetatron 4y agoc is only technically not Turing complete because it runs on real machine with finite memory. by that definition, no programming language is turing complete.
- bmitc 4y ago> Most programming language are Turing complete and if so they're also general purpose by definition. You can use them to build anything. How long do you think it would take to write a web server in Rule 110? https://en.m.wikipedia.org/wiki/Rule_110 https://en.m.wikipedia.org/wiki/Rule_110 Turing completeness is an interesting theoretical concept, but it is wholly unsuitable and largely irrelevant when discussing the usefulness of programming languages.
- YeGoblynQueenne 4y agoWhat is "usefulness" then? It's clear that different programming languages are more suitable for different use cases, for example one wouldn't normally script a browser in Lua or use Javascript to write a driver for a hardware device. That said, if it's about use cases, Prolog is an excellent language for web development and capable of replacing most of the usual mixed OOP and relational stack. For example, the SWI-Prolog website runs on SWI-Prolog's own http libraries. Quoting from https://www.swi-prolog.org/dogfood.html https://www.swi-prolog.org/dogfood.html: This page presents a brief history of hosting and developing http://www.swi-prolog.org http://www.swi-prolog.org. The website runs SWI-Prolog and is basically `PlDoc, the SWI-Prolog source documentation system on steroids'. This site replaced a classic Apache server built from static documentation pages, a Twiki-based wiki and Bugzilla. The site was re-implemented as a SWI-Prolog-based HTTP server that extends PlDoc for the following reasons: 1. PlDoc unites the core reference manual with the package documentation and documentation extracted from all loaded sources in a coherent interface. In addition, it provides search, dynamically generated hyperlinks between the various pieces of documentation, and display of the source code. This is far better than the fragmented and not properly interlinked static documentation of the old site. 2. SWI-Prolog comes with extensive libraries for providing web services. Running the website on the system is just the ideal opportunity to test these services and prove to the Prolog community that they are a vital piece of the infrastructure and that we trust them. The server: welcomes about 4,000 visitors each day, viewing about 30,000 pages (120,000 hits) (2013) serves about 350 Gb of data per month serves downloads from static files serves manual pages from on-the-fly post-processed HTML documents serves dynamically generated HTML pages from documented source files, coloured source files, etc. analyses, indexes and presents packs. It also presents the meta-data for pack_install/1 runs a REST API to handle user annotations. Also see: Can I replace a LAMP stack with SWI-Prolog? https://www.swi-prolog.org/FAQ/PrologLAMP.txt https://www.swi-prolog.org/FAQ/PrologLAMP.txt
- tannhaeuser 4y agoThe Quantum Prolog site [1] advertises ISO Prolog for planning, optimization, diagnostics, and complex configuration but also showcases Inductive Logic Programming as a variant of Machine Learning. Agree Prolog should be seen as special-purpose language, but rather for a much larger domain than parsers. Datalog, using a Prolog syntax subset, is a decidable logic fragment for use in theorem provers and is also used as a query language. MiniKanren may be useful as embedded logic solver (I don't know really) and MiniZinc might have its uses, too, but those really don't compare to the portability and size of the Prolog ecosystem IMO. [1]: https://quantumprolog.sgml.io/ https://quantumprolog.sgml.io/
- YeGoblynQueenne 4y agoI've used Prolog since 2008 I think, and I've heard it said that it's not a "general puprose programming language" but I don't understand what that means. Could you explain? What is a "general purpose programming language" and how does Prolog scream it's not one? I'm asking curiously and I guess I have a weird perspective, having used Prolog for a long time, so I would be grateful for an explanation. (To clarify, most of my career as a programmer I worked mainly with C# and SQL, so I haven't somehow been hiding away in a secret Prolog dimension. I wish :)
- dflock 4y agoPython is a general purpose language. You can write anything in python, from quick and ditry replacements for bash scripts, to windows desktop applications, to clustered supercomputer code. It also has an library ecosystem to match.
- cess11 4y agoSomeone fluent in SWI-Prolog can do all that too.
- YeGoblynQueenne 4y agoYes! See https://news.ycombinator.com/item?id=34195543 https://news.ycombinator.com/item?id=34195543 elsewhere in this thread with a discussion about SWI-Prolog's http libraries used to run their own website, replacing a more traditional LAMP stack. But, just to clarify, is that what is meant by "general purpose", that a programmer can write anything they want and there are libraries to boot? The main reason I am very confused about "general purpose" is because, in my experience, Prolog is very much a language where you can write any kind of program you want. And there are libraries applenty in SWI-Prolog, although of course Prolog has a much smaller community than Python so one should not expect quite the same level of support, I guess.
- todd8 4y agoNaturally, the “curse of Turing” means that virtually any programming language can, with enough effort, do anything. I wouldn’t classify Prolog as appropriate language for general purpose vs say Python. In theory, I could write a replacement for the Linux kernel in machine code or COBOL or even Prolog. This doesn’t mean that it would be wise to do so. (I’ve written code in professional settings in all of these ways.)
- YeGoblynQueenne 4y agoBtw, I wanted to note that Prolog is indeed very good at any problem that requires manipulating recursive data structures, like parsing. But that's one thing that you can do more easily in Prolog than you can in other languages. It's one of the things it is good for, if you want, not the one thing it is good for. For me, what Prolog does best is get all the ceremony of other programming languages out of my way and let me concentrate on the problem at hand. By "ceremony" I mean special syntactic constructs. For example, you don't even declare variables, as such, in Prolog, there's no assignment expressions, classes and enums and switch statements, there are no for and while loops etc etc. Prolog instead gives you a very small set of abstract building blocks that you can use to write any program. It's like programming with Lego bricks, except you have one kind of brick, a universal Lego brick that you can build anything you want with. Which is why it's so good at solving hard problems, because once you're used to its abstractions and how to combine them, any problem becomes an exercise in finding the right way to fit the "bricks" together in the right way [1] [2]. That's also why Prolog is hard to learn: imperative languages have ceremonial constructs (if-then-else, while-do, yield, etc) for a reason. The reason being, because that makes it easier to write programs. But not easier to _solve problems_. Not when the problems get hard anyway [3]. So perhaps this is one reason why people say it's not "general purpose"? Because it's hard to learn, so it's hard to use when you're just trying to write, dunno, simple list processing programs, but makes things easier when you're trying to do something inherently difficult, like write a parser? If I think about that, I could see how Prolog may come across as a language only good for certain kinds of problem (which is my attempt to interpret "general purpose", though I'd still be grateful if someone gave me a clear definition that I can grok). ____________ [1] As an example, here's two ways to write the Ackermann–Péter function in Prolog: https://rosettacode.org/wiki/Ackermann_function#Prolog https://rosettacode.org/wiki/Ackermann_function#Prolog One uses the is/2 predicate, which is an instance of what I mean by "ceremony". The second uses Peano notation for natural numbers and is basically a direct translation of the Function's definition on wikipedia (full disclosure: the second version is mine). [2] That's also the reason why it's infinitely easier to machine-learn Prolog programs, as in Inductive Logic Programming, than to learn, say, Python programs. If you want to loop in Prolog, all you need to do is place a literal in the body of a clause that has the same symbol as the literal at the head of the clause: p:- q, p is recursive. So if you want loops, just move your "bricks" around until they're in the right place, and job done. To machine-learn Python you have to find a way to compose every single special-purpose expression, and all the other kinds of loops, and that gets a lot more complicated, more so as a program grows in size. It should be noted that you get the same simplicity with languages of the lambda calculus, hence Inductive Functional Programming is also a thing. [3] All the high-level abstraction also makes it much harder to read. See the Peano notation Ackermann-Péter Function above.
- Avshalom 4y agoI suppose, why take away those use cases only to later weld them back together with Python, maybe having to do it with a bunch stringly typed ffi calls. Now you have three or four languages/programs/DSLs to deal with, each with impedance mismatches and they can only interact through the central Python program. Or you can collapse your stack down one technology that integrates it all in such a natural way that you can list recursive parsing and linear constraint optimization in the same breath and still say it's not a general purpose language.