Anonymous user
Function prototype: Difference between revisions
→{{header|Racket}}
m (→{{header|J}}) |
|||
Line 293:
=={{header|Racket}}==
Most of the points are covered in this program
<
#lang racket
(define (no-arg) (void))
Line 302 ⟶ 304:
(define (varargs2 a . args) (void)) ;one obligatory argument and the rest are contained in the list
(define (optional-arg (a 5)) (void)) ;a defaults to 5
</lang>
<tt>(void)</tt> is a function that returns "nothing", so this are prototypes that do nothing.
Although standard Racket doesn't allow type declarations, it allows contracts, so we can add this to the previous declarations
<lang racket>
[two-args (integer? integer? . -> . any)]))
</lang>
then any module that imports the function can only pass integers to two-args.
Another way is using the <tt>typed/racket</tt> language, like this
<lang
#lang typed/racket
(: two-args (Integer Integer -> Any))
|