Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2020-08-22 06:27:48

pi_cubed
Member
From: A rhombicosidodecahedron
Registered: 2020-06-22
Posts: 63

Basic Common Lisp

;Comments in Lisp start with a semicolon.
;Every function, statement, and construct in Lisp must be surrounded by (parentheses). 
;Whitespace is ignored (but the space between arguments is required to parse correctly)
;There are multiple ways to print to the console, but I prefer (print) since it adds a newline after the string.
(print "Hello World!")
;Operations in Lisp use Polish/prefix notation, which means that the operators are placed before the objects, so 1 + 2 + 3 would look like + 1 2 3 
;11 < 20 would look like < 11 20
;So 2+(5*9)/2 would be + 2 / (* 5 9) 2
;Global variables can be defined and changed with (setq var_name "var content")
;Local variables can be defined/changed with (setf local_var "local var content")
;The basic use of the if construct is like this: (if (condition) (execute if true) (execute otherwise))
(if (> 3 20) (print "3 is less than 20"))
;You can't put 2 functions to execute on true since the second function will be executed if false
;The when construct executes function(s) when the statement is true. Basic usage: (when (statement) (action))
(setq i 10)
(when (i > 5) (print "i is greater than 5"))
;Looping
;The loop construct (the most basic form of looping) keeps repeating actions until the return function is called. 
;If the return function is not called then it becomes an infinite loop.
Basic usage: (loop (actions to repeat) (when (condition to end loop) (return)))
(setq a 1)
(loop
(print a)
(setq a (+ a 1))
(when (= a 11) (return))
)
;Resources:
;https://www.tutorialspoint.com/lisp/lisp_quick_guide.htm
;Online IDE:
;https://www.tutorialspoint.com/execute_lisp_online.php

Last edited by pi_cubed (2020-08-22 09:06:30)


e to the i pi plus 1 is zero -Leonhard Euler | a squared plus b squared equals c squared -Pythagoras | Energy equals mass times the speed of light squared -Albert Einstein | i² = -1 | x^2+1=0 x^2=-1 x=i

Offline

#2 2020-09-16 03:58:07

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,956
Website

Re: Basic Common Lisp

Hi pi_cubed;

I am a big fan of functional programming myself.

Have you taken a look at Haskell? I suspect that you might find this language way more interesting and elegant!


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

Board footer

Powered by FluxBB