Anonymous user
Function prototype: Difference between revisions
→{{header|Common Lisp}}
(added Ol) |
|||
Line 260:
=={{header|Common Lisp}}==
In Common Lisp, function prototypes can be used with <code>(declaim (inline func-name))</code> function arguments are taken when the function is defined. In addition, the argument types aren't needed.
<lang lisp>
(declaim (inline no-args))
(defun 0args ()▼
(declaim (inline one-arg))
(format t "Called 0args~%"))▼
(declaim (inline two-args))
(declaim (inline optional-args))
(format nil "no arguments!"))
(defun 2args (a b)▼
(defun one-arg (x)
; inserts the value of x into a string
(format nil "~a" x))
▲(defun 2ints (i j)
; same as function `one-arg', but with two arguments
(format nil "~a ~a" x y))
(defun optional-args (x &optional y) ; optional args are denoted with &optional beforehand
; same as function `two-args', but if y is not given it just prints NIL
(no-args) ;=> "no arguments!"
(one-arg 1) ;=> "1"
(two-args 1 "example") ;=> "1 example"
(optional-args 1.0) ;=> "1.0 NIL"
(optional-args 1.0 "example") ;=> "1.0 example"
</lang>
=={{header|D}}==
|