Recently I came across a nice article by Jose Crespo, where the author stresses that the future of programming revolves around the application of math concepts such as Functor, Monads, Folds, etc. In addition, he argues that familiarity with C/C++ is essential in this modern AI age.
The author goes through a toy example that uses time and energy to show how Multiobjective Optimization (MOO) framework can be quite useful in the real world.
I strongly urge readers to go through that article before continuing, since what follows is based on that article.
What impressed me most about the article was the elegant and compact C++ code (using the latest language features) that shows how to use Pareto Front approach to consider both time and energy for arriving at an optimal solution.
Readers may know that my favourite top three programming languages are C++, Common Lisp and Prolog. So when I finished reading that article, I wanted to rewrite the solution in Lisp and Prolog.
Here is the Lisp code:
Here is the program output:
The Lisp program is no less elegant in my opinion! Of course Lisp is a dynamically typed language and hence the performance (space and time) is likely to be marginally inferior to C++ (by the way, LispWorks has a great compiler that can generate optimized native code for the Lisp program). Keeping efficiency aside, the remarkable thing about Common Lisp is its support for Multimethods and Meta Object Protocol (MOP).
Now, let us look at the equivalent Prolog program:
The main predicate follows:
When you run the program, this is the output:
In both Lisp and Prolog, the result matches the C++ output (as described in the article).
I chose Prolog to show that the logic can be implemented in this language too, but it would not be my natural choice for this implementation.
The point is that while C++ is arguably the best language to implement most algorithms, especially with the features available in the recent language specifications, if not running on embedded systems or on resource-critical systems, then languages such as Lisp are equally good choices for implementing such algorithms.
You can download the Lisp and Prolog code here.
Have a nice weekend!
Recent Comments