-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
const Foo=int
compiles; is that legal? what does it mean?
#8610
Comments
It's equivalent to a import macros
const Foo = int
macro foo(name: untyped): untyped =
newTree(nnkVarSection, newIdentDefs(name, getType(Foo), newLit(5)))
foo(bar)
echo bar * 3 # 15 I don't think it's documented though it sometimes would be expected to work. |
It's not legal. |
Related? proc test(a = int, string = string) =
echo 1
test() |
@Tim-St No, that's a default value of a import typetraits
# Same as 'proc test(a: typedesc = int): string = $a'
proc test(a = int): string = $a
doAssert test() == "int"
doAssert test(string) == "string" |
Ok, so If I understood correctly, |
Because procedures can be generic, variables can't. |
But Edit: proc test(a = typedesc) =
when a is int:
echo 123
else:
echo "abc" But still I think it is better to have it consistent. Edit 2: |
@Tim-St types != values. Typedescs bridge that gap, and allow types to be used as compile-time values. That only makes sense for proc arguments. |
As I said in #8657. |
EDIT: is that the syntax to get a const typedesc variable ? where is that documented?
The text was updated successfully, but these errors were encountered: