Can I store the result of a complex calculation in a field?

Hi,

As far as I understand, I can store the result of a filter/function in a field, but not the result of a procedure:

\procedure compute(n)
{{{[<n>multiply[3]]}}}
\end

\function .f(n)
[<n>multiply[3]]
\end

!!! Procedure

regular call: <<compute 4>>

<$let myres=<<compute 4>>>
<$button>
<$action-setfield result1=<<myres>>/>
store result
</$button>
</$let>

Value result: {{!!result1}} (doesn't work)

!!! Function

regular use: {{{[.f[4]]}}}

<$let myres={{{[.f[4]]}}}>
<$button>
<$action-setfield result2=<<myres>>/>
store result
</$button>
</$let>

Value result: {{!!result2}} (works)

But if my calculation is complex, for example below, and cannot be done in a filter/function, is there a way to store the result into a field?

\procedure complexproc(n switch)
<$list filter="[<switch>compare:string:eq[a]]">
{{{[<n>multiply[3]]}}}
</$list>
<$list filter="[<switch>compare:string:eq[b]]">
{{{[<n>add[55]]}}}
</$list>
<$list filter="[<switch>compare:string:eq[c]]">
{{{[<n>]}}}
</$list>
\end

Thanks!

Just a Quick tip, its late here.

To set a field you need a trigger, most commonly a button, you then use action widget(s) such as actionsetfield.

Look into it in the documentation, I can help tomorrow if you still need it.

If you read the offical documents, you see passing a procedure to widget attribute will not render the procedure. You need to use wikify.

1 Like

Thanks, yes I know about this one.

My question is whether I can store the result of a procedure inside a field? in my example I can store the result of a function/filter but not a procedure. But maybe I’m missing something?

Ok thank you very much :slight_smile:

I didn’t know the wikify widget.

1 Like

Here is an example with the wikify widget.

\procedure a-procedure(input:"1")
{{{ [<input>multiply[2]] }}}
\end


<$wikify name=newvalue text="<<a-procedure 4>>" >
<$button set="!!test" setTo=<<newvalue>> >Set</$button>
</$wikify>
  • I like to refer to this as a just in time wikification
  • I would like to see a shorthand form of the wikify widget as it is verbose.
2 Likes

This can now be simplified and avoid the wikify widget.

\function a-calc(input:"1") [<input>multiply[2]]

<$button set="!!test" setTo=<<a-calc>> >Set</$button>