Functional Funny

The following is a correct implementation of Max over a list in a pattern-matching language like Mathematica. It has an amusing fault. Can you spot it?

 Max[{}] := -Infinity;

Max[{x_, xs___}] := x if x > Max[{xs}];

Max[{x_, xs___}] := Max[{xs}] otherwise;

Advertisements

~ by rebcabin on June 15, 2008.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: