1
votes

I am working on an assignment in racket. It looks at a list, does a simple math calculation, then outputs the info from the list. Heres the function that does the outputting.

(define (report-open-seats list-of-courses)
(for/list ([e (in-list course-list)]
  #:when (and (number? (list-ref e 4)) (number? (list-ref e 5))))
            (displayln (open-seats e))))

The #:when is supposed to just make sure there's numbers where I'm expecting numbers. Open-seats returns a string. Here is my output.

CMSC201 (Section 1)=> 70
CMSC341 (Section 6)=> 13
CMSC331 (Section 5)=> 4
CMSC471 (Section 3)=> 9
'(#<void> #<void> #<void> #<void>)

How can I get rid of the junk # output? All I want is the first 4 lines of output not the 5th. I've noticed that if I change the code to this:

(displayln (open-seats e)))"")

It changes the output to:

CMSC201 (Section 1)=> 70
CMSC341 (Section 6)=> 13
CMSC331 (Section 5)=> 4
CMSC471 (Section 3)=> 9
""
2
Just use for instead of for/list - Atharva Shukla

2 Answers

2
votes

As the comment says, you just need to do this:

(define (report-open-seats list-of-courses)
  (for ([e (in-list course-list)]
        #:when (and (number? (list-ref e 4)) (number? (list-ref e 5))))
    (displayln (open-seats e))))

That's because for/list will return a list, if you need to iterate and print the values in a list, without returning anything, then you must use for.

0
votes

The #<void> is the return value from displayln. Return the values directly without displaying them, then the repl will print them.

(define (report-open-seats list-of-courses)
(for/list ([e (in-list course-list)]
  #:when (and (number? (list-ref e 4)) (number? (list-ref e 5))))
            (open-seats e)))