> By what magic might we turn a string object into
> a top-level name: that is the question this lesson
I do have an answer in the queue, my proposed solution.
However I'd be happy to see others toss in some ideas,
just to test whether my lesson plan is clear enough to
get across what the challenge is.
On another front, I'm wanting to tell the story of free
and open source software to a next generation of teen,
and wondered if FOSS veterans here would have any
feedback regarding the following thumbnail:
GNU = GNU is not Unix and was the original inspiration for the
free software movement, centered on what become known as
the GNU Public License (GPL).
The GPL was a way for copyright holders to insist that their hard
work not be used only selfishly by others, that the fruits of their
labors achieve maximum positive benefit for omni-humanity, to
put a Global U spin on it.
Once the GPL was out there getting the work done (e.g. Linux),
a safe-enough ecosystem was developed for a bevy of alternative
licensing schemes, some of which allow shops to take something
inhouse, transform it, and release it under a more restrictive
license agreement, if they release it at all.
[ Python could be an example of this, in that developers of the
IronPython codebase have been enabled to start with CPython,
the original version, with the resulting codebase being free and
open source under a different set of rules from the GPL or even
from whatever the original Python was using. Actually, the story
is more complicated than that, in that Jim H. first worked on the
Java implementation before moving to C# in an attempt to prove
the CLR (common language runtime) engine was unsuitable for
dynamic languages. He came to the conclusion that the CLR
engine could work, hence the IronPython project. ]
The original context is some Google group (a new one). The
relevant thread is accessible from this blog post FYI:
Technically, your use of globals() instead of locals(), like I did, is better, in that it allows you to have it inside a function body, and still be available at the module level, as per your stated goal.
However, I find the use of lambda to be too restrictive, in principle, as it obviously works only for expressions, and not complex functions. If this example is to be used as a prototype to show students how to do this kind of name assignment, then the way I have done it with an inner named function (which I first learned about *years* ago, from a post from you on edu-sig! I believe it was http://mail.python.org/pipermail/edu-sig/2005-March/004590.html) is a better way to go.
On Thu, May 27, 2010 at 3:15 AM, Andre Roberge <[hidden email]> wrote:
> On Thu, May 27, 2010 at 2:52 AM, kirby urner <[hidden email]> wrote:
>> > Much appreciated André!
> It was a fun challenge.
>> > I think our solutions are similar:
>> ... yours is better though, in that you don't make use of exec.
>> My use of it was superfluous.
>> Changing my solution, in light of yours:
>> def makeroot(N):
>> assert type(N)==type(1) and N>=0
>> raise ValueError("0 <= N <= integer")
>> fname = "root" + str(N)
>> if N==0:
>> globals()[fname] = lambda x: pow(x, 0)
>> globals()[fname] = lambda x: pow(x, float(1)/N)
>> for i in range(11):
> Technically, your use of globals() instead of locals(), like I did, is
> better, in that it allows you to have it inside a function body, and still
> be available at the module level, as per your stated goal.
> However, I find the use of lambda to be too restrictive, in principle, as it
> obviously works only for expressions, and not complex functions. If this
> example is to be used as a prototype to show students how to do this kind of
> name assignment, then the way I have done it with an inner named function
> (which I first learned about *years* ago, from a post from you on edu-sig!
> I believe it was
> http://mail.python.org/pipermail/edu-sig/2005-March/004590.html) is a better
> way to go.
Yes sir, I agree. The Python lambda is weak (on purpose) in not providing
for full scale anonymous functions. Binding to the function object returned
by an inner function def is a more liberal strategy, allows for more
This thread will document these suggestions and nuances.