[net.unix-wizards] A C-Shell Puzzle Contest

lipkis (03/12/83)

	So you think you know the C shell?  I offer $10 to the first person
to send me a complete, correct solution to this question:  What do the following
aliases do?  Hint: the "xxx" alias is the main utility, while the others are
"sub-aliases".  Also, I'll tell you that this is a working, useful alias that
I use to cut down on the number of processes I generate.  No attempt was made
to obscure the code, other than to change the name to xxx (this is really
true!).
	To win, you must tell me at least two reasons for the uses of the eval
command (one reason is a csh bug), and what function the auxillary aliases
perform.  The correct solution is quite simple.
	Rules: Employees of NYU and their families are not eligible to play.
Mr. Joy, however, IS eligible (is he out there?).  You may not execute the
aliases (shame on you -- you would cheat to win a measly 10 bucks?).  Entries
must be mailed to cmcl2!acf2!condict (DO NOT REPLY DIRECTLY TO THIS ARTICLE),
and must be postmarked no later than when the next version of the C shell is
released, which is when, I expect, the aliases will stop working.  The decision
of the judge (me) is final.

-------------------------------------------------------------------------------
alias	while1	'eval "if (" \!:1 ")'\
		    'eval \!:2:q \; while1 '\\\''\!:1:q'\\\' \\\''\!:2:q'\\\'\"
#
set stack = ("ENDFRAME")
alias	xxx	'set stack = ("ENDFRAME" $stack:q);'\
		'local argv;'\
		'set argv=(\!*);'\
		'if ($#argv == 0) source;'\
		'if ($#argv > 0) eval'\
		    \''set stack = (" " $stack:q);'\
		      '@ stack[1] = 1;'\
		      'if ("$argv[1]" =~ /*) @ stack[1] += $#path;'\
		      'while1 '\'\\\'\''$stack[1] <= $#path'\'\\\'\
			      \\\'\''if (-x "$path[$stack[1]]"/$argv[1])'\
					'@ stack[1] += $#path;'\
				'@ stack[1] += 1'\'\\\'\'' ;'\
		      '@ stack[1] -= (1 + $#path);'\
		      'if ($stack[1] > 0)'\
				'set argv[1] = "$path[$stack[1]]"/$argv[1];'\
		      'shift stack;'\
		      'eval "shift; source $argv[1]"'\'';'\
		'unlocal; shift stack'
#
alias	local	'if ("\!:2*" != "") eval local \!:2*;'\
		'if (! $?\!{:1})'\
		    'set stack = ("unset \!:1" $stack:q);'\
		'if ($?\!{:1}) eval'\
		    \''set stack = ("shift stack;'\
				    'set \!:1 = ("\$"stack[1-$#\!{:1}]:q);'\
				    'set stack = ("\$"stack[$#\!{:1}-]:q)"'\
				    '$\!{:1}:q $stack:q);'\
		      'if ($#\!{:1} == 0) set stack[1] = "set \!:1 = ()"'\'
#
alias	unlocal	'eval "$stack[1]"; shift stack;'\
		'if ("$stack[1]" != "ENDFRAME") eval unlocal'
-------------------------------------------------------------------------------

	Well, now you know why my eyes are glazed over and my fingers shake
as I type this.

Michael Condict
251 Mercer St.
Courant Inst.
New York University
New York, NY   10012

P.S. My next project is a distributed question-answering system with a
natural-language interface, written as a collection of csh scripts that
use environment variables for the data base.  I think I'll need awk too...

		Excuse me, they're coming for me now -- gotta run ....