demo
blockallHST
comment:HST
interface:HST
params:HST
scope:HST
setup:HST
test:HST
1 namespace demo #:...
2 A namespace for our demo classes.
3 scope:...
4
5 class Person scope:...
6
7 field name : str #:...
8 The name of the person.
9 field height : real<64> #:...
10 Height of person in meters.
11 field weight : real<64> #:...
12 Weight of person in kilograms.
13
14 lifecycle params:...
15 var name -> name;
16 var height -> height;
17 var weight -> weight;
18 setup:...
19 test.personIs(demo.Person('Bob', 1.87, 86.3))
20 test:...
21 test.iseq('Bob', test.person().name())
22 end;
23
24 test field person : demo.Person;
25
26 method bodyMassIndex : real<64> #:...
27 Compute the BMI for this person.
28 scope:...
29 height = self.height()
30 return self.weight() / (height * height)
31 test:...
32 person = test.person()
33 test.isapprox(
34 24.67900, person.bodyMassIndex())
35 end;
36
37 implicit
38 command persondemo #:...
39 An executable providing access to Person code.
40 interface:...
41 flag name @ n : str = 'Bob' #:...
42 The name of the person.
43
44 command bmi #:...
45 Report the BMI of the person.
46 interface:...
47 arg weight : double #:...
48 The weight of the person in kilograms.
49 arg height : double #:...
50 The height of the person in meters.
51 scope:...
52 person = demo.Person(
53 cli.name, cli.height, cli.weight)
54 print '%s has BMI %1.2f' % (
55 person.name(), person.bodyMassIndex())
56 end command bmi;
57 end command persondemo;
58
59 end class;
60
61 end namespace demo;