Hi

I've implemented a new fish function that might be a good idea. It's a
switch (-S/--save) to the function builtin for automatically saving
the function into an autoload file, so that it is available to all
fish instances, permantly.

Fish writes the file to the first directory in fish_function_path that
can be written to. If the directory doesn't exist, but can be created,
fish will do so first.

I've been a bit uncertain about the implementation. Specifically, it
would be possible to use universal variables for providing this
functionality with a great deal less code. The reasons why I chose not
to do so where:

* Functions and variables don't have the same semantics. Variables
have scope, there can be different variables with the same name but
different scope, etc.. Mixing the two will lead to some very
unintuitive corner cases.

* Variable name issues - I'm half convinced that fish functions should
be allowed to have any legal filename, just like regular commands, for
the simple reason that they should be more or less equivalent to
regular commands. This is a case of minimizing the difference between
functions, builtins and commands. This question has been discussed
before, and the more I think about it, the more it makes sense to me.

* namespace issues: You'd need some silly scheme to encode what
variables are actually functions, probably using some weird prefix.
Then you'd have to hide those variables from regular variable usage.
It's perfectly doable, but it's a hack.

The alternative for me would be to make all functions into a special
case of variables, let function definitions have scope, and use
universal variables for storing global functions. This would have the
distinct disadvantage that you'd still need the autoloader and the
file backend for autoloaded functions, since you really want to give
the sysadmin the oportunity to add functions without messing with each
users fishd. Also, if function definitions had scope, you'd really
want functions to be able to insect the namespace of their parent
functions and do other cool Lisp-ish things, and I'm not convinced
that a simple shell should have that kind of features.

In the end, it seems to me like variables and functions are a bit like
each other, but not enough that they should be merged. For that
reason, I have not chosen to call the feature of saving functions
'Universal functions', and the switch is not the same as for defining
universal variables.

Another alternative would be to implement this functionality as a
shellscript. It would be easy to write a shellscript function
'save_function' that would save the definition of the specified
function to a autoloaded file. The only reason for wanting to do this
in the shell is because the syntax would be uglier/less discoverable.
'function -S foo; echo bar; end' vs. 'function foo; echo bar; end;
save_function foo'. Not sure if this functionality is common enough
for that to be a good enough motivation.

Opinions are welcome.

-- 
Axel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to