• thingsiplay@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    13 days ago

    I assume they did that for performance reasons, because removing entries is slow probably? From user perspective, it would have made it more sense to remove the key instead defining it as nil and then expecting the user to handle the nil. The key does not stop existing, right? I don’t program in Lua.

    • pet the cat, walk the dog@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      13 days ago

      Nil doesn’t exist as a value in Lua, because a variable or a field that don’t exist or are unassigned are indistinguishable from a nil value, since they all return nil when evaluating. In particular, this leads to the situation that you can’t have a table where some of the fields are assigned nil as the value, because those fields effectively don’t exist.

      • thingsiplay@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        13 days ago

        Ah I see, that makes it clear. I guess it is a “good enough” solution where it doesn’t matter in real world.

        • pet the cat, walk the dog@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          13 days ago

          I’m guessing it’s more of a stylistic choice. Lisps typically work the same way, except they can retrieve the full map structure even if some fields contain nil as the value.

          Unfortunately, Lua’s approach hinders exchanging structures with null values with other environments: see my comment here.

    • lime!@feddit.nu
      link
      fedilink
      arrow-up
      1
      ·
      13 days ago

      the key does stop existing, insofar as referring to any name that is not defined in lua results in nil. which includes variables, since they are defined in a global table. i don’t actually know what happens internally.