-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
There are the various functions OM.integer, OM.float, OM.string, etc,
I would like a function that, given any javascript object (supported by OpenMath), chooses automatically the appropriate function among OM.integer, OM.float, OM.string, etc, and convert the object to OpenMath.
Here is a draft of what I mean:
function to_openmath(obj){
switch(typeof(obj)) {
case number:
if Number.isInteger(obj) return OM.integer(obj) else return OM.float(obj)
break;
case string:
return OM.string(obj)
break;
case boolean:
return OM.symbol(obj,logic1)
break;
case object
if Array.isArray(obj)
return OM.application(OM.symbol(list,list1), elements of the array, with to_openmath applied to each )
break;
case and so on:
return OM.corresponding to that
break;
default:
throw "Not supported"
}
}
Metadata
Metadata
Assignees
Labels
No labels