Fork me on GitHub
#beginners
<
2016-03-30
>
antonshwab10:03:59

What is the correct way to convert strings to numbers and back?

bronsa10:03:24

read-string (or clojure.edn/read-string if you can't trust the data), or using one of the parse methods of Long or Double

jmayaalv10:03:18

(read-string "1")
=> 1

(str 1)
=> “1”

urbanslug14:03:26

Is there a way for me to just peek into an even channel?

noisesmith15:03:21

urbanslug: this is not part of the official semantics because logic that relies on peek being helpful is likely to deadlock or hit race conditions

noisesmith15:03:37

urbanslug: the operations provided are carefully crafted to avoid the pitfalls of concurrency

noisesmith15:03:49

that said, there's probably some evil way to do it anyway, let the coder beware

noisesmith15:03:56

instead, you can use one of the variations of alts! where one channel might have the data you are interested in, and the other immediately returns nil, then check the value and which channel it came from

noisesmith15:03:16

that can replace some usages of a "peek" logic

bronsa15:03:43

@noisesmith: how would peek cause deadlocks? I remember reading a ML discussion about it but I don't remember

noisesmith15:03:24

bronsa: between peeking and the execution of your next channel operation, the status of the channel (empty vs. full) could have changed - maybe this can only cause races but not deadlocks though?

noisesmith15:03:54

@bronsa: it's probably safer / more conservative to say "CSP is a formally proven system for concurrency with no peek operation defined" and leave it at the fact that when you add peek, the proven properties of CSP are no longer guaranteed

bronsa15:03:03

I see, thanks

noisesmith15:03:26

I'm probably going to wake up at 3 am and have a full model for how to provoke a deadlock using peek

bronsa15:03:47

haha, looking forward to it then simple_smile