Group Abstract Group Abstract

Message Boards Message Boards

Function giving result on notebook but not giving same result on instantAPI

GROUPS:

Hi everybody I am really really new on wolfram programming cloud . I am discovering functions and I want to create a Instant API including integrate function.

Here is my function CloudDeploy[APIFunction[{"eq"->"MathExpression"},Integrate[#eq,x]&]]

When I entered parameters ?eq=x it is giving me result Global`x*x this is diffrent than on notebook

POSTED BY: Suat Karabacak
Answer
2 months ago

When you pass in a symbol, the symbol has to be placed in a context.

http://reference.wolfram.com/language/tutorial/Contexts.html

If you run Context on eq, you'll see some weird stuff. Basically, the input gets put in a randomized context by default so that it won't potentially conflict with anything defined in the Global context.

So, what needs to happen is that we to ensure that everything is in the "right" context, the "Global`" context. The documentation for MathExpression shows how to do this, but the details are still a bit fuzzy in the documentation. Here is what I would do:

CloudDeploy[APIFunction[{"eq" -> 
Interpreter[Restricted["MathExpression", All, Automatic, "Global`"]]},
Integrate[#eq, x] &]]

So instead of just "MathExpression", I've written out an entire Interpreter expression. This InterpreterExpression uses a syntax that allows it to define what context the resulting symbols should be put into.

POSTED BY: Sean Clarke
Answer
2 months ago

Hi Sean , that is work for me thanks a lot I understand why it is not working know.

POSTED BY: Suat Karabacak
Answer
2 months ago