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
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.
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.
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.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I would like some practical guidance on when I should use a Domain Specific Language. I have found resources about advantages and disadvantages, but what kind of project would warrant its use?
It seems like there is a big investment in time to create and maintain a DSL, so in what application space would I get a productivity return on my time investment?
Edit: It seems the most common use of DSL is for file formats for persisting data state, what about using a DSL for program logic and structure(perhaps code generation)? When is this feasible?
Edit #2 I am mainly asking about when is creating a specific DSL worthwhile. Of course we should use existing DSLs as much as possible to save time.
There are very few good reasons for creating yet another DSL. The world is fat with special-purpose languages.
Think along with these lines.
Solve the problem with a general-purpose language such as Python, Java, C++.. whatever.
Optimize that solution to factor out the common features and build a really nice, really elegant, really extensible class library.
Optimize that class library to emphasize "orthogonality". Make sure all features work well together, without any problems.
If you need simplification of the syntax only, create a scripting wrapper around your nice class library. This is your DSL. For Python, this is easy -- it's already a dynamic language. For Java, there are things you can leverage. For C++ it can be a bit of work to build this flexible scripting environment.
If you still need further optimization, consider writing a compiler for your DSL.
The ACM Computing Surveys article When and How to Develop Domain-Specific Languages provides advice on just this topic, as does Martin Fowler's 2010 book Domain-Specific Languages.
Firstly, I would use a DSL when the problem domain your developing against is a widely well known domain, and some business experts of that domain have already went through great lengths to build such a DSL so that you wouldn't have to go through the lengths yourself to solve all the problems they have already figured out.
If you're thinking of creating a DSL, I would consider doing so if your business is done in a very particular area, and you spend the majority of your time focusing in a specific problem domain. If you bounce around doing applications for multiple problem domains, then I wouldn't advise taking that approach.
For example, if your business is soley in building tax applications, it might be a good idea to build a tax system DSL. This would allow your language not only to be useable by you in your various tax applications, but it would also be marketeable (useable) by other businesses in your industry that want to do similar things that you're accomplishing.
Of course, you have to weight the costs/benefits of building a DSL vs a framework on top of an already existing language.
One situation that comes to mind is when the requirements requires a very high or improbable level of customization/configuration. So you would provide a kind of scripting model against a DSL instead.
Takes a car assembly "arm" for example, providing a configuration model to support various factory configurations would be impossible. (detect this, don't detect that, when this happens do this ... etc.)
But compiling a new application with specialized logic for each customer is probably not a good way to go. So in this case, you create a little framework that would becomes a kind of DSL, and then for each robotic arm you sells, you write a little app in your DSL and save it along with the core software that would compiles and runs your DSL scripts instead. Or better yet, tools to program the DSL are included along with the robotic arm so your customer can "program" the arm themselves in the DSL you created.
One real world examples that comes to mind is Yahoo Pipes (you could think of it as a DSL) or the robots.txt directive for automated web crawler for example. They may not be a full-blown DSL but they demonstrate where DSL might be useful.
Well, someone has to say it, so here goes:
Lisp is regarded by some as the domain specific language for any domain. A well-supported and very extensible DSL at that.
In some cases, fashioning a DSL from Lisp (or a similar language such as Haskell) could actually provide a lot of power with minimal effort, and thus would be quite worthwhile. DSLs do not always need to be big maintenance burdens.
The most obvious is you should definitely use them when the language already exists and is well-supported. The prime examples of this are UIL for Motif-based GUI development and make for software builds.
If you have to make your own, I'd say to look for domains a large amount of effort is in just specifying things properly, and where your compiler can't really find most errors, but a domain-specific compiler could. GUIs are a great example, as most of the work is in setting up the layout, and there are generally lots of ways to make syntacticly valid C++ calls that make no sense whatsoever to your underlying GUI system (EG: trying to embed an entire dialog widget inside a button).
I find UIL particularly a huge gain for GUI development because a UIL compiler can find errors in a GUI specification that just look like nice normal compilable code to a C++ compilter. The fact that it is well-supported means that the code is easy to port between platforms, and even GUI builders.