Re: [Tutor] (OT) Flame wars

2006-11-07 Thread Alan Gauld

Tim Johnson [EMAIL PROTECTED] wrote 
 allows us to embed loops and all sorts, effectively adding new
 command structures to the language in a way that only Lisp
 and Tcl have really been good at up till now.
 
  Sorry Alan, but you are leaving out rebol. Command structures
  in rebol are are just functions and IMHO, easier to roll your
  own than lisp macros.

Quite right, I forgot rebol.

I played with it briefly and it is a lot of fun for network 
programming, but ultimately I ran out of steam with it too 
often so gave up. 

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (OT) Flame wars (was: Amazing power of Regular Expressions...)

2006-11-06 Thread Carroll, Barry
Greetings, all:

 -Original Message-
 Date: Mon, 6 Nov 2006 10:32:32 +
 From: Michael Sparks [EMAIL PROTECTED]
 Subject: Re: [Tutor] Amazing power of Regular Expressions...
 To: tutor@python.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain;  charset=iso-8859-1
 
 On Monday 06 November 2006 01:08, Alan Gauld wrote:
  While using a dictionary is probably overkill, so is a rage.
 
 No, in this case it's absolutely the right choice.
 
  A simple string holding all characters and an 'in' test would
probably
  be both easier to read and faster.
 
 I'm stunned you think this. It's precisely this sort of naivete that
 baffles
 me with regard to regales.
 
  Which kind of illustrates the point of the thread I think! :-)
 
 Actually, no, it doesn't.
 
snip
 
 I'm serious, if you think ^[0-9A-Za-z_.-]*$ is unclear and complex, go
 away
 and relearn regales.
 
 Michael.
 

With the final sentence above, this thread has ceased to be an
intellectual discussion and become a religious argument.  Until then, I
was enjoying an informative discussion by knowledgeable people on a
topic of considerable interest.  Now I'm upset by the implications of
the statement and embarrassed on behalf of the writer.

When a person his so convinced of his/her rightness that they feel
justified in insulting those in opposition, that person has substituted
flaming for advocacy.  They have also, in my opinion, seriously weakened
their position on the subject.  Why would someone resort to such an
attack if they were, in fact, correct?  

I am disappointed to see such behavior on this list, and I hope it's
occurrence will continue to be vanishingly small.  

Regards,
 
Barry
[EMAIL PROTECTED]
541-302-1107

We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars (was: Amazing power of Regular Expressions...)

2006-11-06 Thread Chris Hengge
Wow... I had to click this e-mail just because I saw the first posts on the mentioned thread and could see it turning for the worst..  I'm serious, if you think ^[0-9A-Za-z_.-]*$ is unclear and complex, go away
 and relearn regales. Michael.If this is your method to helping people, you should be the one to step back and go away. While your at it, go an take an educated look at debates.. You might learn that your tactics for trying to sway your side of the opinion are harsh and completely self killing. Any point you were trying to make just became invalid because of this childish b/s. 
On 11/6/06, Carroll, Barry [EMAIL PROTECTED] wrote:
Greetings, all: -Original Message- Date: Mon, 6 Nov 2006 10:32:32 + From: Michael Sparks [EMAIL PROTECTED] Subject: Re: [Tutor] Amazing power of Regular Expressions...
 To: tutor@python.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain;charset=iso-8859-1
 On Monday 06 November 2006 01:08, Alan Gauld wrote:  While using a dictionary is probably overkill, so is a rage. No, in this case it's absolutely the right choice.
  A simple string holding all characters and an 'in' test wouldprobably  be both easier to read and faster. I'm stunned you think this. It's precisely this sort of naivete that baffles
 me with regard to regales.  Which kind of illustrates the point of the thread I think! :-) Actually, no, it doesn't.snip I'm serious, if you think ^[0-9A-Za-z_.-]*$ is unclear and complex, go
 away and relearn regales. Michael.With the final sentence above, this thread has ceased to be anintellectual discussion and become a religious argument.Until then, I
was enjoying an informative discussion by knowledgeable people on atopic of considerable interest.Now I'm upset by the implications ofthe statement and embarrassed on behalf of the writer.When a person his so convinced of his/her rightness that they feel
justified in insulting those in opposition, that person has substitutedflaming for advocacy.They have also, in my opinion, seriously weakenedtheir position on the subject.Why would someone resort to such an
attack if they were, in fact, correct?I am disappointed to see such behavior on this list, and I hope it'soccurrence will continue to be vanishingly small.Regards,Barry
[EMAIL PROTECTED]541-302-1107We who cut mere stones must always be envisioning cathedrals.-Quarry worker's creed___
Tutor maillist-Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars

2006-11-06 Thread Danny Yoo

 Wow... I had to click this e-mail just because I saw the first posts on the
 mentioned thread and could see it turning for the worst..

Hi everyone,

So let's try to squash this one now.  There are more interesting problems 
to solve.  Or other flame wars to fight.


Let me see if we can do something constructive.  I've been doing a 
shallow, superficial study of the Ruby language at the moment.  One of the 
things I've been impressed about is that they've managed to make lambdas 
look non-threatening to people with their syntactic sugar of code 
blocks.

For example,

## Ruby #
def twice
 yield
 yield
twice { puts hello world }
#

This prints out hello world twice in a row: the twice() function takes 
in an implicit code block, which it can later call by using their 
'yield' statement.  What the Ruby folks are doing is trying to make the 
use of higher-order procedures look really simple.  In fact, most of the 
encouraged idiom style I've seen so far extensively uses this code style 
pervasively (especially for iteration), and that's very admirable.


The exact functionality can be done in Python, but it does look a little 
more intimidating at first:

 ## Python
 def twice(f):
 f()
 f()
 twice(lambda: sys.stdout.write(hello world\n))

This does the same thing, but it looks a little scarier because the 
concepts needed to grasp his are superficially harder than that in the 
Ruby code.


Anyway, let's derail off this regex flamewar and get us back to talking 
about code and about stuff that actually matters, like learning how to use 
functions well.. *wink*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars

2006-11-06 Thread Alan Gauld
Danny Yoo [EMAIL PROTECTED] wrote
 So let's try to squash this one now.  There are more interesting 
 problems
 to solve.  Or other flame wars to fight.

I wasn't aware we were having a war, but I'm happy to desist :-)

 Let me see if we can do something constructive.  I've been doing a
 shallow, superficial study of the Ruby language at the moment.  One 
 of the
 things I've been impressed about is that they've managed to make 
 lambdas
 look non-threatening to people with their syntactic sugar of code
 blocks.

Ruby blocks are almost as good as Smalltalk blocks for this
kind of thing and very powerful. Regular readers will know I have
often expressed dissappointment at the limitations of Python's
lambdas, it's one thing the Ruby boys have got right IMHO.

 The exact functionality can be done in Python, but it does look a 
 little
 more intimidating at first:

 ## Python
 def twice(f):
 f()
 f()
 twice(lambda: sys.stdout.write(hello world\n))

 This does the same thing, but it looks a little scarier because the
 concepts needed to grasp his are superficially harder than that in 
 the
 Ruby code.

The other advantage in Ruby is that the block can be arbitrarily
complex, not just a single expression as in a Python lambda. This
allows us to embed loops and all sorts, effectively adding new
command structures to the language in a way that only Lisp
and Tcl have really been good at up till now.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars

2006-11-06 Thread Luke Paireepinart
Chris Hengge wrote:
 I may have just missed the point to your attempt to derail this 
 conversation =P
Ah, well, don't worry.  I didn't learn of lambda until I'd been using 
Python for a year or more.
I was trying to pass arguments to callbacks in TKinter.
one of the Pythonistas (Alan, Danny, Kent) told me Oh, that's trivial 
with lambda
and since then, I've tried to read up on lambda and Functional 
Programming in general.
 However..

 Why do all that when you can just

 str = Hello World
 print str * 2

 (Maybe I missed some concept that this small example doesn't accuratly 
 reflect)
Yes, I do believe you're correct here, Chris :)
I will not presume to know enough about lambda to explain it to you,
but I will refer you to these articles:
http://www.secnetix.de/~olli/Python/lambda_functions.hawk
and Alan Gauld's tutorial, of course :)
specifically, the page
http://www.freenetpages.co.uk/hp/alan.gauld/tutfctnl.htm

Or browse there from the main page
http://www.freenetpages.co.uk/hp/alan.gauld/
click 'functional programming'  under Advanced Topics'
if you want the menu frame to remain on the left of the screen.


Consider this:
You don't say
outputstring = Hello, World!
print outputstring

because you're only using the string once, and it's not something that 
would look ugly all on one line.
Instead, you do
print Hello, World!


An alternate example:
a_list = [[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a],
[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a],
[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a],
[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a]]
print a_list

would make more sense than

print [[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a],
[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a],
[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a],
[a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a,b,a]]

because then if you need to change the list, or use it again somewhere,
you don't have to go through the pain of typing it out each time,
since in the first case, you assigned it to a variable, a_list.


The long and short of it is: (or more specifically, the short of it)
 lambda lets you define functions you don't have to bind to a name.
so, supposing you have the function
def call_a_function(a_function):
a_function()

That will call a function object,
you can do something like this:
def f():
sys.stdout.write(Hello, World!)
call_a_function(f)

or you could do
call_a_function(lambda: sys.stdout.write(Hello, World!))

It's like the string example above.  It's a waste to have the function 
definition on two lines,
and the call on another line, if the function's compact enough to fit on 
a single line using lambda.
But also note that you can't reuse the lambda function unless you store 
it in a variable.
In this way, it's similar to the 'print Hello, World!' statement.



I hope that helps you, Chris.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars

2006-11-06 Thread Tim Johnson
* Alan Gauld [EMAIL PROTECTED] [061106 14:01]:
 
 The other advantage in Ruby is that the block can be arbitrarily
 complex, not just a single expression as in a Python lambda. This
 allows us to embed loops and all sorts, effectively adding new
 command structures to the language in a way that only Lisp
 and Tcl have really been good at up till now.
 

  Sorry Alan, but you are leaving out rebol. Command structures
  in rebol are are just functions and IMHO, easier to roll your
  own than lisp macros.

  But with freedom comes responsibility.
  (Tim: rebol = 50% python = 50%)

-- 
Tim Johnson [EMAIL PROTECTED]
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars

2006-11-06 Thread Danny Yoo


On Mon, 6 Nov 2006, Chris Hengge wrote:

 I may have just missed the point to your attempt to derail this 
 conversation =P

Hi Chris,

Ah!  Are we talking about regular expressions anymore?

No?

Good.  *grin*



 Why do all that when you can just

 str = Hello World
 print str * 2

Let me do a more substantial example.  As you know, Python's for loop 
works on iterables:

#
 for x in list(hello):
...print x
...
h
e
l
l
o
#

We're running a for loop across a list of characters.  In this case, our 
list is iterable.  (We could iterate directly on the string itself, but 
let's stick with lists for the moment.)  An iterable in Python is 
something that can give us an iterator.

###
 my_iterator = iter(list(hello))
###


An iterator is something that responses to next() requests until we 
consume everything:

#
 my_iterator.next()
'h'
 my_iterator.next()
'e'
 my_iterator.next()
'l'
 my_iterator.next()
'l'
 my_iterator.next()
'o'
 my_iterator.next()
Traceback (most recent call last):
   File stdin, line 1, in ?
StopIteration
##


So there's a few layers of indirection here.

 iterable - iterator - elements


Ruby takes a different approach: they also have an iterator protocol, but 
what they require is something that provides an each() method.  For 
example:


irb(main):002:0 'hello'.split(//).each {|c| puts c}
h
e
l
l
o


This each method takes in a code block, and runs it on every element in 
the thing we're iterating across.  The iterable itself provides the 
looping mechanism instead of the client code.


The concept sorta looks like this in Python:

###
class MyString:
 def __init__(self, s):
 self.s = s

 def each(self, f):
i = 0
while i  len(self.s):
f(self.s[i])
i = i + 1

MyString(hello).each(lambda c: sys.stdout.write(c + '\n'))


This, too, iterates across our iterable.

The one handling the control flow is the 'each' method, which is a little 
wacky to think about at first.  The Ruby folks make this work because 
their syntax is custom tailored for this pattern, so it's easier to read 
and write.

I'm probably not doing it much justice with my ugly examples.  *grin*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (OT) Flame wars

2006-11-06 Thread Michael Sparks
On Monday 06 November 2006 22:52, Alan Gauld wrote:
 I wasn't aware we were having a war, but I'm happy to desist :-)

FWIW, I wasn't aware of one either. (Mind you I've often noticed what passes 
for plain speaking in the UK passes for vehement flame war elsewhere, so 
maybe that's it)

Anyway, if that's what people here think a flame war looks like... Well, a) 
I'll try and avoid such /mild/ comments in future ;) b) good for such people, 
real flame wars are really nasty !


Michael.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor