Skip to content

Understanding Subscripts #739

Answered by kyouko-taiga
AbhinavK00 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @AbhinavK00!

Your understanding is relatively accurate.

In general, I think it's best to just forget about references when reasoning about Val. The reason is that, although projections (i.e., the result of a subscript) fill a similar role, they do not represent a distinct kind of values, with a distinct type. For example, in C++, a reference to int has type int& or int const&. In Rust, a reference to i64 has type &i64 or &mut i64. In Val, a projection of Int has type Int.

So if it's technically correct to say that "Val functions can't return references", it's important to note that it simply derives from the fact that references don't exist in Val.

Unlike functions, subscripts don't re…

Replies: 0 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@AbhinavK00
Comment options

@neuring
Comment options

@kyouko-taiga
Comment options

@neuring
Comment options

@dabrahams
Comment options

Answer selected by kyouko-taiga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants