steveh2009
2019-6-10 12:25:05

I have a string that I’d like to split where the sep is a \0 character. (string-split “1\02\03\0” "\0" ) doesn’t give me what I expected (“1” “2” “3” ). Thanks for the fix.


alexknauth
2019-6-10 12:42:30

The string "1\02\03\0" might not be what you expected, maybe you meant "1\0002\0003\000", or equivalently "1\x002\x003\x00"

The docs section Reading Strings says this about the \<digit> forms: > A longer form takes precedence over a shorter form

Which means that when \0 is followed by another digit such as 2, it’s interpreted as \(02) not (\0)2


steveh2009
2019-6-10 12:49:09

This is a series of ints, doubles, chars and strings sent over a TCP connection by the Interactive Brokers TWS API. The separator is ’\0’ between every one of these pieces of information. So I’ll have to read char by char, create my own split function.


alexknauth
2019-6-10 12:51:26

Wait, when you print the string, does it show "1\u00002\u00003\u0000", or does it show "1\\02\\03\\0"? One backslash or two?


alexknauth
2019-6-10 12:52:34

If it’s two backslashes the relevant example is (string-split "1\\02\\03\\0" "\\0")


alexknauth
2019-6-10 12:57:33

Or if its one backslash, then the relevant example is (string-split "1\0002\0003\000" "\000")


alexknauth
2019-6-10 12:59:32

Is the separator a null character, or is it a backslash character followed by a 0 character?


steveh2009
2019-6-10 13:41:01

’\0’ is how I see the separator being expressed in other reference language implementations of the API. It’s the NUL character.


steveh2009
2019-6-10 13:41:49

Same character used in the C language to terminate a string.


alexknauth
2019-6-10 13:42:45

Okay. The way you represent the NUL character in the reference language is \0, but in Racket it needs to represented by \000 or \x00 etc.


steveh2009
2019-6-10 13:47:21

(string-split “1\0002\0003\000” "\000" ) works. I’ll try it out on the real data coming across the net connection later today. Thanks!


florence
2019-6-10 14:36:35
> (angle 0)
; angle: undefined for 0 [,bt for context]
> (angle 0.0)
0
> (angle 0+0.0i)
0.0

floating point & complex numbers make my head hurt sometimes. (I think the most suprizing thing is that (angle 0.0) gives exact zero)


florence
2019-6-10 14:36:55

oh hey TR gets (angle 0) wrong


jacobm
2019-6-10 14:40:10

@jacobm has joined the channel


soegaard2
2019-6-10 14:47:10

@florence The racket docs are too precise with regards to angle. (I am comparing with http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_idx_576 )


soegaard2
2019-6-10 14:47:51

And I don’t understand why (angle 0.0) is excact 0.


florence
2019-6-10 14:48:26

Probably because it is a polar coordinate with a very very small radial value on the positive x axis


florence
2019-6-10 14:48:33

meaning it has a defined rotation of 0


florence
2019-6-10 14:48:43

(I would have expected it to be 0.0 as well though)


florence
2019-6-10 14:49:01

since you cant have mixed exact/inexact complexes


florence
2019-6-10 14:51:12

could be a bug, but iirc exact zero shows up in a few surprising places


soegaard2
2019-6-10 14:51:36

I suppose 0.0 is interpreted to mean that the complex part is exact 0.


soegaard2
2019-6-10 14:52:28

But do complex numbers have separate exactnesses for the real and complex part?


florence
2019-6-10 14:54:18

it looks like they do iff the exact part is zero?

> 0+0.0i
0+0.0i
> 1+0.0i
1.0+0.0i

soegaard2
2019-6-10 15:01:46

I see that a in R6RS they list as a change: “Scheme’s real number objects now have an exact zero as their imaginary part.”


soegaard2
2019-6-10 15:02:50

In R5RS I believe the (in)exactness described both parts.


samth
2019-6-10 16:12:40

@jacobm welcome!


sorawee
2019-6-11 03:07:01

Curious why Racket provides a mechanism to provide for-meta/for-syntax/for-template. Isn’t provideing at phase 0 relative to the enclosing submodule, and requireing for-meta/for-syntax/for-template at the use-site does the same thing?


lexi.lambda
2019-6-11 03:11:15

for-meta/for-syntax/for-template don’t actually do any phase shifting of bindings when used with provide, they just select which phase the binding to be provided is at.


lexi.lambda
2019-6-11 03:12:04

To make that more concrete, a module can define two different bindings that are both named x at phase 0 and phase 1. (provide x) will provide the phase 0 binding, while (provide (for-syntax x)) will provide the phase 1 binding.


lexi.lambda
2019-6-11 03:12:30

Neither will provide the phase 0 binding at phase 1 or the phase 1 binding at phase 0. Phase shifting at the require site is necessary to do that.