Alan,
That's no good. You still get something printed out. In this case:
None
Jeff
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 6:15 PM
To: Smith, Jeff; Bob Gailer; tutor@python.org
Subject: Re: [Tutor] Are you allowed to shoot
:-)
Jeff
-Original Message-
From: Jeff Shannon [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 9:19 PM
To: tutor@python.org
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
Alan Gauld wrote:
As an aside, I did try to create a lambda based solution
That's no good. You still get something printed out. In this case:
None
Of course, silly me, p will return the default value None, you need
to replace the pass with return '' or, I guess use the lambda...
ftable = { 'a' : lambda: 'a',...
'd' : lambda: ''}
Now it should work
PROTECTED]
Sent: Tuesday, February 08, 2005 1:24 PM
To: Smith, Jeff; Bob Gailer; tutor@python.org
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
That's no good. You still get something printed out. In this case:
None
Of course, silly me, p will return the default value None
Smith, Jeff wrote:
Jeff,
It looks like that finally is the simplest expression of the original
switch statement:
import sys
def p():
pass
ftable = { 'a' : lambda: sys.stdout.write('a\n'),
'b' : lambda: sys.stdout.write('b or c\n'),
'c' : lambda: sys.stdout.write('b or
Not to be nit-picky but it's still not the same. The switch would
give
no output but yours would give a newline. I think the sys write
solution would be the closest equivalent...and took a lot longer for
us
to code correctly :-)
I can't really argue with that! :-)
Me, I'm blaming the
table = { 'a': 'a', 'b': 'b or c', 'c': 'b or c', 'd': None }
result = table.get(var, 'default case')
if result:
print result
This, to my mind, is much cleaner -- you're factoring out the
repeated
code, whether print statement or call to sys.stdout.write(),
reducing
the complexity of
At 07:14 AM 2/7/2005, Smith, Jeff wrote:
Alan,
No use beating this dead horse...I guess that's why there are so many
languages in the first place. Different people are comfortable with
different things. (I did warn you that I like both Lisp and Prolog and
only wish I had more of a reason to use
Subject: RE: [Tutor] Are you allowed to shoot camels? [kinda OT]
At 07:14 AM 2/7/2005, Smith, Jeff wrote:
Alan,
No use beating this dead horse...I guess that's why there are so many
languages in the first place. Different people are comfortable with
different things. (I did warn you that I
At 07:43 AM 2/7/2005, Smith, Jeff wrote:
That's kinda what I thought but a couple of people suggested that I used
lambdas to make it clearer that I figured I was doing something wrong...
Well you can use lambdas. Have them return an expression which you print
after retrieving:
ftable = { 'a' :
:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 10:10 AM
To: Smith, Jeff; tutor@python.org
Subject: RE: [Tutor] Are you allowed to shoot camels? [kinda OT]
At 07:43 AM 2/7/2005, Smith, Jeff wrote:
That's kinda what I thought but a couple of people suggested that I
used lambdas to make
Bob Gailer wrote:
At 07:14 AM 2/7/2005, Smith, Jeff wrote:
Alan,
No use beating this dead horse...I guess that's why there are so many
languages in the first place. Different people are comfortable with
different things. (I did warn you that I like both Lisp and Prolog and
only wish I had more
As an aside, I did try to create a lambda based solution but was
unable.
Let me know what's wrong:
ftable = { 'a' : lambda: print 'a',
SyntaxError: invalid syntax
I did say if Python had *proper* lambdas...
Unfortunately Python insists on only having *expressions* as
lambdas and since print
That's kinda what I thought but a couple of people suggested
that I used lambdas to make it clearer
I suggested that if we had proper lambdas we could use 'em...
But of course you can still use lambdas just put the print
at the client side:
def p(): pass
ftable = { 'a' : lambda: 'a',
Well you can use lambdas. Have them return an expression which you
print
after retrieving:
ftable = { 'a' : lambda: 'a',
'b' : lambda: 'b or c',
But it would be clearer to store just the expressions:
ftable = { 'a' : 'a',
'b' : 'b or c',
True for this special
at 0x009BDFB0
That's hardly a pass :-)
Jeff
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Monday, February 07, 2005 3:06 PM
To: Smith, Jeff; Bob Gailer; tutor@python.org
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
That's kinda what I thought
That's actually worse than you might think. Try this:
def p(): pass
ftable = { 'a' : lambda: 'a',
'd' : lambda: p}
That should be:
'd': p}
ie No lambda used at all.
I wish Python had real lambdas!
And what you get is:
function p at 0x009BDFB0
Yep, coz the lambda
Alan Gauld wrote:
ie No lambda used at all.
I wish Python had real lambdas!
If python had real lambda's then it would be lisp or schema.
__
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
Alan Gauld wrote:
As an aside, I did try to create a lambda based solution but was
unable. Let me know what's wrong:
ftable = { 'a' : lambda: print 'a',
SyntaxError: invalid syntax
I did say if Python had *proper* lambdas...
Unfortunately Python insists on only having *expressions* as
lambdas and
Even more OT it would seem, but harking back to the original subject,
Perl isn't looking too bad because I've been working through Java
tonight.
$j = STDIN; is relatively intuitive for a child of Unix, and it's
also documented.
BufferedReader keyboard = new BufferedReader(new
Jacob S. wrote:
aFuncList=[]
def x():
print one
aFuncList.append(x)
def x():
print two
aFuncList.append(x)
def x():
print three
aFuncList.append(x)
for item in aFuncList:
item()
Okay, for this problem (it can be altered otherwise)
def makefunct(stri):
def x():
Surely you jest, Alan. :-)
Smiley noted but...
Both perl and awk are turing complete, hence anything perl can do,
awk
can do as well.
This is a popular misconception.
Being Turing complete simply means you can implement any algorithm.
But if the language doesn't provide I/O access for
Alan Gauld wrote:
Sean, what book/tutor are you using for Haskell?
I learned it from The Haskell School of Expression which
was OK but very graphics focused, I'd be interested in
recommended second source on Haskell.
as with Max I am reading Haskell: Craft of Functional Programming. I am
about
We'll just have to have to disagree about awk. I starting
learning Perl
to avoid learning awk :-)
But awk is smaller and simpler than perl. So it should be faster
(esp. at startup) for small and simple tasks.
As usual: Right tool for right task.
awk starts faster but perl is more
Sean, what book/tutor are you using for Haskell?
I'm not Sean,
Oops, sorry, I picked the name from the post I was replying
to, apologies!
but I'm using Simon Thompson's Haskell: The Craft of
Functional Programming, which I find quite good. However, it's a
bit
odd, in that it almost reads
The reasons for the KR style of brace winning is to do
with the way the brain process structure and despite
the subjects stated preference for the 'Pascal' style
they still had lower perception scores.
Little nit-picking here:
if(foo)
{
bar();
}
Is not KR style, but Allman style.
On Thursday 03 February 2005 17:41, Alan Gauld wrote:
In fact the best style of all is neither of the two I showed,
its actually this - which early everyone hates when they see it!
inf f(x)
{
bah()
}
Ugh. Alan, I won't even try to dispute the study. But if I have to
write code
and function. Its like the theory behind how elictricity
Yikes! Did I really manage to type elictricity
And I can't blame finger trouble, e and i are miles
apart on the keyboard!
Blush
Alan G.
___
Tutor maillist - Tutor@python.org
. Nothing beats it for clarity of
expression.
Jeff
-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 03, 2005 6:29 PM
To: Smith, Jeff; Jacob S.; [EMAIL PROTECTED];
tutor@python.org
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
Perl
]
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
We'll just have to have to disagree about awk.
I starting learning Perl to avoid learning awk :-)
Really? Why for? awk is far easier to learn than Perl
- and far less generally capable! - but it makes Perl seem
positively verbose
What you are try to do is execute a block of code based on the
value of
a single statement. if/elif doesn't do that and thereby introduces
the
possibility of errors.
In that case the best solution is a dictionary jump table.
That is more maintainable than either and much faster too.
And its
Max Noel wrote:
According to the Jargon file, this one is called Whitesmiths
style. I tend to use Allman style myself, but given the code
completion, spellchecking, etc. in modern IDEs, I suspect it's
become
more a question of personal preference than anything else.
A bit like
Disagree to disagree again. I certainly don't think Perl is less
capable than awk.
Neither do I...
Really? Why for? awk is far easier to learn than Perl
- and far less generally capable! - but it makes Perl seem
positively verbose!
I said awk was easier to learn but less capable
Smith, Jeff wrote:
IMHO, if/elif/else statements are far more abused than either switch or
ternary but I certainly wouldn't argue they should be removed from the
language.
IMHO, if it's true that if/elif/else statements are more abused than
ternaries, then it's only because they're *used* far
: [Tutor] Are you allowed to shoot camels? [kinda OT]
What you are try to do is execute a block of code based on the
value of
a single statement. if/elif doesn't do that and thereby introduces
the
possibility of errors.
In that case the best solution is a dictionary jump table
Now who's joking?
:-)
Are you saying that
switch var:
case 'a':
print 'a'
...
default:
print 'default case'
Is less clear and maintainable than
I don;tthink I said (certainly didn't mean) less clear, but
yes it is less maintainable.
But then...
def do_this_function():
an experience where a rogue process or editor has trashed the
indentation in your Python and how you recovered from it.
Only in mailing list emails!!
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Now this is a concrete example of how lambda simplifies code, at
least
for me because it does not clutter my mental name space. Also it is
much shorter. However it should be said that this is very much a
question of taste.
Agreed. Which would make it pointless to remove in a future release. ;-)
Alan Gauld wrote:
I said awk was easier to learn but less capable than Perl.
Perl is capable of things that awk can only dream of!
Surely you jest, Alan. :-)
Both perl and awk are turing complete, hence anything perl can do, awk
can do as well. Now, as to which one would be easier to work with
an experience where a rogue process or editor has trashed the
indentation in your Python and how you recovered from it.
Only in mailing list emails!!
I'll second that!!!
Jacob
Alan G.
___
Tutor maillist - Tutor@python.org
Andrew D. Fant said unto the world upon 2005-02-04 18:27:
Alan Gauld wrote:
I said awk was easier to learn but less capable than Perl.
Perl is capable of things that awk can only dream of!
Surely you jest, Alan. :-)
I'm prettry sure he means it. And stop calling him Surely ;-)
Brian vdB
Just wondering if I should bite the bullet and code from scratch in
Perl, or if my Python - Perl is Ok.
Its nearly always a bad idea to just translate code structures from
one language to another. It will usually be sub optimal and non
idiomatic - thus harder for the 'native' programmers to
How's Ruby? I bookmarked the homepage, but never got around to
looking
at it.
Very, very nice. Cleanest object-orientedness I ever saw in a
language
(not that I have that much experience -- people like Alan would
probably be better judges than me on this).
You knew I couldn't resist! :-)
On Feb 3, 2005, at 09:48, Alan Gauld wrote:
Pythons lambda feature is a bare minimum (and Guido wants to remove
it!).
Does he? Damn, just when I was learning functional programming! (in
Haskell, if you're curious ^^)
Yes the Japanese thing is an issue.
THere are a few English books now, and the
code to run it on a different platform. But most existing Java projects
have platform-specific versions, if only to make the GUI (try to) look
native. You can spot a Java app from a hundred meters away.
(then again, the same critic could be made of Python's and Perl's
standard GUI
all the arguments but I just don't agree
with the design choice.
Jeff
-Original Message-From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 03, 2005 8:43 AMTo:
tutor@python.orgSubject: Re: [Tutor] Are you allowed to shoot camels?
[kinda OT]
Well, here's my $0.02. I would
I once heard that Larry Wall said, Perl is worse than Python because
people needed it worse.
And I've heard it said that Perl is the Write-Only language
Marilyn
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
[EMAIL PROTECTED] wrote:
Btw, I'm skeptical that the code below does what you want it
to do. :-)
that was kind of my point. In python I just type the obvious and it
works. In Perl I have to muck with references, slashes, arrows and
the
like. Every time I have had to write a
Max Noel wrote:
On Feb 3, 2005, at 09:48, Alan Gauld wrote:
Pythons lambda feature is a bare minimum (and Guido wants to remove
it!).
Does he? Damn, just when I was learning functional programming! (in
Haskell, if you're curious ^^)
However, Python doesn't need lambdas to be able to write in
Jeff Shannon wrote:
However, Python doesn't need lambdas to be able to write in a functional
style. Functions are first-class objects and can be passed around quite
easily, and IIRC Python's list comprehensions were borrowed (though
probably with notable modification) from Haskell.
Note, it
For the non-Perl people here, let me defend Perl by saying it is
VERY good at what it was built for and not so good (but passable)
at
what it was not built for.
What it is good at:
Very rapid development of small scripts
Replacing sed/awk/ksh/etc for scripting
[mailto:[EMAIL PROTECTED]
Sent: Thursday, February 03, 2005 5:14 PM
To: [EMAIL PROTECTED]; Smith, Jeff
Cc: tutor@python.org; [EMAIL PROTECTED]
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
For the non-Perl people here, let me defend Perl by saying it is
VERY good at what
I also disagree about the symbology. I am never confused by it.
I'll believe you, but its interesting that computer scientists
have done lots of studies to test people's comprehension of programs
and in every single case there has been clear evidence that
additional prefixes/characters etc
: tutor@python.org; [EMAIL PROTECTED]
Subject: Re: [Tutor] Are you allowed to shoot camels? [kinda OT]
I also disagree about the symbology. I am never confused by it.
I'll believe you, but its interesting that computer scientists
have done lots of studies to test people's comprehension
haskell:
[ x | x - xs ]
[ foo x | x - xs, x 2 ]
python
[ x for x in xs ]
[ foo(x) for x in xs if x 2 ]
Sean, what book/tutor are you using for Haskell?
I learned it from The Haskell School of Expression which
was OK but very graphics focused, I'd be interested in
recommended
Perl and Python both resist the introduction of a switch statement
which I (and many others) feel is the most elegant way to express
what it does.
Interesting. What do you feel is the problem with elif?
Its not even much more typing and allows for much more
expressive test conditions.
We'll just have to have to disagree about awk.
I starting learning Perl to avoid learning awk :-)
Really? Why for? awk is far easier to learn than Perl
- and far less generally capable! - but it makes Perl seem
positively verbose!
Alan G.
___
Alan Gauld wrote:
There is no perfect language, and very few truly bad
languages - they never get out of the lab - they all
have something that they are good at and from which
we can learn!
Heh, I'd look at that a bit differently -- I think that there's a
*lot* of bad languages, it's just that
second example. I'm sure what those studies show is what the
majority
find easier not what everyone finds easier.
They are statistical its true, but they were based on the folks
who actually used the second style indent and they actually
got worse scores in the tests using their own style than
On Feb 3, 2005, at 23:19, Alan Gauld wrote:
Sean, what book/tutor are you using for Haskell?
I learned it from The Haskell School of Expression which
was OK but very graphics focused, I'd be interested in
recommended second source on Haskell.
I'm not Sean, but I'm using Simon Thompson's Haskell:
On Feb 3, 2005, at 23:41, Jeff Shannon wrote:
(But then, at my job I'm stuck using a horrible Frankenstein's monster
of a proprietary language on a daily basis, so I can't help but
believe that there's plenty more awful languages around that didn't
happen to be rescued from oblivion by an
Alan Gauld wrote:
However, Python doesn't need lambdas to be able to write in a
functional style.
I disagree Jeff. It does need lambdas to do FP properly, and
better lambdas than we have currently. What it doesn't need
is the lambda keyword and syntax - although pesonally I like
lambda since it
On Thursday 03 February 2005 17:41, Alan Gauld wrote:
In fact the best style of all is neither of the two I showed,
its actually this - which early everyone hates when they see it!
inf f(x)
{
bah()
}
Ugh. Alan, I won't even try to dispute the study. But if I have to
write
Max Noel wrote:
On Feb 3, 2005, at 23:41, Jeff Shannon wrote:
(But then, at my job I'm stuck using a horrible Frankenstein's monster
of a proprietary language on a daily basis, so I can't help but
believe that there's plenty more awful languages around that didn't
happen to be rescued from
Pythons lambda feature is a bare minimum (and Guido wants to
remove
it!).
However, Python doesn't need lambdas to be able to write in a
functional style.
I disagree Jeff. It does need lambdas to do FP properly, and
better lambdas than we have currently. What it doesn't need
is the lambda
Hi,
Had the *ahem* joy of learning Perl last night. Egad. Wrote the script
in Python to get it right, and then 'translated' it to Perl. Does the
style of coding Python engenders suit the Perl environment in anyone's
experienc? AFAI can see there is no real 'style' to Perl, apart from
white noise
On Feb 2, 2005, at 23:18, Liam Clarke wrote:
1) I'll use Perl for the regex stuff from now on, Perl is obviously
built for this.
Actually IIRC Perl *invented* regexes as we know them. The standard
regex syntax is known as Perl regex syntax.
2 ) There's More Than One Way To Do It makes debugging
(damn, forgot to add the main part of my argumentation)
I learnt Perl as well, a few years ago. It was the first scripting
language I came across (all I knew before that were C, Turbo Pascal,
and a few calculator programming languages), so I immediately fell in
love with its string
I don't find it that bad. Ruby does it as well, and it's perfectly
readable. It's more or less equivalent as if condition: and
if(condition): both being valid in Python.
Yeah, but you'd never call a function foo like this-
x = foo
in Python. It's just good to be able to say that a function
On Thu, 3 Feb 2005, Liam Clarke wrote:
Had the *ahem* joy of learning Perl last night. Egad. Wrote the script
in Python to get it right, and then 'translated' it to Perl.
Hi Liam,
I strongly recommend sending the Perl code to that Perl-beginners mailing
list referenced earlier. I'm sure
70 matches
Mail list logo