2
votes

If I define a list in scheme like this

(define list '(when i type I 1 23 4 2))

What's the type of the thing (car list) returns? And another question is: can I convert it to the string?

1

1 Answers

5
votes

In the list shown in the question, the car is the symbol 'when. You can verify it, but first let's change the name of the list to something else, for avoiding a name collision with the built-in list procedure:

(define lst '(when i type I 1 23 4 2))
(symbol? (car lst))
> #t

The #t (true) in the last line shows that indeed the first element is a symbol. If you need to convert it to a string, simply do this:

(symbol->string (car lst))
> "when"

EDIT :

Answering the question in the comments, this should work:

(define (isvariable? symbol)
  (and (symbol? symbol)
       (eqv? (string-ref (symbol->string symbol) 0)
               #\?)))