Checkpoint C

From J Wiki
Jump to navigation Jump to search


<=   =>

At this point you should understand:

  • the general idea of verb debugging
  • how control words create control structures by grouping sentences into blocks
  • what the T block test result is
  • how the test result determines which B block to execute
  • how the test result determines when control structure execution is finished


Check your understanding by doing the following exercises:

  • debug step through your convert verb
  • create a temporary script file and define a verb called conv that is similar to convert, but insists on a 'f' argument to do the conversion to Fahrenheit and gives a string result indicating there was an error if the left argument is neither 'c' nor 'f'.

    Hint: use the control structure sketched out here:
  • if. x = 'c' do. ...
      elseif. x = 'f' do. ...
      elseif. 1 do. 'left arg not c or f'
    end.

    or try a select. structure.

  • create a temporary script file and define a dyad called plus that adds its left argument to its right. But, if there is an error, it should give a string result.

    Hints:
    • use dyad : 0;
    • 4 plus 9 should return 13;
    • 'a' plus 9 should return your error string (perhaps, 'there was an error');
    • Use a try. control structure to catch the error and give the string result.


<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106