C# in front of aritmethic operation + let issue

Discussion of Common Lisp
Post Reply
kapalua
Posts: 7
Joined: Tue Feb 16, 2010 3:32 am

C# in front of aritmethic operation + let issue

Post by kapalua » Thu Mar 18, 2010 9:03 am

(defun x (a b c)
(let (square (sqrt (- (* b b) (* (* 4 a) c)))) (list square))

This code always produces (NIL) as output. Can't figure out why....

(defun x (a b c)
(sqrt (- (* b b) (* (* 4 a) c))))

This code returns ,with 1 2 3 as input, this strange looking output: #C(0 2.828427)

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: C# in front of aritmethic operation + let issue

Post by ramarren » Thu Mar 18, 2010 10:33 am

kapalua wrote:This code always produces (NIL) as output. Can't figure out why....
It would be more obvious if you indented it properly:

Code: Select all

(defun x (a b c)
  (let (square
        (sqrt (- (* b b) (* (* 4 a) c))))
    (list square)))
You are binding two variables, 'square' to NIL and 'sqrt' to some value, and then return the list with one element, the value of 'square', which is NIL. The Hyperspec shows the syntax for all standard operators, including LET. It is a good idea to learn to read the notation, which is pretty similar to a variant of Backus-Naur Form.
kapalua wrote: This code returns ,with 1 2 3 as input, this strange looking output: #C(0 2.828427)
'#C(...)' is a syntax for complex number literals. A square root of a negative number is a complex number. The specification even specifies the branch cut.

Post Reply