Skip to content

a general function to convert to OpenMath #9

Description

@MarcoCostantini

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions