[Wellington-pm] SEND + MORE = MONEY

Steve Wray stevew at catalyst.net.nz
Wed Mar 2 21:14:39 PST 2005


Malcolm Allison wrote:
> so $a + $a == 1 if $a != $a?
> 
> this seems a little like cheating to me  ;)

Depends on how well-behaved the arithmetic operators are with respect to 
side-effects: operators changing their operands 'behind your back' like 
some sort functions that don't *return* a sorted list; they change the 
list argument you give them into a sorted list.

Since side-effects are allowed in some languages, like perl,
and since it may be possible in a sufficiently ill-designed language, ,
to have an arithmetic operator 'side-effect' in a really disastrous way,
and indeed $a + $a may come to == 1 when $a starts as 1 and the + 
operator decrements it by 1 part way through the operation.

$a + $a == 1 is only guaranteed in languages that don't allow 
side-effects, eg prolog, haskell, caml, maybe even lisp.

It can really help when trying to figure out what a program does, 
because you can always be sure that whatever happens, happens 'in front' 
of you and that no operators or functions will make any state changes 
which don't involve their return values. This gets just a little messy 
when it comes to IO
:)

> In message <422694C1.7010600 at vilain.net>, Sam Vilain writes:
> 
>>   use Quantum::Superpositions;
[snip]
> 
> $a + $a == 1  is possible if the first $a is taken as 1, and the second
> $a is taken as 0 (or vice versa).  Where as there is no value in $a
> which can be multiplied by 2 and yeild 1 (you get 2 or 0).



More information about the Wellington-pm mailing list