Evalating Expressions

Discussion of Common Lisp
Post Reply
vignezds
Posts: 7
Joined: Tue Nov 18, 2014 4:26 am

Evalating Expressions

Post by vignezds » Tue Nov 18, 2014 4:31 am

Hello Everyone,
I am Very much new to LISP, I don't have basic knowledge in LISP but I supposed to do project in LISP. I need to evaluate given expression(Just addition, Subtraction, Multiplication, Division), kindly help me to do this. I am using LISPWORKS as tool.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Evalating Expressions

Post by Goheeca » Tue Nov 18, 2014 8:19 am

You don't even specify the input!
However, I provide a generel answer.

If you have an arithmetic expression in s-expr form, you can easily evaluate it:

Code: Select all

(defvar arithmetic-expression '(+ 1 (* 5 6)))
(eval arithmetic-expression) ; = 31
For the standard infix notation of arithmetic expression, feel free to look at general description of Shunting yard algorithm.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Evalating Expressions

Post by Goheeca » Tue Nov 18, 2014 8:25 am

And on Rosetta Code, you have an implementation in CL of the arithmetic expression evaluation. Consider it as an inspiration only.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

vignezds
Posts: 7
Joined: Tue Nov 18, 2014 4:26 am

Re: Evalating Expressions

Post by vignezds » Thu Nov 20, 2014 11:15 am

Thank you so much, I got complete idea over it.
Goheeca wrote:And on Rosetta Code, you have an implementation in CL of the arithmetic expression evaluation. Consider it as an inspiration only.

Post Reply