I used read
to get a line from a file. The documentation said read
returns any
, so is it turning the line to a string? I have problems turning the string "1"
to the number 1
, or "500.8232"
into 500.8232
. I am also wondering if Racket can directly read numbers in from a file.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Check out their documentation search, it's complete and accurate. Conversion functions usually have the form of foo->bar
(which you can assume takes a foo
and returns a bar
constructed from it).
You sound like you're looking for a function that takes a string
and returns a number
, and as it happens, string->number
does exist, and does pretty much exactly what you're looking for.
回答2:
Looks like this was answered in another question:
Convert String to Code in Scheme
NB: that converts any s-expression, not just integers. If you want just integers, try:
string->number
Which is mentioned in
Scheme language: merge two numbers
HTH