top | item 47107099

(no title)

gautamcgoel | 8 days ago

Looks amazing. However, I'm confused about some of the examples in the ownership section. Consider this example:

  [fn consume [xs]
  [println [str "got " [len xs] " items"]]]
  [let items #[1 2 3]]
  [consume items]
  ; items has been moved — using it here is a compile error
This is described as an example of a setting where the variable 'items' has been moved, so it can no longer be used. However, the consume function does not mutate its argument, so I don't see why 'items' can no longer be used. In addition, it seems to me that the term 'moved' is being used to mean 'mutated'. Is that correct, or do I have it wrong?

Another example from the website is the following:

  [fn length [xs] [len xs]]

  [let items #[1 2 3]]
  [println [length items]]
  [println [length items]]  ; items not consumed
The website explains this example as follows: "If the compiler can prove that a reference will not outlive the owner, it passes a borrow instead of moving." However, there are no references in this example, only the original variable 'items'. Am I missing something? I think the language is cool, but the explanations of the semantics could be improved.

discuss

order

No comments yet.