Back from the past
Common Lisp
We will get right to the topic; modern day programming has lot to thank for their predecessors. These days languages and programmers who use those languages have far greater flux than what languages had in early dawn days of programming.
Lisp is one such language which has seen the dawn, and noon all of the day. It has been a tool that most students of computer science must have grasped; well grasped strong through the years of education. We hope this is still taught. However, when then land in a job it is all lost. The principles apply but the language is lost.
Programming for profit and for business involves completely different technology stack. This is talked a lot in different platforms as gap between education and business. To address that gap most often the curriculum gets changed and often business does not take that critical step to stay close to what is taught. Do take cognisance of the number of frameworks that have sprouted and probably many have been already abandoned.
Lisp has seen those phases and fortunately have survived for this dispatch to mention it.
What can you build with Lisp
Everything! Is the simplest answer. But then you ask; Is there an ecosystem that accelerates you to run faster? Like npm, nuget, maven. Well there is but not that much to talk about. That dear programmers is the one common reason why it is not commonly used language in business. If we could say one thing and do not expand upon the reasons for it to be safe; it is language for programmers not for developers, not yet.
You can write web server, do systems programming, make Lisp play in tandem with C, C++, Java etc. So now you see the possibilities. One of the sad reality that is buried deep down the internet’s past is – Lisp is the go-to language for Artificial Intelligence. Unfortunately budding developers will spend time learning Python.
Burying the sentiments
(defun pattern-matcher (pattern input &optional (bindings no-bindings))
“Match pattern against input in the context of the bindings”
(cond ((eq bindings fail-to-match) fail-to-match)
((variable-pattern pattern)
(match-variable pattern input bindings))
((equal pattern input) bindings)
((segment-pattern-p pattern)
(segment-matcher pattern input bindings))
((single-pattern-p pattern)
(single-matcher pattern input bindings))
((and (consp pattern) (consp input))
(pattern-matcher (rest pattern) (rest input)
(pattern-matcher (first pattern) (first input)
bindings)))
(t fail-to-match)))
You will have some idea about what the above program does even before we start laying out the language constructs. Such is the power of expressing thoughts via Lisp.
Language constructs
Lisp i.e. List Processing is one such rare language which has very few rules and construct for you to remember. Thus, was aeasy target for academia to use it in teaching. Following are the rules
Comments
One of the most important thing one must understand while starting language is comments. As you read and obviously write more programs you will write comments. It is important that you identify them quickly plus it is not hard to remember them as well –
;; Comment that is written within 1 line
#| Comment that is
#| across multiple lines
Functions
Lisp works with macros, thus functions are defined using a macro – `deffun`
( deffun <function name> ( <parameters> ) )
That is all you need to know while defining functions. They are called using a syntax
(funcall #'<function name> <parameters>)
or
(apply #'<function name>(<parameters>))
Needless to say parameters are comma separated. Function name can have hyphens to separate words.
Variables
They are lexically scoped as in many other languages that you are aware of. Two types of variables are commonly used in Lisp – Local and Global.
; local variable declaration
let ((pi 3.14))
; another example of local variable
let* ((pi 3.14), ((area-of-circle (*, pi, (^, radius,2) ) ) ) )
; global variable declaration
(defparameter *life* “Circle of life”)
; another approach to declare global variable is
(defvar *life*)
(let (*life* “Full of fun”) )
By no means we are limiting the language to just this. There is more, control statements, class, methods, generics, macros etc. But here is the thing – All use the same principles described above. You might have noticed the similarity already
( something ( something ) )
The language uses only 1 type of bracket; rounded bracket. Then there is an operation, it could be a call to macro or definition of function or class etc with its name. Then again the rounded bracket with more parameters or chaining of further operation. Psst; closures!.
We conclude this dispatch here and will continue to voice over the rant we had while burying the sentiments for the next dispatch.
Recent post
Archives
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- October 2023
- June 2023
- March 2023
- February 2023
- January 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- January 2021
- December 2020
- October 2020
- August 2020
- June 2020
- May 2020
- April 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019