Как правильно вернуть значение из функции? - PullRequest
1 голос
/ 03 мая 2019

Я пытаюсь рассчитать количество мест, оставшихся в каждом классе, вычитая «Зачисление» из «Вместимости», а затем распечатывая результат в отдельной функции. Однако моя функция открытых мест не возвращает значения, если я не использую функцию дисплея. Как я могу это исправить?

    #lang racket
       ( define course-list (cons '("Dept" "Number" "Section" "Class Nbr" "Capacity" "Enrollment")
                                         '(("CMSC" "201" "1" "1052" 100 30)
                                         ("CMSC" "341" "6" "7447" 40 27)
                                         ("CMSC" "341" "3" "7443" "40" 29)
                                         ("CMSC" "331" "5" "7746" 40 36)
                                         ("CMSC" "331" "6" "7747" 40 "40")
                                         ("CMSC" "471" "3" "8196" 40 31))

                                  )
            )

   (define (open-seats section)
      (for ([e (in-list  course-list)])
        (if (equal? section (string->number (list-ref e 2))) (- (list-ref e 4) (list-ref e 5)) 'something)
       ;(if (equal? section (string->number (list-ref e 2))) (display(- (list-ref e 4) (list-ref e 5))) 'something)
            )
        )
  ;test open-seats          
     (open-seats 1)

  (define (report-open-seats list-of-courses)
    (for ([e (in-list course-list)])
      (if (and (number? (list-ref e 4)) (number? (list-ref e 5))) (displayln(string-append (list-ref e 0) (list-ref e 1) " (Section " (list-ref e 2) ")=> " (open-seats 1))) newline)
            )
   )

  ; leave the following function call intact
  ;(report-open-seats course-list)

1 Ответ

1 голос
/ 03 мая 2019

Чтобы составить список предметов, вы можете использовать для / list , например:

(define (open-seats section)
  (for/list ([e (in-list  course-list)]
             #:when (equal? section (string->number (list-ref e 2))))
    (- (list-ref e 4) (list-ref e 5))))
...