-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic-test.rkt
43 lines (29 loc) · 935 Bytes
/
generic-test.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#lang racket
(require "generic.rkt")
(require "applicability.rkt")
;;; Basic function tests
(define g:+ (simple-generic-procedure 'g:+ 2 #f))
(define g:- (simple-generic-procedure 'g:- 2 #f))
(define (sym:+ x y)
(list '+ x y))
(define (sym:- x y)
(list '- x y))
(assign-handler!* g:+ sym:+ (any-args 2 symbol? number?))
(assign-handler!* g:- sym:- (any-args 2 symbol? number?))
(assign-handler! g:+ + number? number?)
(assign-handler! g:- - number? number?)
;;; Macro interface tests
(define/generic (g:* x y))
(define/implementation (g:* [x number?] [y number?])
(* x y))
(define/implementation (g:* (x string?) (y string?))
(string-append x y))
;;; SFD Tests
(define foo
(simple-generic-procedure 'foo 2 #f))
(define-generic-procedure-handler foo (match-args number? number?)
(lambda (a b)
(+ a b)))
(define-generic-procedure-handler foo (any-args 2 symbol? number?)
(lambda (a b)
(list '+ a b)))