Array of Functions

Terry Reedy tjreedy at udel.edu
Sat Nov 15 01:11:34 CET 2014


On 11/14/2014 5:17 PM, Richard Riehle wrote:
> In C, C++, Ada, and functional languages, I can create an array of
> functions, albeit with the nastiness of pointers in the C family.
> For example, an array of functions where each function is an active
> button, or an array of functions that behave like formulae in a
> spreadsheet.

Googling 'python spreadsheet', the first hit is
https://manns.github.io/pyspread/
"Pyspread expects Python expressions in its grid cells,"
and expressions can reference other cells.

There may be other relevant programs.

> I am finding this a bit challenging in Python.

Since python functions are objects, they easy fit into any array of 
objects. They can also be the values in dicts.  Since strings can be 
passed to built-in runtime compile, eval, and exec functions, (not part 
of standard C), functions can also be represented by a return 
expression, as in Pyspread, or even quoted def statements.

A program that executes user-entered code is much easier in Python than 
in C or any other language where one would have to write or find lexer, 
parser, compiler, and execution functions.

> I think my difficulty is related to the REPL nature of Python.

I do not understand this. The interpreter runs a REPL in interactive 
mode but can also run in batch mode.


-- 
Terry Jan Reedy




More information about the Python-list mailing list