Message Boards Message Boards

0
|
8527 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

I don't get how FormFunction works

Posted 10 years ago

I tried to get FormFunction[] to work, but I do not get, how the inputs are used in the actual function I define:

simpleFunc[basis_, exponent_] := basis ^ exponent
foFuSiFu = FormFunction[{"Basis" -> "Number", "Exponent" -> "Number"},simpleFunc]

Then entering numbers into the form and evaluating it by

foFuSiFu[]

Does not give my anything and that drives me crazy.

What am I doing wrong?

POSTED BY: Goetz Galuba
3 Replies
Posted 10 years ago

The second argument to FormFunction is function that expects a single Association (as is also true of APIFunction). The arguments coming to the FormFunction are available as named slot parameters, written like #Basis. It is not recommended to use uppercase letters to begin symbols, so I would also rename your FormFunction parameters to begin with a lowercase letter. Based on I would rewrite your code as follows:

simpleFunc[basis_, exponent_] := basis ^ exponent
foFuSiFu = FormFunction[{"basis" -> "Number", "exponent" -> "Number"}, simpleFunc[#basis, #exponent]&]
POSTED BY: Joel Klein
Posted 10 years ago

I did copy your version and this still does not work in my notebook in Wolfram Cloud. When I enter values into the form and try to evaluate it with

foFuSiFu[]

it gives me an error every time.

"The server is experiencing unexpected issues and could not process your request. Please try again in a few minutes."

When I do not use uppercase variables I would also need to change the name shown in the CloudDeploy. How do I change the label shown in the deployed form? (The examples in the documentation center have uppercase Variables to achieve that, which brought me to doing it that way to)

POSTED BY: Goetz Galuba

If your definition of simpleFunc and and your definition of foFuSiFu are in the same input, they need to be separated by a semi-colon. Better to put them in separate inputs.

In[1]:= simpleFunc[basis, exponent] := basis^exponent

In[2]:= foFuSiFu = FormFunction[{"Basis" -> "Number", "Exponent" -> "Number"}, simpleFunc]

enter image description here

POSTED BY: Frank Kampas
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