Changes

Jump to: navigation, search

Howto:Serializing Nasal data structures

52 bytes added, 12:29, 9 February 2019
Proof of concept: beautified
var serializeVector = func(vector) {
retVal = "["; foreach(var item; vector) { retVal ~= serialize(item) ~ ',';
}
var serializeHash = func(hash) {
var retVal = "{"; foreach(var member; keys(hash)) { retVal ~= serialize(member) ~ ',';
}
var serialize = func (data) {
var type = typeof(data); if (type == "scalar") return data; if (type == "vector") return serializeVector(data); if (type == "hash") return serializeHash(data); if (type == "ghost" or type == "func") return "nil"; die("cannot serialize unsupported data type:", type);
}
# populate the vector with elements with [index, index^2]
for (var i=0;i<=40;i+=1) {
append(myVector,[i, i*i]);
}
539
edits

Navigation menu