Wednesday, January 24, 2018

Important programming languages to learn (a break from C++17 and friends)

A break from C++17 and friends. If I had to name the programming languages that are important to learn I would include LISP somewhere near the top of the list (no pun intended). One thing that speaks in favor of LISP is the fact that learning it will develop your programmer mind in ways that other programming languages will not. The other factor in favor of learning this language is the doors it will open for you. Armed with your knowledge of LISP you will be able to use a great number of good tools and platform. In Linux for example there is a large number of implementations available (Steel Bank Common Lisp, GNU Common Lisp and possibly others). LISP is also available on the Java VM in the form of Clojure, ABCL, KAWA (a Scheme) and possibly other implementations. For a few years now Lisp is also an option when programming for the Erlang VM as LFE (Lisp flavor Erlang). Erlang has a Virtual machine (BEAM) that has interesting characteristics and is certainly worth taking a look at. However, Erlang (the primary language for this platform) is not a language that has the same availability as Lisp so learning Erlang might be considered too large an investment. Fortunatly with a dialect of Lisp available you now have an interesting alternative. Here is me fooling around in the Erlang LFE REPL:
Erlang R14B04 (erts-5.8.5) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

lfe: (set mytuple #(1 "Winston Churchill"))
#(1 "Winston Churchill")
lfe: (element 1 mytuple)
1
lfe> (element 2 mytuple)
"Winston Churchill"
lfe: (defun nth (n atuple) (element n atuple))
nth
lfe: (nth 1 mytuple)
1
lfe: (nth 2 mytuple)
"Winston Churchill"
lfe: (defun doubleit (x) (* 2 x))
doubleit
lfe: (doubleit 2342342342)
4684684684
I create a tuple and peek at the values inside using the 'element' function. Since 'element' feels a little long I define a function named 'nth' to mimic a function available for List in other Common Lisp implementation, I also create a simple function 'doubleit'. Here is me fooling around in the GNU GCL REPL:
GCL (GNU Common Lisp)  2.6.7 CLtL1    Feb  1 2012 09:07:26
Source License: LGPL(gcl,gmp), GPL(unexec,bfd,xgcl)
Binary License:  GPL due to GPL'ed components: (XGCL READLINE UNEXEC)
Modifications of this banner must retain notice of a compatible license
Dedicated to the memory of W. Schelter

Use (help) to get some basic information on how to use GCL.
Temporary directory for compiler files set to /tmp/

::(defvar *mylist*)

*MYLIST*

::(setf *mylist* '(1 "WInston"))

(1 "WInston")

::(nth 1 *mylist*)

"WInston"
>>(nth 0 *mylist*)

1
::(defun doubleit (x) (* 2 x))

DOUBLEIT
::(doubleit 4598349)

9196698
Clojure alone is enough of a reason to learn Lisp. Even more so now that Clojure Script is available.

No comments:

Post a Comment