greatFritz
greatFritz

Reputation: 201

Using Let inside of a if statement

I am writing a code fragment that takes an element in a list and creates a variable with its absolute value. The problem is that DrRacket does not like like how I am using Let. let: bad syntax (missing binding pairs or body) in: (let ((abs (car l))))

(define abs
  (lambda (l)
    (if(>= (car l) 0)
       (let 
           ((abs(car l))))
       (let 
           ((abs(- car l)))))

    )
  )

Thank you

Upvotes: 0

Views: 1818

Answers (1)

Barmar
Barmar

Reputation: 781028

Your let forms have no body in which the variable abs is used.

Using two let expressions is also probably not what you want. You should use one, and then use if when calculating the value to bind the variable to.

(define abs
  (lambda (l)
    (let ((val (if (>= (car l) 0)
                   (car l)
                   (- (car l)))))
      val)
    )
  )

Upvotes: 2

Related Questions