How to correctly return value from function?

Bob Smith

I am trying to calculate the seats left in each class by subtracting "Enrollment" from "Capacity" and then printing the result in a separate function. However my open-seats function returns no value unless I use the display function. How can I fix this?

    #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)
rain1

To make up a list of the items you can use for/list like this:

(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))))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Correctly return Promise value from recursive function

How to correctly return the result from Cloud Function?

How to correctly return and display string value if function does not return true?

How to return value from this function?

How to return a value from a function

How to return a value from a function if no value is found

How to return dynamically allocated array from function and correctly delete it

How to return response from async function correctly & push it into another object

How do I return value correctly from CloudKit completionHandler

How to return a value from a function in Java?

How do I return value from this function

How to return by value from native function?

How to return a value from a function of type `LPCTSTR`?

How to return value from function to main thread?

How to return custom value from function call?

How to get a return value from a connect function

How to return value from a function in gwidgets

How to capture return value from function in vim?

React, how to return a value from function to component?

How to return the value resolved from promise in function?

How to return value from debounced function in javascript?

How to return a value from an EventEmitter function?

How to return a value from a stored procedure (not function)?

How to return value from an extended casperjs function?

How to return value from an asynchronous callback function?

How to return value from exec in function?

How to return a string value from a Bash function

How to return value from callback function?

How to return a value from a function based on conditions