smallbasic/SmallBASIC

Issue with associative array example

circular opened this issue · 2 comments

I was just learning about associative arrays in SmallBASIC and unfortunately there seems to be an issue with the exmaple:

https://smallbasic.github.io/pages/features.html

tload "/etc/passwd", buffer
dim users
for row in buffer
  split row, ":", fields()
  if (len(fields) > 0) then
    local user
    user.name = fields(0)
    user.passwd = fields(1)
    user.userId = fields(2)
    user.groupId = fields(3)
    ' Line below seems linked to error
    users(user.name) = user
  fi
next row
? users("mail").userId
RTE-ERROR ... Line 11
Expr/RT: Not a number
Joe7M commented

I just realized, when doing 2 changes, the example works. But still DIM doesn't do, what it should.

tload "/etc/passwd", buffer
users = array("{}")
for row in buffer
  split row, ":", fields()
  if (ubound(fields) > 0) then
    local user
    user.name = fields(0)
    user.passwd = fields(1)
    user.userId = fields(2)
    user.groupId = fields(3)
    ' Line below seems linked to error
    users(user.name) = user
  fi
next row
? users("mail").userId
Joe7M commented

I forgot to mention, that I fixed the example a while ago -> Update example according to bug #148