home *** CD-ROM | disk | FTP | other *** search
- Liszt will now check that you are passing the correct number of arguments
- to functions. As a result, some files which have compiled without
- complaint in the past may compile now with warnings or errors. In this
- note, I'll explain what the compiler knows, what it looks for in your
- program, and how you can help the compiler understand your program.
-
- For each function, liszt either knows nothing about the the number of
- arguments to a function, or it knows the minimum number of arguments, or the
- maximum number of arguments, or both the minimum and maximum number of
- arguments. This information comes about in one of three ways:
- 1) it is known when liszt starts (by virtue of a value stored under the
- fcn-info indicator on a function's property list)
- 2) it is declared by the user, either via (declare (*arginfo ...))
- or (declare (*args ...)) [see below]
- 3) it is determined when a (lambda) function is compiled.
- When a lambda is compiled, the compiler can easily figure out the
- minimum and maximum number of arguments.
- When an nlambda or lexpr function is compiled, the compiler doesn't
- make a guess as to how many arguments are expected. The user should
- use the (declare (*args ...)) form to tell the compiler how many
- arguments are expected.
- For lexpr's generated via 'defun' using &optional and &rest keywords,
- the correct declaration is generated automatically.
- Once liszt determines the number of arguments to a function, it uses that
- information to check that the function is called with the correct number of
- arguments. It does not check calls to the function that occured before it
- determined the correct number of arguments. [This backward checking will
- be added sometime in the future.]
-
- If liszt finds that a function is called with the wrong number of
- arguments, it prints an informative message. That message is a error if the
- function being called is one which is open coded by the compiler. The
- message is a warning otherwise. The reason for the distinction is that
- you are free to redefine functions not open coded by the compiler. If the
- number of arguments is not correct, it may just be that the compiler's
- database and your code are refering to two different functions.
- If you redefine system functions, you should use the
- (declare (*arginfo ...)) form to let the compiler know about the number
- of arguments expected by your version of the functions.
-
- You can declare the number of arguments to functions using this form
-
- (declare (*arginfo (fcnname1 min1 max1) (fcnname2 min2 max2) ...))
- where each min or max is either a fixnum or nil (meaning "I don't know")
-
- for example, here are some `correct' declarations:
-
- (declare (*arginfo (read 0 2) (cons 2 2) (boole 3 nil) (append nil nil)))
-
- explanation:
- (read 0 2) means that the function read expects between 0 and 2
- arguments (inclusive).
- (cons 2 2) means that cons expects 2 arguments.
- (boole 3 nil) means that boole expects at least 3 arguments.
- (append nil nil) means that append expects any number of arguments,
- this is equivalent to (append 0 nil).
-
-
- The *arginfo declaration is usually made at the top level of a file.
-
- To declare the argument characteristics of the current function being
- compiled use the '*args' declaration. It looks somewhat like the
- *arginfo declaration.
-
- It is best explained with examples
-
- (def read
- (lexpr (n)
- (declare (*args 0 2))
- ... code for read
- ))
-
- (def process
- (nlambda (x)
- (declare (*args 1 3))
- ... code for process
- ))
-
- Note: the *args declaration is not needed for lambda's.
-
-
-
- If you get an error or warning which you believe is incorrect, it is
- probably due to an incorrect database entry. Please let me know and I will
- fix it immediately. I expect that there will be quite a few of these
- errors because much of the database was built by hand.
-
-
-
-
-
-
-