home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / lisp / lispnews / text0022.txt < prev    next >
Encoding:
Text File  |  1985-11-10  |  3.8 KB  |  93 lines

  1.   Liszt will now check that you are passing the correct number of arguments
  2. to functions.   As a result, some files which have compiled without
  3. complaint in the past may compile now with warnings or errors.  In this
  4. note, I'll explain what the compiler knows, what it looks for in your
  5. program, and how you can help the compiler understand your program.
  6.  
  7.   For each function, liszt either knows nothing about the the number of
  8. arguments to a function, or it knows the minimum number of arguments, or the
  9. maximum number of arguments, or both the minimum and maximum number of
  10. arguments.   This information comes about in one of three ways:
  11.   1) it is known when liszt starts (by virtue of a value stored under the
  12.      fcn-info indicator on a function's property list)
  13.   2) it is declared by the user, either via (declare (*arginfo ...))
  14.      or (declare (*args ...)) [see below]
  15.   3) it is determined when a (lambda) function is compiled.
  16.      When a lambda is compiled, the compiler can easily figure out the
  17.        minimum and maximum number of arguments.
  18.      When an nlambda or lexpr function is compiled, the compiler doesn't
  19.      make a guess as to how many arguments are expected.  The user should
  20.      use the (declare (*args ...)) form to tell the compiler how many
  21.      arguments are expected.
  22.      For lexpr's generated via 'defun' using &optional and &rest keywords,
  23.      the correct declaration is generated automatically.
  24. Once liszt determines the number of arguments to a function, it uses that
  25. information to check that the function is called with the correct number of
  26. arguments.  It does not check calls to the function that occured before it
  27. determined the correct number of arguments.  [This backward checking will
  28. be added sometime in the future.]
  29.  
  30.   If liszt finds that a function is called with the wrong number of
  31. arguments, it prints an informative message.  That message is a error if the
  32. function being called is one which is open coded by the compiler. The
  33. message is a warning otherwise.  The reason for the distinction is that
  34. you are free to redefine functions not open coded by the compiler. If the
  35. number of arguments is not correct, it may just be that the compiler's
  36. database and your code are refering to two different functions.
  37. If you redefine system functions, you should use the
  38. (declare (*arginfo ...)) form to let the compiler know about the number
  39. of arguments expected by your version of the functions.
  40.  
  41.   You can declare the number of arguments to functions using this form
  42.  
  43. (declare (*arginfo (fcnname1 min1 max1) (fcnname2 min2 max2) ...))
  44.   where each min or max is either a fixnum or nil (meaning "I don't know")
  45.   
  46. for example, here are some `correct' declarations:
  47.  
  48. (declare (*arginfo (read 0 2) (cons 2 2) (boole 3 nil) (append nil nil)))
  49.   
  50.  explanation:
  51.    (read 0 2) means that the function read expects between 0 and 2
  52.        arguments (inclusive).
  53.    (cons 2 2) means that cons expects 2 arguments.
  54.    (boole 3 nil) means that boole expects at least 3 arguments.
  55.    (append nil nil) means that append expects any number of arguments,
  56.       this is equivalent to (append 0 nil).
  57.       
  58.  
  59. The *arginfo declaration is usually made at the top level of a file.
  60.  
  61. To declare the argument characteristics of the current function being
  62. compiled use the '*args' declaration. It looks somewhat like the
  63. *arginfo declaration.
  64.  
  65. It is best explained with examples
  66.  
  67. (def read
  68.    (lexpr (n)
  69.        (declare (*args 0 2))
  70.        ... code for read
  71.        ))
  72.  
  73. (def process
  74.   (nlambda (x)
  75.       (declare (*args 1 3))
  76.       ... code for process
  77.       ))
  78.  
  79. Note: the *args declaration is not needed for lambda's.
  80.  
  81.  
  82.  
  83.   If you get an error or warning which you believe is incorrect, it is
  84. probably due to an incorrect database entry.  Please let me know and I will
  85. fix it immediately.   I expect that there will be quite a few of these
  86. errors because much of the database was built by hand.
  87.  
  88.  
  89.      
  90.  
  91.  
  92.  
  93.