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

From: A rhombicosidodecahedron
Registered: 2020-06-22
Posts: 115

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"))
;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)
(print a)
(setq a (+ a 1))
(when (= a 11) (return))
;Online IDE:

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



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

Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974

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.


#3 2022-12-15 05:13:54

Registered: 2022-12-15
Posts: 2

Re: Basic Common Lisp

I never knew this coding language but it sounds cool

Hello smile


Board footer

Powered by FluxBB