Message Boards Message Boards

0
|
9097 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Strange APIFunction / Interpreter Behaviour, Possible Bug

Posted 10 years ago

I've been using Mathematica for a few years, and today decided to have a first play with the Wolfram Cloud, to get a feel for how to deploy a function. I set up a very basic function that, when called via its url with the correct parameters, should interpret the argument as a Wolfram Language expression, and return it:

CloudDeploy@APIFunction[{"p"->"Expression"},#&,"WL"]

When called, this mainly seems to work, returning an association with the evaluated expression, e.g

https://www.wolframcloud.com/objects/cccb5437-d414-4af2-93eb-d7d976970f63?p=Sin[x]/Cos[x]

returns

<|"p" -> Tan[x]|>

as I would expect from Mathematica. Similarly, attaching "p=Cos[Pi]" to the url returns <|"p"-> -1|>, for example.

But there seems to be a bug where "+" is interpreted as "*". So calling

https://www.wolframcloud.com/objects/cccb5437-d414-4af2-93eb-d7d976970f63?p=2+3

returns

<|"p" -> 6|>

for example.

I have tried this with quite a few expressions, both in Firefox on a thin client PC, and Chrome on my Android phone, and the behaviour is consistent. However, calling the url with "p=Plus[2,3]", for example, returns the correct result. Also using

APIFunction[{"p"->"Expression"},#&,"WL"][<|"p"->"2+3"|>]

in the cloud notebook returns

<|p->5|>

as expected. Could this be a bug with the way "+" is interpreted when in an url, or am I doing something daft?

POSTED BY: Robert Ferguson
2 Replies
Posted 10 years ago

Thanks very much for your explanation Kuba, that's given me something to work on.

POSTED BY: Robert Ferguson
Posted 10 years ago

There are some special symbols in urls world, like ?, +, % and so on.

You can't use them explicitly but you can use dedicated functions to create a valid URL:

cloudobject =    CloudDeploy @ APIFunction[{"p" -> "Expression"}, # &, "WL"]

SystemOpen @ URLBuild[ cloudobject, {"p" -> "2+3"}]
<|p->5|>

If you want to be able to write url by hand, then you have to know how to do this replacements. Or you can use FullForm of the expression:

[...url...]?p=Plus[2,3]

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract