Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Changes

Jump to: navigation, search

Howto:Serializing Nasal data structures

52 bytes added, 9 February
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]);
}
493
edits

Navigation menu