home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / a / armbob / doc / Tutorial / 01 next >
Text File  |  1994-06-06  |  4KB  |  115 lines

  1. ArmBob v.1.02 Tutorial 1                               GCW 06/06/94
  2.  
  3. Hello World
  4. -----------
  5. ArmBob has syntax that conforms very closely to that of C. The 
  6. standard textbook on C is "The C Programming Language" by 
  7. B.W.Kernighan and D.M.Ritchie (KR). If you are not acquainted with C
  8. you will find the first few chapters of this book very useful. If
  9. you are acquainted with C you might find it interesting to note in
  10. which respects the examples below fail to be C programs.
  11.  
  12. Let us follow KR by considering the "first program" in any language -
  13. a program to print the words "Hello, World". Here it is in Bob:
  14.  
  15.   main()
  16.   {
  17.    print("Hello, World\n");
  18.   }
  19.  
  20. To run this program, create a text file, type the program in, and
  21. save your file. Then use the filer menu to change its filetype to
  22. BobTask. If you get a message box saying "Bad file type" that means
  23. that either the system has not "seen" the !ArmBob application or
  24. you mistyped. Double-click on !ArmBob and try again. You should find 
  25. that the file's icon has changed to light blue with yellow text 
  26. lines on it, with a small window overlaid. Double-click on the file's 
  27. icon and the program will run in a task window (we presume you have 
  28. Risc OS 3. If you change the file's type to BobFile it will run in a 
  29. command window.
  30.  
  31. A Bob program consists of functions and classes. We have defined 
  32. a single function 'main'. Normally a function can have any name you
  33. like (subject to the rules of syntax - see ref.Syntax). However, main
  34. is special, in that a program starts executing at main's first 
  35. statement. Every program must have a function called 'main'.
  36. The order in which the functions are defined makes no difference.
  37. Classes must be defined before their instance objects are created.
  38.  
  39. The statements in a function are enclosed in braces ({ ... }). Our
  40. program has only one statement,
  41.  
  42.                  print("Hello, World\n");
  43.  
  44. A function is called (i.e. used) by naming it, followed by a 
  45. parenthesized list of argument expressions. Here we call the built-in
  46. function 'print'. Most functions take a definite number of arguments,
  47. separated by commas, but 'print' is rather special in that it can
  48. take an indefinite number of arguments. In our example, there was the
  49. single argument
  50.  
  51.                     "Hello, World\n"
  52.  
  53. which is a 'string' expression. Strings are sequences of characters
  54. enclosed in double-quotes ("). They may not contain double-quotes.
  55. The pair of characters '\n' denotes a single character - the newline.
  56. Unlike Basic, Bob's print function does not provide a newline 
  57. automatically. We could have written our program as
  58.  
  59.    main()
  60.    {
  61.     print("Hello, ","World","\n");
  62.    }
  63.  
  64. or as 
  65.  
  66.    main()
  67.    {
  68.     print("Hello, ");
  69.     print("World");
  70.     print("\n");
  71.    }
  72.  
  73. Bob has an alternative notation borrowed from C++. We could also
  74. have written
  75.  
  76.   main()
  77.   {
  78.    stdout << "Hello, World\n";
  79.   }
  80.  
  81. The expression 'stdout' stands for "standard output channel". If
  82. 'out' denotes any output channel, say to a file, and 'message' denotes 
  83. a string, the statement
  84.  
  85.                     out << message;
  86.  
  87. causes message to be transmitted along out. Now the expression
  88.  
  89.                      out << message
  90.  
  91. actually evaluates to out itself. The process of evaluating it causes 
  92. the transmission of message along out as a side-effect. It follows
  93. that a statement of the form
  94.  
  95.            out << mesg1 << mesg2 << ..... << mesgn;
  96.  
  97. will cause mesg1, mesg2, ... mesgn all to be transmitted, in order,
  98. along out. So we could also have written
  99.  
  100.     main()
  101.     {
  102.      stdout << "Hello, " << "World" << "\n";
  103.     }
  104.  
  105. Note the distinction we made between the expression 'out << message'
  106. and the statement 'out << message;'. The semicolon (;) marks the
  107. termination of a single statement. Statements are like complete
  108. sentences, but expressions are like nouns; they stand for something 
  109. but mean nothing by themselves.
  110.  
  111.  
  112.  
  113.          
  114.  
  115.