how to get the ordinal number in list

Rustom Mody rustompmody at gmail.com
Tue Aug 12 23:49:36 EDT 2014


On Wednesday, August 13, 2014 12:59:35 AM UTC+5:30, Neil D. Cerutti wrote:

> > Some things follow from this:
> > For the lego-game of playing with functions at the REPL to work and be
> > pleasant and rewarding:
> > 1. functions should be non side-effecting; else same trials giving different
> > answers adds more confusion than understanding
> > 2. They should be non-printing else:
> > def foo(x): return x+1
> > def bar(x): print x+1
> > look similar when trivially tried but compositionally are utterly different
> > In effect a printing function breaks the lego bricks

> That may be so, but printing stuff to the screen is very natural to 
> people. I've downloaded Haskell a few times, but the knowledge that 
> getting input and writing output requires something mysterious called 
> gonads just frightens me.

I thought they were quite common <wink>

But yes...

- Monads in Haskell
- Pointers in C
- Inheritance in Java/Python

all suffer the same problem -- glorification of the failure-mode.

When one uses pointers, especially non-trivial pointer arithmetic in C,
one is essentially blasting a hole in the floor of the hi-level facade
of C and working at machine level.

Inheritance produces coupling whereas the whole intent of modularity is to 
avoid coupling.

Likewise Monads are for imperative programming in Haskell.
Maybe better to just use an imperative language?

> Functional programming could be particularly hard to teach since it is
> generally made up of numerous small units of work combined in a complex
> way. This is precisely the formula for something that beginners will
> find extremely challenging. 

> When functional programming is dumbed down enough for a beginner to be 
> able to grok it, the programming problems start to look really lame. It 
> needn't be that way, of course, but it takes a good deal of creativity 
> on the part of the instructor. If Factorial doesn't turn you on, you 
> might be screwed. ;)

Did you see my example a bit earlier on Catalan numbers?  I believe it
explains them better -- certainly more succinctly -- than the
math+verbiage you can find at:
http://en.wikipedia.org/wiki/Catalan_number

Yes it may be hard to grok but I think its the exact opposite of
'numerous small units'



More information about the Python-list mailing list