Thank you @Spacechild1 for your explanation.
I don’t think this is an error related to my erratic interpretation on types.
Sorry, I forgot to put an example on the actual JSON file I’m using. Please finde below the actual JSON file I’m using as a base for my tests (even if, at least according to my experiments, it seems to me not to be related on the kind ond JSON file).
{
"myObjects": [
{ "index":0,"name":"object_A", "value":0.11 },
{ "index":1,"name":"object_B", "value":0.21 },
{ "index":2,"name":"object_C", "value":0.31 },
{ "index":3,"name":"object_D", "value":0.41 }
]
}
After parsing it and getting a corresponding dictionary on the language side, every time I try to add new associations (like this ~myDict.put(\cat, 10)
) it raises an error like the one shown below:
ERROR: Primitive '_BasicPut' failed.
Index out of range.
RECEIVER:
Instance of Array { (0x55750c027758, gc=BC, fmt=01, flg=00, set=02)
indexed slots [2]
0 : "myObjects"
1 : instance of Array (0x55750c027608, size=4, set=2)
}
PATH: /home/nicola/Documenti/sketchbooks/SC_sketchbook/Dictionary_tests/01_test_normal_dict_and_json_dict.scd
CALL STACK:
MethodError:reportError
arg this = <instance of PrimitiveFailedError>
Nil:handleError
arg this = nil
arg error = <instance of PrimitiveFailedError>
Thread:handleError
arg this = <instance of Thread>
arg error = <instance of PrimitiveFailedError>
Object:throw
arg this = <instance of PrimitiveFailedError>
Object:primitiveFailed
arg this = [*2]
Dictionary:put
arg this = <instance of Dictionary>
arg key = 'cat'
arg value = 10
var atKey = nil
var index = -2
Interpreter:interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
var code = "~myDict.put(\cat, 10);"
var doc = nil
var ideClass = <instance of Meta_ScIDE>
Process:interpretPrintCmdLine
arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Primitive '_BasicPut' failed.
Index out of range.
RECEIVER: [ myObjects, [ Dictionary[ (name -> object_A), (value -> 0.11 ), (index -> 0) ], Dictionary[ (name -> object_B), (value -> 0.21 ), (index -> 1) ], Dictionary[ (index -> 2), (name -> object_C), (value -> 0.31 ) ], Dictionary[ (name -> object_D), (value -> 0.41 ), (index -> 3) ] ] ]
I’ve also tried adding association using string instead of symbol (~myDict.put("cat", 10)
) I’m getting the same error ( '_BasicPut' failed. Index out of range.
)
ERROR: Primitive '_BasicPut' failed.
Index out of range.
RECEIVER:
Instance of Array { (0x55750c027758, gc=BC, fmt=01, flg=00, set=02)
indexed slots [2]
0 : "myObjects"
1 : instance of Array (0x55750c027608, size=4, set=2)
}
PATH: /home/nicola/Documenti/sketchbooks/SC_sketchbook/Dictionary_tests/01_test_normal_dict_and_json_dict.scd
CALL STACK:
MethodError:reportError
arg this = <instance of PrimitiveFailedError>
Nil:handleError
arg this = nil
arg error = <instance of PrimitiveFailedError>
Thread:handleError
arg this = <instance of Thread>
arg error = <instance of PrimitiveFailedError>
Object:throw
arg this = <instance of PrimitiveFailedError>
Object:primitiveFailed
arg this = [*2]
Dictionary:put
arg this = <instance of Dictionary>
arg key = "cat"
arg value = 10
var atKey = nil
var index = -2
Interpreter:interpretPrintCmdLine
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
var code = "~myDict.put("cat", 10);"
var doc = nil
var ideClass = <instance of Meta_ScIDE>
Process:interpretPrintCmdLine
arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Primitive '_BasicPut' failed.
Index out of range.
RECEIVER: [ myObjects, [ Dictionary[ (name -> object_A), (value -> 0.11 ), (index -> 0) ], Dictionary[ (name -> object_B), (value -> 0.21 ), (index -> 1) ], Dictionary[ (index -> 2), (name -> object_C), (value -> 0.31 ) ], Dictionary[ (name -> object_D), (value -> 0.41 ), (index -> 3) ] ] ]
By the way, I’ve also tried parsing your JSON string instead of a file and I get same errors
~dict = "{ \"foo\": 123, \"bar\": 5 }".parseJSON;
~dict.put(\cat, 10); // --> doesn't work
~dict.add(\cat -> 1); // --> doesn't work
~dict.put("cat", 10); // --> doesn't work
~dict.add("cat" -> 1); // --> doesn't work
Do you know why?
Thank you @mstep for your explanation, I’ve actually found this primitive definition inside the lang/LangPrimSource/PyrStringPrim.cpp
source code file. I will dig deep on this.