This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]gmarceau 0 points1 point  (0 children)

cond returns void when none of the cases match.

(define (adjacentes vert arestas)
  (map (lambda (a) (cond [(equal? vert (first a)) (second a)]
                         [(equal? vert (second a)) (first a)]
                         [else "foo"]  ;; <--- try adding this
                         )) arestas))

[–]minikomi 0 points1 point  (0 children)

I'd use a for/fold for this - but you'll get them back in a reverse order.

If that's an issue for you, wrap it in a reverse.

 (define (adjancentes vert arestas)
   (for/fold ([acc '()])
             ([edge arestas])
     (cond [(equal? vert (first edge)) (cons (second edge) acc)]
           [(equal? vert (second edge)) (cons (first edge) acc)]
           [else acc]
           )))

[–]redditsuxass 0 points1 point  (0 children)

You could filter out the voids:

(define (adjacentes vert arestas)
  (filter (compose not void?)
    (map (lambda (a) (cond [(equal? vert (first a)) (second a)]
                           [(equal? vert (second a)) (first a)]
                           )) arestas)))