zsh: incompatibility on autoloading functions

zsh: incompatibility on autoloading functions

Post by King Oin » Thu, 05 Oct 1995 04:00:00



in ksh:
        # in anydirectory exists a file anyfunction containing:
        #       anyfunction ()
        #       {
        #         date
        #       }
        #
        FPATH=anydirectory
        typeset -f -u anyfunction
        anyfunction # anyfunction is now autoloaded and executed!

in zsh:
        # in anydirectory exists a file anyfunction containing:
        #       anyfunction ()
        #       {
        #         date
        #       }
        #
        FPATH=anydirectory
        typeset -f -u anyfunction
        anyfunction # anyfunction is only loaded this time
        anyfunction # anyfunction is executed 1st time

What is the reason for this incompatibility between ksh and zsh 2.5.03 ?

--
      _/_/_/  _/ _/    _/
    _/    _/ _/ _/_/  _/
   _/    _/ _/ _/  _/_/
   _/_/_/  _/ _/    _/

------------------------------------------------------------------------------
Franz Schmausser      VOICE  +49 89 636 49764   ... waiting for the prompt ...

------------------------------------------------------------------------------

 
 
 

zsh: incompatibility on autoloading functions

Post by Mark Borge » Thu, 05 Oct 1995 04:00:00


Quote:>> King Oin(O) wrote on 4 Oct 1995 08:35:34 GMT:

O> in ksh:
O>   anyfunction # anyfunction is now autoloaded and executed!

O> in zsh:
O>   anyfunction # anyfunction is only loaded this time
O>   anyfunction # anyfunction is executed 1st time

O> What is the reason for this incompatibility between ksh and zsh 2.5.03 ?

From the FAQ, located at

        http://www.mal.com/zsh/FAQ/

C5. Why do my autoloaded functions not autoload [the first time]?

      When you put a shell function in an autoload directory (i.e. one
      mentioned in $FPATH), it should be written just as if it were a
      shell script. In other words, there should be no line at the
      beginning saying `function foo {' or `foo () {', and
      consequently no matching '}' at the end. If you include those,
      then the first time you try to use the function, the _whole_
      file is run --- in other words, zsh simply defines the function
      and does nothing else. As a concrete example, if you have a
      function which you would define on the command line as

            xhead () { print -n "\033]2;$*\a";}

      and you have assigned `FPATH=~/fns', then your .zshrc should
      contain `autoload xhead' and the file ~/fns/xhead should contain
      only

            print -n "\033]2;$*\a".

      (A neat trick to autoload all functions in a given directory is
      to include a line like autoload ~/fns/*(:t) in .zshrc; the bit
      in parentheses removes the directory part of the filenames,
      leaving just the function names.)

      The shell has just (version 2.6 beta 5) been enhanced to allow
      the Korn shell syntax, where the file contains the whole
      function including the definition lines.  However, the form
      given above is unlikely to disappear as it allows significant
      benefits, including using a function directly as a script, and
      being able to link a function under different names.

 
 
 

1. zsh: incompatibility on case (opening (!)

ksh allows:
case $var in
  (abc) cmd ;;
# ^   ^
  (*)   exit ;;
# ^ ^
esac

so every opening ( has a closing ) and vice versa
this is very very very good for vi and set showmatch

zsh complains about parse error

there are a lot of settings for csh junkies
what the matter with ksh junkies?

--
      _/_/_/  _/ _/    _/
    _/    _/ _/ _/_/  _/
   _/    _/ _/ _/  _/_/
   _/_/_/  _/ _/    _/

------------------------------------------------------------------------------
Franz Schmausser      VOICE  +49 89 636 49764   ... waiting for the prompt ...

------------------------------------------------------------------------------

2. Process limit for 2.4.2 for threaded applications

3. Passing Variables to Autoload Functions in ksh

4. PowerPC Installation

5. ksh silently ignores function if mistakenly not autoloaded

6. Network installation and reloc.cpio: Broken pipe

7. ksh alias ignored in autoloaded function

8. OSR5 slows - dtdaemon using most of cpu time

9. zsh function does not get in foreground

10. zsh: Bind a key to an arbitrary function?

11. zsh typeset inside a function

12. zsh function syntax.

13. zsh function/positional parameter question...