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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to return value from debounced function in javascript?

分類Dev

How to return value from a child process in a function?

分類Dev

How to get a return value from a connect function

分類Dev

How to return value from an extended casperjs function?

分類Dev

How to return one and only one value from a PowerShell function?

分類Dev

How to get the single return value from mysql stored function in php

分類Dev

How can I return a value from a parent function in Node?

分類Dev

PHP: how to return counter of value from recursive function?

分類Dev

How to properly return value from a data inside the function

分類Dev

How to return a value from a async function in array.map in javascript?

分類Dev

Lua: How to assigned a return value from a function to a local value of a different function in lua

分類Dev

How to return a value from a function , use that value to make a math formula and push the solution(key/value) to an array of objects?

分類Dev

How to return a list from a function?

分類Dev

How to return value from a Promise

分類Dev

Return value from a function callback in a for loop

分類Dev

Cannot return value from a function in other file

分類Dev

getting address of pointer from function return value

分類Dev

How to capture function return value with if condition

分類Dev

How to unwrap return value at function call?

分類Dev

How to process return value of main() function?

分類Dev

Python: How to obtain return value from only one function (out of several executed with asyncio.gather)

分類Dev

Return value from setInterval() function called from html

分類Dev

How to get the return values from a function?

分類Dev

React native how to return a string from a function

分類Dev

how to return observable from function that has a promise

分類Dev

How to return result in series from R function?

分類Dev

How to return value from JavaScript using Selenium?

分類Dev

Get return value from c# function and display in html

分類Dev

Using SQL Query to return value from BigQuery User Defined Function

Related 関連記事

  1. 1

    How to return value from debounced function in javascript?

  2. 2

    How to return value from a child process in a function?

  3. 3

    How to get a return value from a connect function

  4. 4

    How to return value from an extended casperjs function?

  5. 5

    How to return one and only one value from a PowerShell function?

  6. 6

    How to get the single return value from mysql stored function in php

  7. 7

    How can I return a value from a parent function in Node?

  8. 8

    PHP: how to return counter of value from recursive function?

  9. 9

    How to properly return value from a data inside the function

  10. 10

    How to return a value from a async function in array.map in javascript?

  11. 11

    Lua: How to assigned a return value from a function to a local value of a different function in lua

  12. 12

    How to return a value from a function , use that value to make a math formula and push the solution(key/value) to an array of objects?

  13. 13

    How to return a list from a function?

  14. 14

    How to return value from a Promise

  15. 15

    Return value from a function callback in a for loop

  16. 16

    Cannot return value from a function in other file

  17. 17

    getting address of pointer from function return value

  18. 18

    How to capture function return value with if condition

  19. 19

    How to unwrap return value at function call?

  20. 20

    How to process return value of main() function?

  21. 21

    Python: How to obtain return value from only one function (out of several executed with asyncio.gather)

  22. 22

    Return value from setInterval() function called from html

  23. 23

    How to get the return values from a function?

  24. 24

    React native how to return a string from a function

  25. 25

    how to return observable from function that has a promise

  26. 26

    How to return result in series from R function?

  27. 27

    How to return value from JavaScript using Selenium?

  28. 28

    Get return value from c# function and display in html

  29. 29

    Using SQL Query to return value from BigQuery User Defined Function

ホットタグ

アーカイブ