SmallBASIC icon indicating copy to clipboard operation
SmallBASIC copied to clipboard

Issue with associative array example

Open circular opened this issue 2 years ago • 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

circular avatar Jun 12 '22 19:06 circular

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 avatar Oct 19 '22 20:10 Joe7M

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

Joe7M avatar Dec 13 '22 14:12 Joe7M