RosettaCodeData/Task/Introspection/Aikido/introspection.aikido
2023-07-01 13:44:08 -04:00

50 lines
1.2 KiB
Text

import math
if (version < 144) {
throw "Version of aikido is too old"
}
var bloop = -1.4
// Math package doesn't have 'abs'. We'll use 'fabs' instead.
if ("fabs" in Math) {
if ("bloop" in main) {
println ("fabs(bloop) is " + eval ("Math.fabs(bloop)"))
}
}
var x = 104
var y = 598
var z = "hello"
var a = 1234
function count_ints {
// there are builtin integer variables that we don't want to count. There are
// 3 of them
var intcount = 0
// map of builtin variables we want to ignore
var ignore = {"version":true, "int":true, "integer":true}
var sum = 0
// the 'split' function can be used to split a block into a vector of the names
// of the variables within it
foreach v split (main, 0) {
var varname = v
try {
var value = eval (varname)
if (typeof(value) == "integer") {
if (varname in ignore) {
continue
}
intcount++
sum += value
}
} catch (e) {
// ignore exception
}
}
println ("There are " + intcount + " integer variables in the global scope")
println ("Their sum is " + sum)
}
count_ints()