How to do procedures?

Has anyone figured out how to do procedures in Coda?

I have a formula I use over and over again, rather than rewrite it each time it needs to be called, I want to use a procedure (or a macro). Has anyone figured out how to do that?

There are three ways I can think of:

  1. Create something akin to an itertable, use ModifyRows to supply the arguments, then reference the result column
  2. Use a Pack to define external logic, then call those custom functions
    a. Perhaps there’s even a way to use a pack to allow for native Coda functions, but I haven’t had a chance to hack at it
  3. Use some Black Magic to do macro replacement inside of a formula. (looking at @Paul_Danyliuk)
    a. This could be onetime replacement (i.e. a formula generator)
    b. or maybe it could be done in realtime, so my formulas can be truly readable

@Connor_McCormick1

your option 1 is the one i use most.

i regard tables as a type of class (using OOP concepts here), so rows are objects, columns are attributes.

so formula columns are functions, they take other columns as arguments and return values.

by similar analogue, button columns are object methods, again, taking other columns as arguments.

if i need class methods, i create a seperate 1 row table for those. and i create similar 1 row tables for global procedures. they have columns for arguments.

your option 2 ‘use a pack’ is possible but not good

currently packs run on the coda servers, so there is an indeterminate delay in their execution. also, it uses javascript and not coda language, so the idiom is very different and complex.

option 3 ‘black magic’ is possible but not supported.

you can insert pure-text formulas into the json object of an Action column and it will be executed. it requires use of unsupported functions and depends on the inner structure of coda objects - so it could break if coda change stuff in a future release.

i use this ‘black magic’ in my BASIC and JAVASCRIPT emulators, if you want to take a look.

i am working on a document to explain this trick clearly (but client work has pre-empted that so far).

finally, i have just recently posted a technique to execute simple formulas using named variables that i want to modify to allow named arguments as well, it does not need any unsupported black magic. watch this space.

respect
max

1 Like