Group Abstract Group Abstract

Message Boards Message Boards

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

I don't get how FormFunction works

Posted 12 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 12 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 12 years ago
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