Lisp: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
No edit summary
Line 22: Line 22:
<syntaxhighlight lang="lisp">
<syntaxhighlight lang="lisp">
(print "Hello World")
(print "Hello World")
</syntaxhighlight>
=Variables=
To declare
<syntaxhighlight lang="lisp">
(defvar *my-variable* "Hello World" )
</syntaxhighlight>
It is common practice for local variable to have asterixes<br><br>
We can declare variables for functions too, in this case read-data now is the built-in read function.
<syntaxhighlight lang="lisp">
(defvar *read-data* (read))
</syntaxhighlight>
=Functions=
We can of course define functions. So putting the above together we are prompted for a value and it prints it to the terminal
<syntaxhighlight lang="lisp">
(defvar *read-data* (read))
(defun read-and-print (name)
  (format t "Read and Print value is ~a ~%" name))
(read-and-print *read-data*)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 01:24, 7 September 2024

Introduction

This is a quick tour on lisp. I decided to look at this because of the build a compiler youtube by lens_r which made me feel I am missing something. This has been rabbit hole which I have fallen done

Concepts

This is my view and maybe wrong but to me the first thing I noticed was the huge amount of parentheses which are involved. It made the language look really ugly and made me feel don't do this. I think I have touched this in the past because of a gun to my head. That said, like people, you probably need to understand before having a view, and even then, not for you is a better view and it is negative. So here is the half day I spent

Comments

;;;; Describe Program 4 semi colons
;;; Comments

;; Indented Comments

#|| Multiline
My Comments
||#

Format to terminal

(format t "Hello World ~%")

Print

(print "Hello World")

Variables

To declare

(defvar *my-variable* "Hello World" )

It is common practice for local variable to have asterixes

We can declare variables for functions too, in this case read-data now is the built-in read function.

(defvar *read-data* (read))

Functions

We can of course define functions. So putting the above together we are prompted for a value and it prints it to the terminal

(defvar *read-data* (read))

(defun read-and-print (name)
  (format t "Read and Print value is ~a ~%" name))

(read-and-print *read-data*)