Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'languages,': 0.04; 'interpreter': 0.05; 'c++,': 0.07; 'expressions': 0.07; "'python": 0.09; 'exec': 0.09; 'executes': 0.09; 'grid': 0.09; 'objects,': 0.09; 'pointers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runtime': 0.09; 'url:github': 0.09; 'runs': 0.10; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'programs.': 0.14; 'behave': 0.16; 'expects': 0.16; 'expression,': 0.16; 'googling': 0.16; 'objects.': 0.16; 'quoted': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'repl': 0.16; 'spreadsheet.': 0.16; 'language': 0.16; 'wrote:': 0.18; '(not': 0.18; 'bit': 0.19; 'fit': 0.20; 'header:User-Agent:1': 0.23; 'button,': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'array': 0.29; 'related': 0.29; 'mode': 0.30; 'nature': 0.30; 'code': 0.31; 'easier': 0.31; 'this.': 0.32; 'run': 0.32; 'but': 0.35; 'there': 0.35; 'functions.': 0.36; 'example,': 0.37; 'challenging': 0.38; 'richard': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'functional': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'easy': 0.60; 'first': 0.61; 'difficulty': 0.68; 'parser,': 0.84; 'received:fios.verizon.net': 0.84; 'family.': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Array of Functions Date: Fri, 14 Nov 2014 19:11:34 -0500 References: <42b534f0-aeef-411f-80c5-db5d20c80b55@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <42b534f0-aeef-411f-80c5-db5d20c80b55@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416010316 news.xs4all.nl 2864 [2001:888:2000:d::a6]:40590 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:80794 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