Bug fixed in V11.2
Previously dependencies collector failed to collect check if check was only mentioned in lhs: foo[x_?check] := $Failed;
Cross posted on community.wolfram.com
Background
After failed attempt (1) to create a complex API, by nicely linking my APIFunction to a cloud based package, I decided to go with the flow and trust that:
CloudDeploy[expr, ...]automatically deploys all definitions needed to evaluate expr, much likeCloudSave.
Problem
but either it can't be trusted or I'm missing the point. It seems that definitions are collected by scanning right-hand-sides of related definitions but not left-hand-sides.
Example
ClearAll[foo, check];
check = IntegerQ;
foo[x_?check] := $Failed;
foo[x_] := x^2
api = CloudDeploy[
APIFunction[{"x" -> "Number"}, foo[#x] &]
, Permissions -> "Public"
]
foo[2] (* -> $Failed*)
foo[1.2] (* -> 1.44 *)
URLExecute[api, {"x" -> 2}] (* -> 4*) !!!!!!!!!!!
URLExecute[api, {"x" -> 1.2}] (* -> 1.44*)
The first URLExecute is wrong, it is caused by missing definition of check.
One can confirm that by
Import[api, "Text"]
Language`ExtendedFullDefinition[] = Language`DefinitionList[ HoldForm[foo] -> {..., DownValues -> { HoldPattern[foo[(x_)?check]] :> $Failed, HoldPattern[foo[x_]] :> x^2 }, ... }];APIFunction[{"x" -> "Number"}, foo[#x] & ]
Questions
Is this expected? Are there any new guidelines how to write code so it could be collected well? Or is it a flaw in
Language`?Is there anything I could read to learn working with the Cloud features in such a way that I won't have to come back here with a question/problem about a basic issue like deployment of dependencies?
foo[x_?check] := (Hold[check]; $Failed);will work. This kind of new cloud programming paradigm ("mention all symbols somewhere on the right of := ") should probably be followed until the Wolfram Cloud system stays in its current beta-phase and until it is properly documented. I heard that better documentation is being worked on. And that is promising. (Andre?). – Rolf Mertig Jun 12 '17 at 20:26