Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a general function to convert to OpenMath #9

Open
MarcoCostantini opened this issue May 21, 2020 · 0 comments
Open

a general function to convert to OpenMath #9

MarcoCostantini opened this issue May 21, 2020 · 0 comments

Comments

@MarcoCostantini
Copy link

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"
 }  
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant