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

Comments

Projects
None yet
3 participants
@kaushalmodi
Copy link
Contributor

kaushalmodi commented Jun 1, 2018

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
@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico commented Jun 1, 2018

that's because $ is not defined for openarray

@Yardanico Yardanico changed the title [strformat] fmt does not work on openarrays There's no `$` for openArray Jun 1, 2018

@Yardanico Yardanico added the Stdlib label Jun 1, 2018

@kaushalmodi

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Collaborator

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, "[", ", ", "]")
@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico commented Jun 1, 2018

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

@kaushalmodi

This comment has been minimized.

Copy link
Contributor

kaushalmodi commented Jun 1, 2018

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

@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico commented Jun 1, 2018

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

@data-man

This comment has been minimized.

Copy link
Collaborator

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

@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico 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

This comment has been minimized.

Copy link
Collaborator

data-man commented Jun 1, 2018

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

@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico commented Jun 1, 2018

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

@data-man data-man closed this in b4626a2 Jun 1, 2018

@Yardanico

This comment has been minimized.

Copy link
Collaborator

Yardanico 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

This comment has been minimized.

Copy link
Collaborator

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