summaryrefslogtreecommitdiff
path: root/tests/general/techo.icn
blob: aa6fe71b3bf52d9c9df3180a437be7b477279a39 (plain)
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
global time, date, save, wombats

# All variables passed to echo() must be:

#    Simple scalar variables, because echo() does not yet understand
#    Icon keywords (such as &clock), arrays, records, or function
#    calls.  However, such entities may be assigned to simple global
#    variables, as the main program below shows; and

#    Global, because echo() cannot accesss their values otherwise.

# If a variable is undefined or null, echo() outputs nothing.

link echo

procedure main()
   time := "12:34:56"		# fake &clock for reproducible test
   date := "2010/02/30"		# fake &date for reproducible test
   save := 47.23
   wombats := 22

   # Usage method 1:

   "It is now $time on $date and you have savings of $$$save." ? echo()
   "The number of wombats is $wombats." ? echo()
   "It is now ${time} on ${date} and you have ${wombats} wombats." ? echo()
   "There is no global variable named \"$foo\"." ? echo()
   "This does not work:  It is now ${&clock}." ? echo()
   echo()
   "The previous echo() example printed an empty line." ? echo()
   echo()
   "Here is another way to use echo()..." ? echo()
   echo()

   # Usage method 2:

   "It is now $time on $date and you have savings of $$$save." |
      "The number of wombats is $wombats." |
      "It is now ${time} on ${date} and you have ${wombats} wombats." |
      "There is no global variable named \"$foo\"." |
      "This does not work:  It is now ${&clock}." |
      "" |
      "The previous input line printed an empty output line." ? echo()

   # The value of &subject defaults to "", so echo() will print out an
   # empty line if it is called without a `?'.

   echo()

   # The next test takes advantage of the fact that string
   # concatenation has a higher precedence than alternation.  It
   # prints three lines:

   "Fee, " ||
      "fi, " ||
      "fo, " ||
      "fum, " |                    # 1st line
      "I " ||
      "smell " ||
      "the blood " |               # 2nd line
      "of an Englishman!" ? echo() #3rd line

end