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

misc cast #546

Open
timotheecour opened this issue Jan 21, 2021 · 4 comments
Open

misc cast #546

timotheecour opened this issue Jan 21, 2021 · 4 comments

Comments

@juancarlospaco
Copy link
Collaborator

The only way to make a Tuple type without any extra unwanted temporary variable is cast,
maybe a template can improve the usability, even if using cast internally.

type A = tuple[a: string, b: int]
echo A(a: "a",  b: 9)  # Error: object constructor needs an object type
type A = tuple[a: string, b: int]
var x: A = (a: "a",  b: 9)  # Unwanted temporary variable.
echo x                      # Works
type A = tuple[a: string, b: int]
echo cast[A]((a: "a",  b: 9))  # Works but uses cast

🤔

@timotheecour
Copy link
Owner Author

The only way to make a Tuple type without any extra unwanted temporary variable is cast

see nim-lang/RFCs#321 which would enable echo A(a: "a", b: 9)

@SolitudeSF
Copy link

The only way to make a Tuple type without any extra unwanted temporary variable is cast,

type A = tuple[a: string, b: int]
echo A (a: "a",  b: 9)

@timotheecour
Copy link
Owner Author

or this works too:

type A = tuple[a: string, b: int]
echo A (a: "a",  b: 9)
echo A((a: "a",  b: 9))

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

No branches or pull requests

3 participants