Python and Flaming Thunder

Nick Craig-Wood nick at craig-wood.com
Thu May 22 16:30:07 EDT 2008


Mel <mwilson at the-wire.com> wrote:
>  Mensanator wrote:
> > On May 22, 10:30??am, Nick Craig-Wood <n... at craig-wood.com> wrote:
> >> Dave Parker <davepar... at flamingthunder.com> wrote:
> >> > But after getting input from children and teachers, etc, it started
> >> > feeling right.
> >>
> >> > For example, consider the two statements:
> >>
> >> > x = 8
> >> > x = 10
> >>
> >> > The reaction from most math teachers (and kids) was "one of those is
> >> > wrong because x can't equal 2 different things at the same time".
> >>
> >> This is a common feature in functional languages...
> >>
> >> Eg
> >>
> >> Erlang (BEAM) emulator version 5.6.2 [source] [smp:2]
> >> [async-threads:0] [kernel-poll:false]
> >>
> >> Eshell V5.6.2 ??(abort with ^G)
> >> 1> X = 8.
> >> 8
> >> 2> X = 10.
> >> ** exception error: no match of right hand side value 10
> >> 3>
> >>
> >> That error message is the erlang interpreter saying "Hey I know X is
> >> 8, and you've said it is 10 - that can't be right", which is pretty
> >> much what math teachers say too...
> > 
> > Are you saying that erlang treats 1> as an assignment, yet
> > treats 2> as a comparison?
> > 
> > That's inconsistent. No wonder nobody uses erlang.
> 
>  In Prolog terms, they're both unification.  If X has never been defined you
>  can define it as 8 with no chance of contradicting anything.  Once X is 8,
>  the proposition "X is 10" is false.
> 
>  I act as though Erlang thinks the same. My Erlang chops aren't as good as my
>  Prolog chops were.

I had to look up the definition of unification, but yes you are right,
erlang and prolog seem mean roughly the same thing by the = sign.  It
is called the pattern matching operator in erlang.

>From Armstrong's book: The expression Pattern = Expression causes
Expression to be evaluated and the result matched against Pattern. The
match either succeeds or fails. If the match succeeds any variables
occurring in Pattern become bound.

It is a very powerful idea and one which (along with the concurrency
and message passing from Erlang) has been implemented for python :-

  http://candygram.sourceforge.net/

I've been reading the Erlang book and I have to say it has given me a
lot of insight into python...

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list