File: test136.thp

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (110 lines) | stat: -rw-r--r-- 2,951 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;; -*-theme-d-*-

;; Copyright (C) 2008-2013 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.

;; Expected results: a (runtime) error
;;   When both of the argument lists are null
;;   the recursive type dispatch in my-map fails.


(define-proper-program (tests test136)


  (import (standard-library core)
	  (standard-library console-io))


  (define-param-proc my-for-all1? (%type1)
    (((proc (:procedure (%type1) <boolean> pure))
      (lst (:uniform-list %type1)))
     <boolean>
     pure)
    (if (null? lst)
	#t
	(let* ((lst2 (cast (:nonempty-uniform-list %type1) lst))
	       (hd (car lst2))
	       (tl (cdr lst2)))
	  (and (proc hd)
	       (my-for-all1? proc tl)))))


  (define-simple-proc my-map-car0
    (((lists (:uniform-list <nonempty-list>)))
     <list>
     pure)
    (if (null? lists)
	null
	;; If we enter here 'lists' is nonempty.
	(let ((lists2 (cast (:nonempty-uniform-list <nonempty-list>) lists)))
	  (cons (car (car lists2))
		(my-map-car0 (cdr lists2))))))


  (define-param-proc my-map-car (%types)
    (((lists (type-loop %type2 %types (:nonempty-uniform-list %type2))))
     %types
     pure)
    (cast %types (my-map-car0 lists)))


  (define-simple-proc my-map-cdr0
    (((lists (:uniform-list <nonempty-list>)))
     (:uniform-list <list>)
     pure)
    (if (null? lists)
	null
	;; If we enter here 'lists' is nonempty.
	(let ((lists2 (cast (:nonempty-uniform-list <nonempty-list>) lists)))
	  (cons (cdr (car lists2))
		(my-map-cdr0 (cdr lists2))))))


  (define-param-proc my-map-cdr (%types)
    (((lists (type-loop %type4 %types (:nonempty-uniform-list %type4))))
     (type-loop %type5 %types (:uniform-list %type5))
     pure)
    (cast (type-loop %type6 %types (:uniform-list %type6))
	  (my-map-cdr0 lists)))


  (define-param-virtual-method my-map (%arglist %result)
    (((proc (:procedure ((splice %arglist)) %result pure))
      (lists (splice (type-loop %type %arglist
				(:uniform-list %type)))))
     (:uniform-list %result)
     pure)
    null)


  (define-param-logical-type :my-map-class (%arglist %result)
    (:param-proc (%arglist %result)
		 ((:procedure ((splice %arglist)) %result pure)
		  (splice (type-loop %type %arglist
				     (:uniform-list %type))))
		 (:uniform-list %result)
		 pure))


  (define-param-virtual-method my-map (%arglist %result)
    (((proc (:procedure ((splice %arglist)) %result pure))
      (lists (splice (type-loop %type %arglist
				(:nonempty-uniform-list %type)))))
     (:uniform-list %result)
     pure)
     (let* ((cars (my-map-car lists))
	    (cdrs (my-map-cdr lists)))
       (cons
	(apply proc cars)
	(apply (cast (:my-map-class %arglist %result) my-map) (cons proc cdrs)))))


  (define main
    (lambda (() <integer> nonpure)
      (let* ((lst1 (list 1 2 3))
	     (lst2 (list "a" "b" "c"))
	     (result (my-map cons lst1 lst2)))
	(console-display result)
	(console-newline))
      0)))