0

This is what works:

(define obj1 (maak-object (coord 1 1) #f #f #t))
(set! karaktersenobjectenlijst (append karaktersenobjectenlijst
                                  (list (list 'object obj1)))))

> (cadar karaktersenobjectenlijst)
obj1
> (positie obj1)
{1 . 1}

This doesn't work:

> (positie (cadar karaktersenobjectenlijst))
. . vector-ref: expects type <vector> as 1st argument, 
. .   given: obj1; other arguments were: 0

How can I make it use the value obj1 when (cadar karaktersobjectenlijst) is evaluated?

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
Vincent
  • 11
  • 1
  • What are `maak-object` and `positie`? – Tim Feb 11 '11 at 14:55
  • (define (maak-object positie blokkerend? breekbaar? water?) (vector object-tag positie blokkerend? breekbaar? water?)) – Vincent Feb 11 '11 at 15:11
  • (define (positie k) (cond ((karakter? k) (vector-ref k 6)) ((object? k) (vector-ref k 1)))) – Vincent Feb 11 '11 at 15:12
  • Can you be more specific about the program you're writing? There are a lot of undefined variables here: `object-tag`, `karakter?`, `coord`, `karaktersenobjectenlijst`. Providing what seems like reasonable values for them doesn't produce results like what you're seeing. – Sam Tobin-Hochstadt Feb 11 '11 at 16:17
  • I think those variables don't really matter, do they? – Vincent Feb 11 '11 at 16:23
  • 2
    What scheme system is this? I'm most suspicious about the value that prints as 'obj1'. Also, 'cadar' is going to select from the first element of the karaktersenobjectenlijst; if it's not empty to begin with, then the stuff you're adding makes no difference. Sam's right; there are too many dangly bits here to make sense of this request. – John Clements Feb 11 '11 at 16:54
  • @Vincent, I can't try running your program without those variables. If they're too complicated to include here, try to provide a smaller example of your question. – Sam Tobin-Hochstadt Feb 15 '11 at 14:08

1 Answers1

1

The code is correct. I have replaced your functions with some dummys and it evaluates fine:

(define coord cons)
(define maak-object list)
(define positie car)

(define obj1 (maak-object (coord 1 1) #f #f #t))
(define karaktersenobjectenlijst '())
(set! karaktersenobjectenlijst (append karaktersenobjectenlijst
                                       (list (list 'object obj1))))
(cadar karaktersenobjectenlijst)

(positie obj1) #-> (1 . 1)
(positie (cadar karaktersenobjectenlijst)) #-> (1 . 1)

The problem must be in your library code or the way you use it. The Scheme evaluation works fine.

ceving
  • 21,900
  • 13
  • 104
  • 178