maradydd: (Default)
[personal profile] maradydd
A programmer is sent to the grocery store with instructions to "buy butter and see if they have eggs. If they do, buy ten."

Returning with ten butters, the programmer says, "They had eggs."

(no subject)

Date: 2009-08-17 11:16 am (UTC)
From: [identity profile] oliverx.livejournal.com
Actually, there are a bunch of implied bindings in this program, not just one:

buy [one unit of] butter [from some vendor] and see if [that vendor] has [more than one] egg. If [that same vendor] has eggs, buy ten [units] [of those eggs].

We can see all these bindings explicitly by transliterating:

vendor.buy(butter, 1)
see = (vendor.has(egg) >= 1):
if vendor.has(egg) >= 1:
vendor.buy(egg, 10)

There's an obvious bug with 2 < eggs < 10.

I would actually be less surprised with the programmer who came back with 120 eggs. As the minimum purchase unit is typically 12, buying 10 units seems to be implied. This programmer would apply his standard vegan substitution rules and return with one tub of Earth Balance margarine and ten boxes of Egg Replacer (about 800 egg equivalents).

This parsing bug is significantly less serious than failure to properly track implied subjects and objects, as that parser feature is generally invoked multiple times per line of input.

Here's a related bug:

"Buy cookies and see if they have eggs. If they do, buy ten."

The programmer may return with 10 boxes of cookies if said cookies are made with eggs. The buggy parsing rule is "bind [they] to the last plural mentioned".

Profile

maradydd: (Default)
maradydd

September 2010

S M T W T F S
   1234
567891011
12131415 161718
19202122232425
26 27282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags