How can you use recursion in lisp (clisp)
to process infix. Example (Thisisinfix '(1 + 2 * ( 1 + 2)) =
7
(Thisisinfix '((1 + 2) * ( 1 + 2))) = 9
I need the general idea of how this works, not the full functional
code.
This also needs to be done not using any kind of variables such as
let, or any sets, only recursion,
however you can define other functions using defun if that
helps.
I am looking to get better with lisp, so once again if you could
explain the steps and/or
rational behind the thought process / calls that would be
great.
//this code is to find factorial of a number
(defun factorial (n) //genral function definition defun (keyword ) factorial (name of function)
//(n) is the parameter of the function
(if (= n 1) //this is the base case for recursion that means if n is equal to 1 then it will execute
1
(* n (factorial (1- n))))) //lets break this call
In lisp two numbers or equation after symbol denotes operation
n*(factorial(1-n))
for n=3 this will run as
3*(factorial(1-3))
2*(factorial(2-1))
//base case is triggered and value goes like from down to up
1
2*(1)
3*(2)
=6
this is how a function of recurrsion looks like and then the breakup of the equation with function calls
hope you got it
Get Answers For Free
Most questions answered within 1 hours.