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

Use a different operator for cstring stringification #47

Open
dom96 opened this issue Jan 27, 2018 · 5 comments
Open

Use a different operator for cstring stringification #47

dom96 opened this issue Jan 27, 2018 · 5 comments

Comments

@dom96
Copy link
Contributor

dom96 commented Jan 27, 2018

Using & is a strange choice and is confusing

@timotheecour
Copy link
Collaborator

timotheecour commented May 17, 2021

from https://irclogs.nim-lang.org/27-01-2018.html#12:48:00

Araq should have used $! or something, not freaking &

instead of an operator, can we just use toCstring, as used in stdlib ?
users can always define their own operators in their own code if they want something shorter

my recommendation:

  • introduce toCstring
  • mark those & procs as deprecated: use `toCstring` and remove all uses of & in karax in the same PR

note

one problem with using operators for this is that parsing rules makes it awkward to use in UFCS/MCS chains, eg:

# what i want:
let a = foo.bar.toString.toLower

# what i have to use:
let a = ($foo.bar).toLower
let a = foo.bar.`$`.toLower

although it's nice to have a short, standard name for stringification; not sure if there's a better solution though.

links

karax/jstrutils.nim:19:6:proc `&`*(a, b: cstring): cstring {.importcpp: "(# + #)", nodecl.}
karax/jstrutils.nim:21:6:proc `&`*(s: int): cstring {.importcpp: "((#)+'')", nodecl.}
karax/jstrutils.nim:22:6:proc `&`*(s: bool): cstring {.importcpp: "((#)+'')", nodecl.}
karax/jstrutils.nim:23:6:proc `&`*(s: float): cstring {.importcpp: "((#)+'')", nodecl.}
karax/jstrutils.nim:25:6:proc `&`*(s: cstring): cstring {.importcpp: "(#)", nodecl.}
karax/kajax.nim:7:21:import jsffi except `&`
karax/reactive.nim:159:7:lift2 `&`
karax/vstyles.nim:348:12:  template `&`(x: untyped): untyped = $x

@Araq
Copy link
Collaborator

Araq commented May 17, 2021

introduce toCstring

toCstring is too verbose, IMHO. I picked an operator because anything else was too verbose. We should use a different operator but I don't know which one.

@timotheecour
Copy link
Collaborator

since there's nothing karax specific about & or toCstring or whatever name should be used, and since stdlib already has toCstring procs defined, I feel a stdlib module (std/cstrings? std/cdollars?) should standardize it (and work for c, js backends); then karax can reuse it for nim versions > 1.5.1 else redefine it.

options:

  • cstr ? (no existing hits in stdlib, at least no relevant ones)
  • if an operator, IMO it should start with $; $$ would make sense but std/marshal uses it; $^ or similar could work

I still prefer cstr though (not much longer that $$, and works better in MCS/UFCS)

@geotre
Copy link
Collaborator

geotre commented Mar 2, 2023

@Araq let me know if one of these works and I will PR a backwards compatible change (with deprecation message) to karax?

@Araq
Copy link
Collaborator

Araq commented Mar 3, 2023

cstr is short for c string but that name is widely regarded to be mistake now too, so how about jss?

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

5 participants