<![CDATA[Math Is Fun Forum / Basic Common Lisp]]> 2020-09-16T15:58:07Z FluxBB https://www.mathisfunforum.com/viewtopic.php?id=25837 <![CDATA[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!

]]>
https://www.mathisfunforum.com/profile.php?id=95904 2020-09-16T15:58:07Z https://www.mathisfunforum.com/viewtopic.php?pid=415064#p415064
<![CDATA[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``````
]]>
https://www.mathisfunforum.com/profile.php?id=222180 2020-08-22T18:27:48Z https://www.mathisfunforum.com/viewtopic.php?pid=414744#p414744