Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91271

Re: Array of Functions

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <lac@openend.se>
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; 'else:': 0.03; 'performs': 0.07; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'tuple': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; 'python.': 0.11; 'appropriate': 0.14; 'def': 0.14; 'missed': 0.15; 'java,': 0.15; 'languages,': 0.15; '1):': 0.16; '>in': 0.16; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'immutable,': 0.16; 'index.': 0.16; 'message- id:@fido.openend.se': 0.16; 'parameters,': 0.16; 'received:89.233': 0.16; 'received:89.233.217': 0.16; 'received:89.233.217.133': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'simplified': 0.16; 'laura': 0.18; 'solution.': 0.18; 'compare': 0.20; 'cc:addr:python.org': 0.21; 'cc:2**1': 0.22; 'c++,': 0.22; 'function,': 0.22; 'parameter': 0.22; 'phd': 0.22; 'tuples': 0.22; 'posted': 0.23; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.25; 'earlier': 0.27; 'looks': 0.29; '-0500,': 0.29; 'arrays': 0.29; 'dictionary': 0.29; 'finds': 0.29; 'received:se': 0.29; 'solution,': 0.29; 'array': 0.29; 'cc:no real name:2**1': 0.29; 'function': 0.30; 'becomes': 0.31; 'anyone': 0.32; 'problem': 0.33; 'decorators': 0.33; 'another': 0.34; 'question,': 0.35; 'solving': 0.35; 'really': 0.35; 'asking': 0.35; 'problem.': 0.35; 'but': 0.36; 'too': 0.36; 'list,': 0.36; 'so,': 0.37; 'two': 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'list.': 0.37; 'level': 0.37; 'associated': 0.38; 'tue,': 0.38; 'doing': 0.38; 'someone': 0.38; 'or,': 0.38; 'wanted': 0.39; 'called': 0.40; 'easy': 0.60; 'hope': 0.61; 'header:Message-Id:1': 0.62; 'more': 0.62; 'enclosed': 0.63; 'within': 0.64; 'here': 0.66; 'fact,': 0.67; 'received:89': 0.80; '>def': 0.84; 'dimensional': 0.84; 'interesting,': 0.93
To richard_riehle <rriehle@itu.edu>
cc python-list@python.org, lac@openend.se
From Laura Creighton <lac@openend.se>
Subject Re: Array of Functions
In-Reply-To Message from richard_riehle <rriehle@itu.edu> of "Tue, 26 May 2015 19:43:31 -0500." <TbKdnVQBR8OujvjInZ2dnUU7-LOdnZ2d@giganews.com>
References <42b534f0-aeef-411f-80c5-db5d20c80b55@googlegroups.com><TbKdnVQBR8OujvjInZ2dnUU7-LOdnZ2d@giganews.com>
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <30863.1432688730.1@fido>
Content-Transfer-Encoding quoted-printable
Date Wed, 27 May 2015 03:05:30 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [89.233.217.130]); Wed, 27 May 2015 03:05:32 +0200 (CEST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.69.1432688744.5151.python-list@python.org> (permalink)
Lines 54
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432688744 news.xs4all.nl 2871 [2001:888:2000:d::a6]:37271
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91271

Show key headers only | View raw


In a message of Tue, 26 May 2015 19:43:31 -0500, richard_riehle writes:
>I realized that I mentioned earlier that I found a solution to my original question, but that I never posted an example of the solution.   So, here is a simplified example for anyone who is interested.
>
>def fArray(fselect, fparm  = 1):
>	def A1(p = fparm):
>		if p == 1:
>			print("printing A1[1]")
>		else:
>			print("printing A1[other]")
>	def A2(p = fparm):
>		if p == 1:
>			print("printing A2[1]")
>		else:
>			print("printing A2[other]")
>	A = [A1, A2]
>	A[fselect]()
>
>In this example, I enclosed two functions within another function, and then put those two functions in a list.  Then, with appropriate parameters, I called one of the functions in the list, associated the formal parameter with the function in a call to the array, and presto, it performs the function.
>
>The more advanced problem I wanted to solve, a two dimensional array of functions, once this example is understood, becomes trivial to implement.  In fact, the more interesting problem I wanted to solve involved a dictionary of functions in a two-dimensional array, and that too was easy to do in Python.  
>
>When I compare what this would require in C, C++, Java, or most other languages, I find Python to be really easy for solving this kind of problem.
>
>Next, I plan to develop the solution using decorators and assertions to empower it with a greater level of portability and to make the functions more generic.
>
>I hope someone finds this interesting.
>
>Richard Riehle, PhD

I am happy you found a solution, but I fear that adding decorators and
assertions will not do what you are asking for.  I missed the
original question, but it looks to me as if what you were looking
for is a nice python dictionary with a tuple as an index.  Since
tuples are immutable, they can be used as indices, while arrays
cannot.

Or, despite finding it interesting, have I misunderstood what
you are doing altogether?

Laura

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Array of Functions richard_riehle <rriehle@itu.edu> - 2015-05-26 19:43 -0500
  Re: Array of Functions Laura Creighton <lac@openend.se> - 2015-05-27 03:05 +0200
  Re: Array of Functions Gary Herron <gary.herron@islandtraining.com> - 2015-05-26 18:18 -0700

csiph-web