1

An operation * is associative iff (A*B)*C = A*(B*C). For * the access operation on associative arrays, it is not associative:

Consider an associative array, represented as a json:

A = { B: { C: D } }

We have: (A.B).C = D

But: A.(B.C) is undefined

I have also tried other operations like add etc. Nothing is associative.

(Wikipedia doesn't offer an answer in case you wanted to try ;)

Dominik Teiml
  • 505
  • 1
  • 4
  • 12
  • Associative arrays *are* associative. Just not in the same sense. You are expecting a technical term in one universe of discourse to have exactly the same meaning in another universe of discourse. Natural languages don't work like that. The fact that JSON and Lua use `.` as a selection operator for associative arrays is just a language feature. Your argument falls down with Python and awk where the selector is `[...]`. – BoarGules Feb 01 '19 at 14:29
  • With all respect, I don't think this is a good comment. I could have rewritten the equations as `(A[B])[C]` and `A[(B[C])]` (more naturally as `A[B][C]` and `A[B[C]]`) and the result would be the same. See the answer for a better explanation :) – Dominik Teiml Feb 01 '19 at 15:02

1 Answers1

1

Associative as in associative arrays has a different meaning, which is relative to how to get elements:

  • Non associative array: you only store values that you can retrieve using an index (Array[5])
  • Associative array: you associate values to keys, then you can use the key to retrieve the value (Array['MyKey']).
FXD
  • 1,960
  • 1
  • 6
  • 9