Jump to content

Multiple distinct objects: Difference between revisions

jq
(Add Nimrod)
(jq)
Line 494:
for (var i = 0; i < n; i++)
a[i] = new Foo();</lang>
 
=={{header|jq}}==
jq does not have mutable data types, and therefore in the context of jq, the given task is probably of little interest. However, it is possible to fulfill the task requirements for jq types other than "null" and "boolean":<lang jq>
def Array(atype; n):
if atype == "number" then [ range(0;n) ]
elif atype == "object" then [ range(0;n)| {"value": . } ]
elif atype == "array" then [ range(0;n)| [.] ]
elif atype == "string" then [ range(0;n)| tostring ]
elif atype == "boolean" then
if n == 0 then [] elif n == 1 then [false] elif n==2 then [false, true]
else error("there are only two boolean values")
end
elif atype == "null" then
if n == 0 then [] elif n == 1 then [null]
else error("there is only one null value")
end
else error("\(atype) is not a jq type")
end;
 
# Example:
 
Array("object"; 4)</lang>
 
=={{header|Logtalk}}==
2,502

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.