I have a fairly simple need. Think a conversion - there’s a text field for user to enter a number, and that gets converted to another number and shown. There’s a formula to perform the conversion.
This is a simple enough use case that it doesn’t need a table.
My thought was to define a formula in the canvas (I needed to reuse it), and refer to the formula to perform the conversion.
However, code completion doesn’t seem to find the formula. Not with myFormula(), not with thisDocument().myFormula(). At least not consistently.
Do formulas not work outside of a table?
your Formula works where you placed it and displays the result there.
if you have given it the name myFormula then you can refer to its RESULT anywhere else in another formula with myFormula, no parentheses needed.
if the name is not available in autosuggest in the formula editor, you need to check to make sure you have named the original canvas formula correctly.
The myFormula without parentheses was the key insight, although I still don’t quite get why.
My page is at Currency (coda.io) BTW, if you want to see what I meant. The formulas are defined in a collapsed section.
the idiom of empty parentheses for function invocations is common in procedural programming languages. but coda’s formula language (CFL) does not strictly follow that paradigm.
the object you are referencing as myFormula is a ‘control value’ object. there are several types of control value objects: canvas formulas, single and multi selection objects, sliders for numbers and textboxes for strings, checkboxes, etc etc.
so CFL refers to all these objects by name only. the result is the current value of the control object.
you cannot provide any parameters when you reference these, so there is no syntax for formal arguments inside parentheses. thus, no syntax using empty parentheses when no arguments are given.
so: your myFormula is not a function, but a kind of variable.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.