Other notes

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Jan 5 19:40:47 EST 2005


Thank you to all the gentle people that has given me some comments, and
sorry for bothering you...

Doug Holton:

>This will also likely never appear in Python.

I know, that's why I've defined it "wild".


>Also, you might request the NetLogo and StarLogo developers to support
Jython (in addition to Logo) scripting in their next version<

I was suggesting the idea of adding the complex data structures of
NetLogo (patches, etc) to the normal Python.

-------------

Andrew Dalke:

>(BTW, it needs to be 1 .. 12 not 1..12 because 1. will be interpreted
as the floating point value "1.0".)<

Uhm, I have to fix my ignorance about parsers.
Cannot a second "." after the first tell that the first "." isn't in
the middle of a floating point number?


>In Pascal it works because you also specify the type and Pascal has an
incr while Python doesn't.<

The Pascal succ function (that works on chars and all integer types) is
often useful (it's easy to define it in Python too).


>>This may allow: assert 5 interval 9 == interval(5,9)
>Maybe you could give an example of when you need this in real life?<

Every time you have a function with 2 parameters, you can choose to use
it infix.


>Does this only work for binary or is there a way to allow unary or
other n-ary (including 0-ary?) functions?<

It's for binary functions only.
For unary the normal fun(x) syntax is good enough, and for n-ary the
sintax becomes unnecessary complex, and you can use the normal function
syntax again.


>But to someone with C experience or any language which derives its
formatting string from C, Python's is easier to understand than your
Pascal one.<

You can be right, but "understanding" and "being already used to
something" are still two different things :-)


>A Python view is that there should be only one obvious way to do a
task. Supporting both C and Pascal style format strings breaks that.<

Okay.


>I don't think Pascal is IEEE enough.<

Well, if you assign that FP number inside the program (and not as a
constant) Delphi 4 too gives a more "correct" answer ^_^ (I don't
know/remember why there are such differences inside Delphi between
constants and variables).


>note also that the Pascal-style formatting strings are less capable
than Python's,<

I know...


>though few people use features like<

Right.


>A real-life example would also be helpful here.<

(I was parsing trees for Genetic Programming).
People here can probably suggest me 10 alternative ways to do what I
was trying to do :-)
As list comprehensions, that suggestion of mine cannot solve new kinds
of problems, it's just another way of doing things.


>What does  map(len, "Blah", level = 200)  return?<

Well:
"c" == "c"[0][0][0][0][0][0]
map(len, "blah") == [1, 1, 1, 1]
So I think that answer is still [1, 1, 1, 1].


>You need to learn more about the Pythonic way of thinking of things.
The usual solution for this is to have "level = None".<

To Steven Bethard I've suggested an alternative syntax (using a
level-ed flatten with a standard map command).


>There's also tmPython.<

Thank you, the screenshoots are quite nice :-)
http://dkbza.org/11.0.html

--------------

Steven Bethard:

>Since I can't figure it out intuitively (even with examples), I don't
think this syntax is any less inscrutable than '%<width>.<decimals>f'.<

Well, I haven't given a textual explanation, but just few examples.


>My suspicion is that you're just biased by your previous use of
Pascal.<

This is possible.


>This packs two things into map -- the true mapping behaviour (applying
a function to a list) and the flattening of a list.<

Okay, then this is my suggestion for the syntax of an iterable
xflatten:
xflatten(sequence, level=-1, monadtuple=False, monadstr=True,
safe=False])

- level allows to specify the mapping level:
level=0 no flattening.
level=1 the flattening is applied to the first and second level.
Etc.
And like in the indexing of lists:
level=-1 (default) means the flattening is applied up to the leaves.
level=-2 flattens up to pre-leaves.
Etc.
- monadtuple (default False) if True tuples are monads.
- monadstr (default True) if False then strings with len>1 are
sequences too.
- safe (default False) if True it cheeks (with something like an
iterative isrecursive) for recursive references inside the sequence.


>(Also, Google for flatten in the python-list -- you should find a
recent thread about it.)<

I've discussed it too in the past :-)
http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/d0ba195d98f35f66/


>and that your second example gains nothing over<

Right, but maybe with that you can unify the def and lambda into just
one thing ^_^


>def foo(x):
>    globals()['y'] = globals()['y'] + 2
>Not exactly the same syntax, but pretty close.

Thank you for this idea.


>I'll second that. Please, "Bearophile", do us the courtesy of checking
[...] before posting another such set of questions. While most of the
people on this list are nice enough to answer your questions anyway,
the answers are already out there for at least half of your questions,
if you would do us the courtesy of checking first.<

I've read many documents, articles and PEPs and, but I'm still new, so
I've missed many things. I'm sorry... I'm doing my best.

-----------

Terry J. Reedy

>I also suggest perusing the archived PyDev (Python Development mailing
list) summaries for the last couple of years (see python.org). Every
two weeks, Brett Cannon has condensed everything down to a few pages.<
Okay, thank you.

Bear hugs,
Bearophile




More information about the Python-list mailing list