ServiceLogos icon indicating copy to clipboard operation
ServiceLogos copied to clipboard

[Request] LISP

Open Sinihopea opened this issue 1 year ago • 5 comments

Check for duplicates

  • [x] Checked

Service Name

LISP

Comment

I hope to share some basic information to give understanding and inspiration for this programming language. It should be noted that more appropriately understood LISP is a family of programming languages based on similar syntax, grammar and libraries.

Existing logos

240px-Lisp_logo svg

More proper official logo for ANSI Common LISP featuring the lambda symbol.

IMG_0326

"LISP alien", the mascot character for the programming language was designed by Conrad Barski. It's in public domain and free to use for anyone. Website for logo and resources: https://www.lisperati.com/logo.html

Notably the mascot character's colours, number of eyes and arms change depending on which LISP family of language it is meant to represent. So different variations exist for example for Scheme, Guile, Clojure and Racket to name a few.

Ideal properties

  • Lambda symbol
  • Words such as: CONS, CAR, CDR, CL-USER>
  • Lots of round brackets: ((((((((((((( ^ω^)))))))))))))))))
  • LISP Alien
  • Any kind of S-Expression such as: (+ 1 2).
  • Rough visual estimate of </> in LISP would be (end)

Brief history for inspiration

LISP is one of the oldest high-level programming languages still in use. It was originally created in 1958 by John McCarthy. It is either the second oldest or the third oldest high-level language depending on definition. It is sometimes called "a programmable programming language" due to its powerful macro features, symbolic computation and metaprogramming features which have made it very useful for the AI (artificial intelligence) research.

LISP is (mostly) memory safe language as well depending on implementation due to garbage collection. In LISP the barrier between data and running code is minimal. LISP supports REPL (Read-Eval-Print Loop) style programming where programmer doesn't need to recompile the code after making changes and can witness modifications in real-time as they are written in. Also in LISP major data structures such as the code itself are linked lists.

Programmer can extend the LISP to their specific problem domain(s) to create powerful new programming languages (as LISP dialects such as Scheme or Clojure) to solve issues. Notable software written in LISP include GNU Emacs, NASA Deep Space 1 spacecraft and original Reddit for example.

Innovative features in LISP (to name a few)

  • Metaprogramming
  • Multi-paradigm
  • First-class Functions
  • Higher-order Functions
  • Recursion
  • Dynamic Typing
  • Garbage Collection
  • Homoiconicity
  • First intepreted programming language

Grammar

This is a quick "cheat-sheet" to Common LISP syntax and grammatical notation.

Syntax Meaning
' "Don't evaluate"
'blah Unevaluated symbol
blah Evaluated symbol
(blah) Function call
(defun a (&key (b 1))...) Default parameter values
'(blah) Unevaluated list
'(a . b) Unevaluated pair
"blah" String
3.14159 Number
#' Function object
#\ Character literal
#c or #C Complex number
#b, #x, #o, #nR Numbers in different bases
` Signals that in the expression that follows, every subexpression not preceded by a comma is to be quoted, and every subexpression preceded by a comma is to be evaluated - This helps with creating lists inside LISP macros
, Unquoting an expression in a macro
,@ "Splicing" something into a list in a macro
&rest Indicate "catch-all" parameter in function
&optional Indicate optional parameter in function
&body Same as &rest
:blah Keyword
#:blah Uninterned symbol
foo:bar Access symbol "bar" in a package "foo"
setq Assign value to a variable
setf Like setq, but accepts arbitrary place and form as parameters rather than just symbols
defvar Define global variable, unbound if no value is assigned to the variable
defparameter Define global variable and always assign initial value to it
defun Define function

Code example

This code example can be run e.g. in Steelbank Common LISP intepreter/compiler or any other Common LISP compatible interpreter. Save the contents above into hello.lisp text file and then run... sbcl --script hello.lisp

;; ANSI Common LISP (X3J13)

; Basic math
(+ 1 4 2 3)
(- 2 3 (+ 4 (- 1 2)))
(* 3 2)
(/ 4 1)

; Basic string output
(format t "Hello World~%")

; Convert integer to string and output to stdout with newline at the end of the character stream
(write-line (write-to-string (+ 1 4 2 3 5)))

; Functions
(defun area-circle (rad)
    "Calculates area of a circle with given radius"
   (terpri)
   (format t "Radius: ~5f" rad)
   (format t "~%Area: ~10f" (* 3.141592 rad rad)))

(area-circle 10)

; Push a newline into the standard output stream aka. "TERminate PRInting".
(terpri)

; Typical list of data items
(write (list 1 2 3) :escape t :pretty t)

; Macros
(defmacro set-to-10 (integer-variable)
    (setq integer-variable 10)
    (print integer-variable)
    (fresh-line))

(defvar my-variable nil)
(setq my-variable "List Processing")
(print my-variable)
(set-to-10 my-variable)

; Self-modifying code
(defun foo (x) (+ x 1))
(format t "~d~%" (foo 3))

(defun bar (x) (+ x 2))
(format t "~d~%" (bar 3))

(setf (symbol-function 'foo) #'bar)
(format t "~d~%" (foo 3))

In theory any-kind of computable symbol should be fine. So something like this is possible...

;; Japanese symbols

(defun 月給 (&key アキ マイコ ユリ コナタ)
    (write (list アキ マイコ ユリ コナタ)))

(月給 :マイコ "100円" :アキ "0円" :コナタ "500万円")

(terpri)

Resources

  • https://lisp-lang.org/
  • https://common-lisp.net/
  • https://en.wikipedia.org/wiki/Lisp_(programming_language)
  • https://ja.wikipedia.org/wiki/LISP

Sinihopea avatar Apr 23 '24 06:04 Sinihopea