How do I get the type of a value in Scheme?

前端 未结 4 1615
情话喂你
情话喂你 2021-01-01 13:58

I want a function that gets the type of a value at runtime. Example use:

(get-type a)

where a has been defined t

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 14:46

    To check the type of something just add a question mark after the type, for example to check if x is a number:

    (define get-Type
      (lambda (x)
        (cond ((number? x) "Number")
              ((pair? x) "Pair")
              ((string? x) "String")
              ((list? x) "List")))) 
    

    Just continue with that.

提交回复
热议问题