Function prototype: Difference between revisions

Line 293:
=={{header|Racket}}==
Most of the points are covered in this program
<lang Racket>#lang racket>
#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>
</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>
<lang Racket>(provide (contract-out
[two-args (integer? integer? . -> . any)]))</lang>
</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 Racket>#lang typed/racket>
#lang typed/racket
 
(: two-args (Integer Integer -> Any))