[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: settor functions



| the uncaught exception is because {} are not considered functions.
| maybe they should be.  

Can you precisely state the semantics for {}?  At first I thought that
{ foo } might be equivalent to @ { foo }, but it isn't.

Another question is, what does "return" mean.  In es it means two
things, a control flow construct and a value returning construct.  In
scheme those concepts are separate.  Every expression evaluates to
some value, and you return a value just by falling off the end,
without any additional control flow constructs.  (Perl works the same
way, as it happens.)  In a shell like es this is a little stickier,
since you execute everything in sight, including literals, which perl
and scheme don't do.

| to support return from {}, but the reason i don't want {} to
| catch return is that then

Ah, but now we see that it is "return" that is misbehaving.  When you
write "return" in function foo, you really want it to mean is
"call-escape-continuation-for-function-foo", which you can easily
generate code for since you know what function you are in, or you can
pass that continuation as a paramter (probably fluid-let is better for
that, though) so that return would be syntactic sugar for calling it.
This is assuming you add all this scheme stuff to the language, but it
fixes the problem in a clean way.

| 	fn foo {
| 		local (orig = $*) {
| 			while {!~ $#* 0} {
| 				if {~ $1 --} {
| 					return $*(2 ...)
| 				}
| 				* = $*(2 ...)
| 			}
| 			return $orig
| 		}
| 	}

But suppose you wrote:

	fn borg { while {sleep 1} $1 }
	fn alert { echo 'unix is futile'; return; }

Then typed this:

	borg alert

As expected, the inner return doesn't exit from the loop.  Similary,
for this:

	borg @ { echo 'software is irrelevent'; return; } 

But the following is magic, and exits after one iteration:

	borg { echo 'new operating system Deep-Space-9'; return; } 

| anyway, that's the argument, and it convinces me, but it does seem
| asymmetric, and that causes concern.

Orthogonality is key.  Lambda is irresistable.  You will be assimilated. :-)