1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2006-2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 fun val1
: Int is abstract
20 fun val2
: Int do return val1
26 redef fun val1
: Int do return _a
28 init(i
: Int) do _a
= i
29 redef fun to_s
do return "Aa{a}"
35 redef fun val1
: Int do return _b
/2
36 redef fun val2
: Int do return _b
37 init initelt2
(i
: Int) do _b
= i
42 init(i
: Int) do initelt2
(i
)
43 redef fun to_s
do return "Bb{b}"
50 redef fun val1
: Int do return _c
end
51 redef fun val2
: Int do return _d
end
53 init init2
(i
: Int, j
: Int) do
57 redef fun to_s
do return "Cc{c}d{d}"
63 redef fun val1
: Int do return _a
end
64 redef fun val2
: Int do return _b
end
66 init init2
(i
: Int, j
: Int) do
70 redef fun to_s
do return "Da{a}b{b}"
75 redef fun val1
: Int do return 5 end
77 init(i
: Int) do initelt2
(i
)
78 redef fun to_s
do return "Eb{b}"
83 redef type COMPARED: Elt
84 redef fun compare
(a
, b
)
87 return a
.val1
<=> b
.val1
89 return a
.val2
<=> b
.val2
95 _is_val1
= not _is_val1
98 var is_val1
: Bool = false
107 return new A
(10.rand
)
109 return new B
(10.rand
)
111 return new C
.init2
(10.rand
, 10.rand
)
113 return new D
.init2
(10.rand
, 10.rand
)
115 return new E
(10.rand
)
122 if not args
.is_empty
then
126 var array
= new Array[Elt].with_capacity
(n
)
128 array
.push
(generator
)
131 print array
.join
(", ")
133 var comparator
= new EltComparator
135 comparator
.sort
(array
)
139 print array
.join
(", ")