At work, there was a discussion of using prolog as the backend for a rules engine on a web-app.
How would this get tied into existing systems?
Are there available prolog libraries for other languages allowing the invocation of prolog modules?
For SWI-Prolog, you could look to Thea2 which has support for SWRL in Prolog and can also be attached to external reasoners via JPL such as HermiT for OWL/SWRL reasoning, or Pellet, etc.
On a personal note, I have used JPL several times in the past to enable web-apps with a SWI-Prolog backend, which works just fine if you intend to program your web app using a language which is executable on a JVM, like Java, Groovy, or Scala, for example. Another alternative would be to hook SWI-Prolog into a C or C++ environment, which I haven't tried for a web-app.
If your web-app is using another development language that doesn't run on a JVM or in C/C++, then this mightn't be the right path for you as it seems to be a bit harder to connect a running SWI-Prolog environment to other language environments. However, that said, we have successfully implemented a SWI-Prolog-to-anything bridge using HTTP before, but this is less than ideal if performance is a necessity.
swi-prolog has a perfectly reasonable HTTP server/ web framework included.
You could talk to it over HTTP.
There are tools for parsing XML/SGML and JSON, and ODBC
I'm not sure exactly what you're looking for, but you may want to look into Yield Prolog
, which allows the embedding of Prolog code into programs using Python, C#, or Javascript. There is no API involved. I haven't used this myself (yet), but it may be amenable to what you're trying to do.
I guess an important prerequisite for web embedding, especially on the
server side, is multi theading capability of the Prolog system. At
least you would probably need this, if you want to serve multiple
users concurrently.
You can then opt either for a pure solution, where the pages are
generated and maintained by Prolog itself. Or maybe for a mix solution,
where the Prolog system is only used for some business logic and another
programming language is used for presentation and/or storage.
The following Wiki comparison table gives an overview of Prolog systems and
whether they are multi threaded and/or support some web programming:
Comparison of Prolog implementations,Operating system and Web-related features
For my own take on this problem I have set up a little tutorial
that shows the use of the Jekejeke Runtime for server side
business logic. Jekejeke Runtime is quite flexible, you can not
only have multiple threads, you can also have multiple
knowledge bases.
Jekejeke Runtime,Deployment Methods
The Jekejeke Runtime is for example currently used in a productive
sales system, by some custom read/write locks, it allows even remote
hot swap of the knowledge base by an administrator without restarting
the web context. Unfortunately there is no report yet on that.
Bye
LPA Prolog has been widely used in various commercial web-based applications, most noticeably within Business Integrity's industry-lead document assembly product, DealBuilder
LPA provide various architectures for deliverying web-based applications - some of which are shocased within the VisiRule section on the LPA web-site
www.lpa.co.uk
Clive
Some languages make use of a bridge and provide a library for it for example in Python there's PySWIP for single-threaded use, so it doesn't play nicely with web apps. I've found Pengines to be far more versatile.
Pengines are in SWI, they're a way of querying Prolog via HTTP. There's at least a JavaScript, Java, and Python library to interface with them, but it's just a bunch of HTTP requests. Makes it easy to distribute, use as a micro-service, or horizontally scale. Although as anniepoo has witnessed to, a SWI server can handle decent amount of traffic!
Also in the case of JavaScript there's Tau Prolog which compiles to and works within JavaScript.
There's a lot of sense in using a logic language as a rule engine.
Related
Is it good architecture of an application if,
I am using multiple technologies leveraging strong points of each.
for example:
Encryption in python,
integration of services in java etc.
or should I stick to one technology like Java as I am comfortable with it?
Also the reason for this question is I am thinking of developing a new application in which speed is a major concern, I am targeting to attain.
Also Database that I am preferring for now is MongoDb.
Any suggestions on the Technologies apart from these technologies?
Also will this approach help in speeding up the application?
Writing the main application in one language only is a easier approach than dividing your application and attempting to write pieces in each language that is best suited for the task, unless you are fluent in a few languages and the ones chosen are particularly suited to specific groups of tasks that make up parts of the functionality.
Because MongoDB has a Java Driver there's nothing wrong with writing your main application in Java and relying on libraries written in other languages (MongoDB is written in C++, C and JavaScript).
As long as other works you need to rely on are well maintained there's no reason to switch from your preferred language to match what any of your libraries are using.
If you add artificial intelligence to your program in the future and part of the code is to run on a GPU you are forced to have a program that is a hybrid; learning a new language along with the details of the underlying algorithms is certainly more of a burden than learning the API.
Decide where to draw the line, what you will write in your preferred language and what will be written by others. It's certainly better to choose libraries and programs that you interface with written in languages you understand (assuming that they are open source). If what you interface with has no source available it becomes a 'black box' which simply must work, there are occasions when that is acceptable and occasional when there is no choice.
I'm using Prolog for an academic project. I wanted to know if there is a way for Prolog to interact with other programming languages. What I want is an easy input/output redirection of Prolog question and answers.
I'm aware that Prolog can call C functions in some Prolog implementations. i.e. SWI Prolog.
What I need is a simple input/output redirection of Prolog questions and the answer that user provides.
Any help would be really appreciated.
I don't see any true requirement for a foreign language interface for your task: use Prolog IO, it's easy to use and efficient. You could also start with just support from protocol/1. Just a KISS advice...
A foreign language interface it's mandatory when you need something implemented in that other language.
SWI-Prolog C++ interface it's much easier to use than C counterpart, and allows both extending the language with really easy builtins' coding as well as embedding the engine in a standalone 'main'. And these 2 aspects can cohexist gracefully: say for a fast prototype just we implement the builtins, and use the REPL top level, while a full blown application can start the engine to be used as logic engine, and submit the (hopefully tested via REPL) queries in background.
Then there is JPL to interface SWI-Prolog and Java. I know little about it... I've seen some problem reported on the SWI-Prolog mailing list, due (mainly) to the complexity of different threading models. But certainly it's working.
An interesting development is occurring to make available the IDE into Eclipse (PDT, Prolog Development tools). I think they use their own Java interface. Currently could be a better choice than JPL.
But the most interesting interface SWI-Prolog can propose today it's the HTTP server infrastructure. If you known WEB client development (HTML/JavaScript/XML/RDF) you have plenty of tools to split your design in MVC Client/Server. Prolog runs a Web Service, and a Rich Client interacts with end user. This architecture make your application ready to run locally as well in the wild.
Please see the relevant How To section...Is not a simple task, but (IMHO) a very rewarding and long standing one.
SWI-Prolog can interface with C (http://www.swi-prolog.org/pldoc/package/clib.html), C++ (http://www.swi-prolog.org/pldoc/package/pl2cpp.html), C# (http://www.swi-prolog.org/contrib/CSharp.html) and Python (http://code.google.com/p/pyswip/). Furthermore, you can communicate with Prolog via e.g., external files.
Take a look at Amzi Prolog + Logic Server - its purpose is to make prolog programs accessible as componentto other conventional languages.
It depends on the Prolog distribution you are using. As previously commented SWI-Prolog provides different interfaces for the most common uses like C, C++, databases, HTTP, XML and others.
The Ciao distribution can be also useful for what you are looking for. In this case is C so check out this link Ciao Prolog and C
Is Lisp good for web programming/applications (interactive), the way ruby and php are?
Things to take into consideration would be:
Ease of use
Deployability
Difficulty (especially for a beginner to programming)
(Edit)
I was Particularly referring to Common Lisp, after reading Paul Graham's essay. Would be my first programming language. In this regard. Is it suitable to do so ?
I hear that Clojure's macro functionality is not as powerful as Common Lisp's, and that's why I'm trying to learn Clojure. It teaches programming and is very powerful.
Lisp is a language family, not a single language. To somewhat answer your question, yes, web frameworks exist for the various Lisp dialects, like UnCommon Web for Common Lisp and PLT Racket (a Scheme dialect) has a tutorial on their web site too:
http://docs.racket-lang.org/continue/
But one Lisp dialect where you'll see quite a lot of web development going on at the moment is Clojure, since it can leverage existing Java libraries and infrastructure. Here's a list of projects, and that's not comprehensive:
Hiccup - represent HTML in Clojure
Ring - a HTTP abstraction similar to Rack in Ruby
Enlive - selector based templating and more
ClojureQL - a SQL integration library
CongoMongo - a wrapper for MongoDB
There'd be many more, but I think you get the idea. As for Clojure web apps in the wild, the Clojure learning site 4Clojure would be an example and you can check out the source code on GitHub (I occasionally contribute to this):
https://www.4clojure.com/
https://github.com/dbyrne/4clojure
As you can see there's quite a lot going on in terms of Clojure and web development. It may not always be smooth sailing, but people are working fast at making the experience better. Making use of existing Java infrastructure does have its benefits, like the possibility to deploy to Google App Engine etc.:
http://www.infoq.com/articles/deadline-clojure-appengine
Hope that somewhat answers your question...
I have almost no experience with PHP or Ruby. However, I can say that it is quite easy to write a web application using Hunchentoot, CL-WHO, and one of the many database backends (Postmodern, CL-SQLite, CLSQL, or even a simple serialization library like USerial or Rucksack).
There are also frameworks like Uncommon Web or Weblocks, but I have not tried them yet.
There's a funny quote from Kent Pitman
"...Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list."
And, look, "web authoring" even made it on the list!
Lisp is good for web programming because it is so flexible and the s-expressions that make up Lisp forms have some nice similarities to HTML. To see what I mean, check out Lisp for the Web. Notice how he writes a macro to basically create a domain-specific language for creating web pages -- instead of defining functions, he's now defining pages! This DSL concept is also apparent in the CL-WHO library he's using, which lets you write Lisp that turns into HTML.
Paul Graham had success rolling his own solution while creating what later became Yahoo! Store in Common Lisp (and even more success writing about it afterwards), and since then many packages have sprung up.
Weblocks is the Common Lisp web framework that seems to me to have the most momentum at the moment. There's a video of it being discussed at the Twin Cities Lisp user group. UCW is very similar, but I don't see much action on it now (please excuse me if I'm just looking in the wrong places). The blog post on why the creator made Weblocks is pretty enlightening: he basically wrote enough Lisp so that he'd never have to deal with HTML, AJAX, and JavaScript again. That might be an overstatement, but the fact that he could even do some of that should answer your question.
This is opinionated but so is the nature of the question, so here's my take.
I would not recommend a beginner to programming to start with a functional language, especially a Lisp.
T concepts on functional languages and especially Clojure are more advanced and the power it gives you, you propably won't need in your first steps into web development.
So since you are a beginner, then my answer would be no, Lisps are not as easy to learn and use as Ruby and PHP are.
For web application, framework is important consideration than language. If language is very powerful but don't have good web framework, developing web application immediately become hard and face lot of known complexity.
Think about ruby without rail framework, people start to like it because of rail framework. This is same as java, using only Servlet without Jsp or other framework developing web application will be horrible.
Now come to your point, easy of use always relative- I could not find any end to end framework in LISP family like ruby or python. But I found Clojure reduce lot of complexity in server side. Deployment- it depends on server, not language like java server need war or ear file. Learning- it is also relative but tools some times help like debugging or ide. But most of the lisp family don't have good debugging option.
I'm a fairly advanced hobby programmer. I consider myself capable at Objective-C, Java, some straight C, Python, and general MVC design.
I've written quite a few programs but they have all been relatively self-contained, using external libraries occasionally.
When reading about larger projects, and/or more complicated programs, I hear a lot of language thrown around about "Writing one part in X, and writing this part in Y."
Since I have a lack of experience with this, I was wondering if someone could point me in the right direction. What general designs/mechanisms are employed for applications or projects written in more than one language? What is involved in a "scriptable" design?
Thanks for any guidance on the topic!
-Chase
There is no single "right way". A multitude of approaches exist, including the .NET-way, where all the languages are hosted inside a common runtime environment with well-specified interoperability constraints, and a good old Unix-way, where all the components are supposed to communicate via pipes or sockets, using simple text-based protocols.
For the latter you can read a classic book: http://en.wikipedia.org/wiki/The_Unix_Programming_Environment
Depends on what you need to do. For example if you want to build a poker game online then, most probably you would use java for the application and flash/flex for the interface. Java has the power of the libraries and the flash/flex are quite generally available and offer a rich interface.
If you have a software that receives input from an online application and offers output on a specific output (label printer for example) then your online-ready software (Java/PHP/Python) would best communicate with a specially designed program on the target computer. A program for which I'd use C++ for it's technical power, rigurosity and speed compared to java.
The idea is to identify the languages that suit your purpose best. In my opinion it is ideal that you use one language to do all the stuff, that is why I like java as it seems to fit everything although it has a more or less bad renown for slowness.
I see things in a kind of this way:
1. Engineered, machine oriented stuff then it is C++ (and languages of it's kind)
2. Mobile multifunctional stuff (middle-ware mainly) Java
3. Online , browser based stuff PHP especially for B2C(people oriented) applications
4. Python,Ruby etc are from my point of view somewhere between java and PHP but I never really worked with them so I can not give an exact opinion
You can link them together depending on your needs.
For alot of the tasks I have to do I find myself having to choose between making the program using a Shell Script in Linux or a programming language such as Java or Groovy. Does anyone havce any experience about how I should choose one over the other and why?
Shell scripts are excellent for concise filesystem operations and scripting the combination of existing functionality in filters and command line tools via pipes.
When your needs are greater - whether in functionality, robustness, performance, efficiency etc - then you can move to a more full-featured language. They tend to offer some combination of:
type safety
more advanced containers
better control over variable lifetimes and memory usage
threading
advanced IPC like shared memory and TCP/IP
full binary I/O capabilities, memory mapped file access etc.
access to OS APIs and myriad powerful libraries
better readability and maintainability as the project size increases
support for more advanced programming paradigms: Object Orientation, Functional Programming, Generative Programming etc.
better error-checking before your program starts running, hence less dependent on test case coverage
#Tony provides an excellent list of pros and cons. I would add one more general point - shell scripts, because they are so handy, risk displaying the "there is nothing more lasting than a temporary solution" characteristic with all the attendant problems of maintenance when somebody else needs to use it.
Shell script is the most intuitive way to have a "glue" on your system. However, it does not have some useful concepts, like inheritance and modularization, that languages like Python (which is very used to "glue" systems too) have.
True, the use of language depends basically on the task you are trying to do. For the most cases I've worked, shell script worked well, although I'm using a lot of Python to accomplish system related tasks. I don't think that Java would be an alternative in this case. Probably Groovy would be, but not Java (I mean Java as a language, not Java as platform.)
In a sysadmin view, I think Python and Ruby are awesome languages. Not only because of dynamic typing and the lack of need to be compiled, but because tools like Fabric, Capistrano, Puppet, and a lot of others which makes a sysadmin's life a lot easier :-)