0

I am trying to write a scheme program which is Dijkstra's Shortest Algorithm. In a procedure when I am relaxing the edges I get the error that

;Ill-formed special form: (let (...) ())

Code of my procedure is,

(define relax-over-edge 
   (lambda (distlist edge min-pair)
     ( if (null? distlist)
       ()
       (if (equal? (cadr edge) (caar distlist)) 
            (if (> (cdar distlist) (+(cdr min-pair) (cddr edge)))
                (let (((cdar distlist) (+ (cdr min-pair) (cddr edge)) )) ())
                ()
            )
            (relax-over-edge (cdr distlist) edge min-pair)
        )
     )  
   )
)

Thank you very much already.

KlaatuSama
  • 21
  • 2

2 Answers2

5

Of course this is an ill-formed let:

(let (((cdar distlist)
       (+ (cdr min-pair) (cddr edge)))) 
  '())

What were you trying to do? assigning the (+ (cdr min-pair) (cddr edge)) expression to the element in the (cdar distlist) position? that's definitely not the way lists work in Scheme (at least not the immutable lists), you can't assign a value to a position like that. Besides, only variables can be declared in the left side of a binding in a let expression, and not other expressions (like in your code).

You'll have to rethink your algorithm, either use a vector (which does support in-place modification of an element in a given position), or check the documentation of the Scheme interpreter you're using, to see what does it say about mutable pairs and lists.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
1

You're getting the error because the body of your let form is just (), which is not a valid expression that can be evaluated. Quoting the guile manual:

syntax: (let bindings body) BINDINGS has the form

      ((VARIABLE1 INIT1) ...)

 that is zero or more two-element lists of a variable and an
 arbitrary expression each.  All VARIABLE names must be distinct.

...

    * The expressions in BODY are evaluated in order, and the value
      of the last expression is returned as the value of the `let'
      expression.
gcbenison
  • 11,723
  • 4
  • 44
  • 82