nrc / darkly

40 stars 2 forks source link

Compare to mmun's spec #7

Open nrc opened 7 years ago

nrc commented 7 years ago

https://gist.github.com/mmun/bffc62a5eb6ad648b7f7b2825364962c (cc @mmun)

nrc commented 7 years ago

I just pushed a commit which adds the expression form. It always returns a tuple of results, which is not great for single values, but that should be fairly easy to add. E.g.,

    let x: i32 = scan!("hello {}"); // todo
    let x: (i32,) = scan!("hello {}"); // works
    let x: (i32, i32) = scan!("hello {}"); // works
mmun commented 7 years ago

Awesome. I came to the same conclusion after several months of using scan!("hello {}").0 in my own library -- supporting singular values is just way more ergonomic!

mmun commented 7 years ago

@nrc Should it be "hello {} {}" in your third line? Or am I misunderstanding.

nrc commented 7 years ago

it should

mmun commented 7 years ago

Another thing that comes up often is scanning individual characters. E.g. I'd expect that for the input string "123",

let (x: char, y: u8) = scan!("{}{}") // x == '1', y == 23
nrc commented 5 years ago

We could allow an empty format string in the statement form too: scanln!(x: i32) is equivalent to scanln!("{}", x: i32)

nrc commented 5 years ago

I came to the same conclusion after several months of using

Single values are not tuple-wrapped now