name_masked
name_masked

Reputation: 9793

String length in Scheme

I am not able to understand the error with the code below which simply prints the length of the string:

(define codeLen (read))
(display codeLen)
(define code (read))
(display code)
(string-length code)

I am getting an error: string-length: expects argument of type <string>; given a

Upvotes: 0

Views: 3744

Answers (1)

Eli Barzilay
Eli Barzilay

Reputation: 29556

You've probably entered a. read reads an arbitrary piece of s-expression, and in this case, it reads the symbol a. If you enter "a" instead, you will get a string.

But more likely you will want to use the read-line function.

Upvotes: 3

Related Questions