On 4/20/06, Philip Ganchev <[EMAIL PROTECTED]> wrote: > On 4/20/06, Axel Liljencrantz <[EMAIL PROTECTED]> wrote: > [...] > > > fish> echo hello | $VIEWER > > > > Oh, right. Never tried those alternatives. Here is how to do this > > properly in fish: > > > > if test "$OPSYSTEM" = "TANDEM"; > > function viewer; more; end > > else > > function viewer; less; end > > end > > > > ... > > > > case 4 > > cat /etc/hosts | viewer > > case 5 > > ifconfig | viewer > > end > > Why did you decide to disallow the naive syntax "command1 | $commandstr"? >
Because using variables as a poor mans functions has several drawbacks: * It makes it much harder to validate the code without executing it * It blurs the distinction between code and data In the rare cases where you really _have_ to evaluate the contents of a variable as a command, simply use the eval builtin. Forcing the user to do this means that we can clearly and easily find all places where unvalidated and potentially problematic code is executed - simply search for and calls to 'eval'. In this case, we don't have to use a variable, and using a real function instead of a variable means you have separate namespaces for code and data, your code is validated before executing a file, and if the file contains syntax errors, nothing will be executed. By designing the fish language so that it can be validated before executing it (or even without executing it, by using 'fish -n FILE'), one of the biggest drawback of interpreted code is mostly removed - syntax bugs can be weeded out without having to make sure every codepath is executed first. None of these issues are important for quick throwaway hacks, but using a real function isn't really wordier or harder to us, so why not use the proper syntax instead of one which has no benefits and several drawbacks? -- 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&kid0709&bid&3057&dat1642 _______________________________________________ Fish-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/fish-users
