Zulip Chat Archive

Stream: new members

Topic: Array out of bounds error half caught


Lars Ericson (Jul 17 2023 at 12:10):

This example from here doesn't behave as expected:

def northernTrees : Array String :=
  #["sloe", "birch", "elm", "oak"]

#eval northernTrees[8]

def foo := northernTrees[8] -- sets foo to "8"

#check foo -- prints "foo : String"

The #eval northernTrees[8] produces a warning message but it also produces a value, the string "8".

The def foo := northernTrees[8] causes foo to be bound with a type of String, as shown by the #check foo.

I expected the #eval to fail completely and for foo to remain unbound.

Screenshot attached.
Screenshot-from-2023-07-17-08-10-06.png

Damiano Testa (Jul 17 2023 at 14:55):

Something related was also noticed in this post.


Last updated: Dec 20 2023 at 11:08 UTC