From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sun, 4 Oct 2009 03:03:27 +1100 From: Sam Watkins To: 9fans@9fans.net Message-ID: <20091003160327.GA15021@nipl.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) Subject: [9fans] mishandling empty lists - let's fix it Topicbox-Message-UUID: 7cd4521a-ead5-11e9-9d60-3106f5b1d025 hi, I wanted to have a whinge about one fault I find in unix: commands such as cat, grep etc. do not handle an empty argument list correctly. For example, cat should output nothing and exit - concatenating 0 files. Instead it copies stdin to stdout, which is inconsistent. This problem still exists in plan 9. Copying stdin should be coded as: cat - Such syntax would provide useful extra capability: find -type d | cat lib/emptydirs - | mail 9fans@9fans.net Although this bug is not annoying for command-line work, consider a script that processes all .c files to be found using cat or grep: find -name '*.c' | xargs cat | cc - # this clever cc can handle it :) This program works fine until there are no .c files to be found, in that case it hangs, waiting for one on stdin! This is a hazard to shell scripters, and a potential source of security holes. It's worse than cat -v. Another example: 8c && echo 1 should compile 0 files to give an empty object file, and echo 1. Is there any chance we could fix these things in plan 9/inferno? I feel that freedom from past mistakes is a key principle of plan 9. If people support this change, I would be keen to work on it. thanks! Sam (I noticed the "pike" language has a similar bug, `+(1,2,3) -> 6 but `+() -> error! `+() should be 0 and `*() should be 1, of course.) I don't think such bugs exist in Lisp :)