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

Re: lexically scoped functions



> Currently in es, you can not define a function that has lexical scope.
> I asked Paul about this, and he says that at one time he had convinced
> himself that lexical scoping for function names was not desirable, but no
> longer remembers why now.

	I remember in my first posting way back (I think before es-0.70),
asking a similar question, which was, why was there an inconsistency in the
following,
	let (fn foo {echo $*}) foo bar
	local (fn foo {echo $*}) foo bar
Why weren't the results identical?  Well I know better now, but I can see
it's a shame that es doesn't search for functions in the let-namespace, just
for the sake of consistency.  
	However, I can see some logic in terms of efficiency because a let
function definition can only be used inside the let-body, so why not
reference directly using $fn-foo because you must have known that you are
overriding the foo function anyway.
	This is not the case for local function definitions, because you
intend this foo to be used in all subsequent calls from your local-body.  Es
is a shell, so you can't make all function calls by doing $fn-prog because
prog may be an external program (or may need autoloading :-) ) for
instance.  Therefore this apparent inconsistency in let() and local() is
necessary is justifiable ;-).

>       fn frobme  with some args { echo frobme $with $some $args }
>       fn doit { 
>          frobme harder $*
>       }
>       local (fn frobme { rm $* }) {
>          frobme /tmp/*~
>          doit to me baby
>       }

I never do this kind of thing because as you say, it can be dangerous :-),
you know it makes sense to use,
	let (fn frobme {rm $*}) { $fn-frobme ... }

Pete.