Create an object/Native demonstration: Difference between revisions
Create an object/Native demonstration (view source)
Revision as of 22:37, 25 June 2019
, 5 years agono edit summary
No edit summary |
|||
Line 263:
jq objects, however, are really just values: they are immutable, and cannot be "deleted" any more than the number 1 can be deleted.
=={{header|Kotlin}}==
Line 277 ⟶ 281:
{A=65, B=66, C=67}
</pre>
=={{header|Julia}}==
<lang Julia>
using BackedUpImmutable
function testBackedUpImmutableDict()
fibr = BackedUpImmutableDict{String,Int64}(["a" => 0, "b" => 1, "c" => 1, "d" => 2,
"e" => 3, "f" => 5, "g" => 8, "h" => 13, "i" => 21, "j" => 34, "extra" => -1])
x = fibr["extra"]
@test x == -1
fibr["extra"] = 0
y = fibr["extra"]
@test y == 0
restore!(fibr, "extra")
z = fibr["extra"]
@test z == -1
@test_throws String begin fibr["k"] = 55 end
# test alternative constructor
# fibr = BackedUpImmutableDict("a" => 0, "b" => 1, "c" => 1, "d" => 2,
# "e" => 3, "f" => 5, "g" => 8, "h" => 13, "i" => 21, "j" => 34, "extra" => -1)
fibr["a"] = 9
fibr["b"] = 7
# test restore all to default
restoreall!(fibr)
@test fibr["a"] == 0
end
</lang>
All tests pass.
=={{header|M2000 Interpreter}}==
{{trans|C sharp}}
|