Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's no $ for openArray #7940

Closed
kaushalmodi opened this issue Jun 1, 2018 · 12 comments
Closed

There's no $ for openArray #7940

kaushalmodi opened this issue Jun 1, 2018 · 12 comments

Comments

@kaushalmodi
Copy link
Contributor

import strformat
proc foo(x: openArray[int]) =
  echo fmt"{x}"

Compiling that gives this error:

lib/pure/strformat.nim(268, 13) Error: type mismatch: got <openarray[int]>
but expected one of:
proc `$`(x: string): string
proc `$`(s: WideCString): string
proc `$`[T: tuple |
    object](x: T): string
proc `$`(x: uint64): string
proc `$`(x: int64): string
proc `$`[T, IDX](x: array[IDX, T]): string
proc `$`[Enum: enum](x: Enum): string
proc `$`(w: WideCString; estimate: int; replacement: int = 0x0000FFFD): string
proc `$`[T](x: set[T]): string
proc `$`[T](x: seq[T]): string
proc `$`(x: int): string
proc `$`(x: cstring): string
proc `$`(x: bool): string
proc `$`(x: float): string
proc `$`(x: char): string
@ghost
Copy link

ghost commented Jun 1, 2018

that's because $ is not defined for openarray

@ghost ghost changed the title [strformat] fmt does not work on openarrays There's no $ for openArray Jun 1, 2018
@ghost ghost added the Standard Library label Jun 1, 2018
@kaushalmodi
Copy link
Contributor Author

kaushalmodi commented Jun 1, 2018

Ah, was just going to comment on that.. here's an even smaller example:

proc testOpenArray(x: openArray[int]) =
    echo x 

I am aware that repr(x) can be used instead. But I eventually would like to use fmt for open arrays too.

@data-man
Copy link
Contributor

data-man commented Jun 1, 2018

From my patched superpupercool system.nim :)

proc `$`*[T](x: openarray[T]): string =
  ## generic ``$`` operator for openarrays that is lifted from the components
  ## of `x`. Example:
  ##
  ## .. code-block:: nim
  ##   $(@[23, 45].toOpenArray(0, 1)) == "[23, 45]"
  collectionToString(x, "[", ", ", "]")

@ghost
Copy link

ghost commented Jun 1, 2018

@data-man what do you have in your patched superpupercool system.nim and why you don't make PRs? 💃

@kaushalmodi
Copy link
Contributor Author

@data-man Of course I tried it and didn't work.. your superpupercool system.nim has collectionToString defined too :P

@ghost
Copy link

ghost commented Jun 1, 2018

@kaushalmodi no, collectionToString is a proc defined in system.nim, but it's not exported.

@data-man
Copy link
Contributor

data-man commented Jun 1, 2018

@Yardanico

Because PRs for system.nim often isn't accepted.

what do you have in your patched superpupercool system.nim

Many Things. :-D

@ghost
Copy link

ghost commented Jun 1, 2018

@data-man well, you should at least try to make a PR, so there will be a discussion and people will decide if it's good to put it in system.nim

@data-man
Copy link
Contributor

data-man commented Jun 1, 2018

Should try?
No, I'll spend my time better.

@ghost
Copy link

ghost commented Jun 1, 2018

Well, it means that you don't want to contribute to Nim (with system.nim additions) :P

@ghost
Copy link

ghost commented Jun 1, 2018

@data-man I didn't mean that you should just commit, I've meant that you should make PRs, but ok :D

@data-man
Copy link
Contributor

data-man commented Jun 1, 2018

@Yardanico

I hope that Araq wouldn't object to this improvement. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants