Message Boards Message Boards

0
|
5884 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why does the "APIFunction" require the successive code on the same line?

Posted 10 years ago

I am creating an APIFunction to which receives a zip code, radius in miles, and an address and then returns whether or not the given address is within a specified mile radius of the provided zip code.

I wrote the APIFunction on one line and then the command to run it on the next line. The results were as follows:

INPUT:

LocAPI = APIFunction[{"Zc" ->"ZIPCode","dist" -> "Integer","Saddress" ->"StreetAddress"},GeoWithinQ[GeoDisk[#Zc, Quantity[#dist,"Miles"]],#Saddress]&]; 
LocAPI[<|"Zc" -> "61606", "dist" -> 5, "Saddress" -> "300 NE Adams St Peoria, IL"|>] 

OUTPUT (error):

GeoWithinQ[GeoDisk[<|"Zc" -> "ZIP 61615" Entity["ZIPCode", "61606"], "dist" -> 5 "ZIP 61615", "Saddress" -> "ZIP 61615" GeoPosition[{40.6939, -89.5862}]|>, Quantity[<|"Zc" -> 5 Entity["ZIPCode", "61606"], "dist" -> 25, "Saddress" -> 5 GeoPosition[{40.6939, -89.5862}]|>, "Miles"]], <|"Zc" -> 
           "300 NE Adams St Peoria, IL" Entity["ZIPCode", "61606"], "dist" -> 5 "300 NE Adams St Peoria, IL", 
          "Saddress" -> "300 NE Adams St Peoria, IL" GeoPosition[{40.6939, \-89.5862}]|>]

For some reason it tends to combine the inputs of the APIFunction: #Zc, #dist, etc. . .

Now if I input everything on the same line (or throw brackets around it all-essentially doing the same thing), the code will run fine:

INPUT:

(
LocAPI = APIFunction[{"Zc" ->"ZIPCode","dist" -> "Integer","Saddress" ->"StreetAddress"},GeoWithinQ[GeoDisk[#Zc, Quantity[#dist,"Miles"]],#Saddress]&]; 
    LocAPI[<|"Zc" -> "61606", "dist" -> 5, "Saddress" -> "300 NE Adams St Peoria, IL"|>]
)

OUTPUT: true

So why does the APIFunction seem to require successive, separate instances of code to be on the same line or encapsulated in brackets? The same issue occurs when adding the "CloudDeploy" function in succession as well. It must be on the same line or else the same error occurs.

Regards,

Matt

POSTED BY: Matt Brauer
6 Replies
Posted 10 years ago

Arnoud,

That is precisely the error I am experiencing.

David,

I'm glad that you too were able to verify the issue.

POSTED BY: Matt Brauer

Matt,

This is the error you are seeing?

enter image description here

(I think it is, but just wanted to make sure before continuing).

POSTED BY: Arnoud Buzing

If I paste the code into a Programming Cloud notebook (it includes the carriage return after the first line as you posted it) it works fine. Then I delete the carriage return and add it back in and execute the code again and get your error message. So something is indeed amiss on the Cloud...

POSTED BY: David Reiss
Posted 10 years ago

I am using it on the Wolfram Programming Cloud. Its interesting that it works on your local copy of Mathematica.

I also tried copying the code into a fresh notebook and the same issue occurred. Just in case, I also tried retyping it explicitly instead of copying it and that didn't help either.

The two pieces common to the problem seem to be the APIFunction and using it in the Wolfram Programming Cloud.

Thanks for looking into it. If you have any more suggestions I am open to them!

I also tried this simpler code with the APIFunction and had the same issues:

INPUT:

addf[x_,y_]:=
x+y; 
test = APIFunction[{"g" -> "Integer", "Hf"->"ZIPCode"}, addf[#g,#Hf] &];
test[<|"g"->5, "Hf"->"ZIP 47025"|>]

OUTPUT:

<|g->5 g+5 Hf,Hf->6 g+6 Hf|>

Again, if I combine the "addf" function, APIFunction, and the inputs on the same line, the output works fine.

POSTED BY: Matt Brauer

That's strange. The code seems to run fine for me too. Maybe there was some sort of stray character that was added. Try copying your code from this webpage into a fresh notebook and then running it. Do you still see the problem?

POSTED BY: Sean Clarke

It appears to work fine on my system (OSX Yosemite with Mathematica 10.01)

POSTED BY: David Reiss
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