Exploring LISP programming

Search for a command to run...

No comments yet. Be the first to comment.
I'm using this space to highlight all of my best tweets. Also, you can check out my Polywork profile at timeline.vphreak.net Programming Concept in ASL https://twitter.com/vphreak/status/1358810584158937094?s=20 https://twitter.com/vphreak/status/...
On Twitter, I often get this question: subtitles are available and why not use them? The reason some people are asking because they do not understand the benefit of having an American Sign Language interpreter to be available at the live event, on vi...

My world as a deaf person at Apple WorldWide Developer Convention

In life, there is always misdirection everywhere. As a child, I dreamed of becoming a pilot because I remember my mom would take me to the pond and there is an airfield nearby. I watched airplanes taking off. At about 11 years old, I was able to pilo...

As of today, I have never seen any LISP programming language before. I am writing this article while I am learning LISP, why am I doing this? It is because I made a joke on a tweet about JavaScript (ECMAScript 2015) keywords.
On Twitter, @stephenjohnlimb replied and suggested LISP avoid those JavaScript keywords. I told him that I am going to try LISP programming tomorrow, so that's why I am here writing about the experience.
Right now, I'm at google.com looking for a LISP programming resource. @mohjb said that Lisp was the 2nd language (after assembly). Oh boy!
I have been googling around and trying another bunch of stuff and then finally, I found this simple site to learn LISP!
I am on my M1 MacBook Pro and already have brew.sh installed. HomeBrew is awesome because it makes my life easier installing programs to run in the terminal.
Inside the terminal, I only have to type in: brew install sbcl and then bang! It's installed! Also, we have to install a package manager for LISP which is called quickLISP.
curl -o /tmp/ql.lisp http://beta.quicklisp.org/quicklisp.lisp
sbcl --no-sysinit --no-userinit --load /tmp/ql.lisp \
--eval '(quicklisp-quickstart:install :path "~/.quicklisp")' \
--eval '(ql:add-to-init-file)' \
--quit
I am going to read the tutorial and my goal is to print out Hello World from LISP! so I can start somewhere here. I'm opening up the VS Code app to start writing my first Hello World on LISP!
;;; helloworld.lisp
;;; by Paul Sweeney Jr
;;;
;; This is a comment
;;
(format t "Hello, world!") ; this is inline comment
I am saving this as helloworld.lisp
I am not sure, what's next? So, I just type in man sbcl to read the manual on the terminal. I figured out that I can type in sbcl --script helloworld.lisp to run my very first LISP program!
I want to do some math for my LISP program. So, I googled format lisp to find out how to print out numbers. I found the answer and it is (format t "~d" 3) to output a number. You can dive into wiki about format text on LISP
Lisp does have some math functions to use. Those are a few basic examples here.
(+ 3 6) ; 9
(- 1 5) ; -4
(* 3 3) ; 9
(/ 10 2) ; 5
This is where I learned about math at this website: www2.cs.sfu.ca
I am adding my own defined function to my LISP program!
;; functions
;;
(defun add (x y)
(format t "~d" (+ x y))
)
(defun sub (x y)
(format t "~d" (- x y))
)
(defun multiply (x y)
(format t "~d" (* x y))
)
(defun divide (x y)
(format t "~d" (/ x y))
)
(add 1 2)
(sub 1 4)
(multiply 3 3)
(divide 10 2)
I ran the program and here is the result but it's not what I am expecting.
Hello, world!3-395%
I googled on how to add linefeed to my program... here is it! (format t "~d ~%") and whoa! I did it and it works after some struggling.
(format t "~d + ~d = ~d ~%" (values x) (values y) (+ x y))
vphreak@Pauls-MBP lisp % sbcl --script helloworld.lisp
Hello, world!
1 + 2 = 3
1 - 4 = -3
3 * 3 = 9
10 / 2 = 5
So far, I learned how to run LISP program on my computer and output Hello, World!, also added some defined functions with some math. I will come back to LISP someday if I want to learn more.