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

static[T] and varargs together #1083

Open
PavelVozenilek opened this issue Apr 11, 2014 · 7 comments
Open

static[T] and varargs together #1083

PavelVozenilek opened this issue Apr 11, 2014 · 7 comments
Assignees

Comments

@PavelVozenilek
Copy link
Contributor

The documentation does not say how to combine static[T] feature with varargs parameter.

@zah zah self-assigned this Apr 12, 2014
@reactormonk
Copy link
Contributor

Can you give an example where you would like to combine them?

@PavelVozenilek
Copy link
Contributor Author

Graphic pipeline which takes a set of transformation matrices. If you know them all in advance you can avoid runtime calculation of result matrix.

Possibly a database transaction executing several SQL commands. If you know all of these commands in advance you may check their validity against the database during compile time.

Mixing of compile time and runtime parameters looks like a problem:

var s : string = ...

proc foo(static varargs[string]) = ...

foo("aaa", s, "bbb")

@Varriount
Copy link
Contributor

Wouldn't a template work in this case?

@Araq Araq added the feature label Apr 13, 2014
@PavelVozenilek
Copy link
Contributor Author

Wouldn't a template work in this case?

I do not know. This advanced part of the language is underdocumented, I didn't play with it yet.

@zah
Copy link
Member

zah commented Apr 13, 2014

The correct syntax would be

proc foo(args: varargs[static[string]]) = ...

... but the combination is not supported yet.

@tobim
Copy link

tobim commented Dec 19, 2014

I would like to have support for that. I hope it will also work with macros.

@Araq Araq added the Static[T] label Apr 4, 2016
@shirleyquirk
Copy link
Contributor

this would be handy for making a proc/template for strformat to concat staticly known substrings.
it's not trivial? / impossible to detect staticness inside a macro

Clyybber pushed a commit to Clyybber/Nim that referenced this issue Feb 24, 2024
## Summary

Neither the program output nor the comparison string are cut off at the
first null byte anymore.

## Details

Output comparisons in testament used `strutils.contains`, which uses
`strutils.find`, which, by default, uses `c_strstr`.

`c_strstr` operates on null-terminated strings, and thus stopped at the
first occurrence of one, even if the end of the NimSkull string hasn't
been reached yet.

Testament now uses a custom `contains` implementation based on C's
`memcmp`, so that the `\0` byte doesn't terminate the search.
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

7 participants