Home | History | Annotate | Line # | Download | only in Examples
      1  1.1  christos The following is a demonstration of the guess.d script,
      2  1.1  christos 
      3  1.1  christos 
      4  1.1  christos guess.d is a guessing game written in DTrace. It goes like this,
      5  1.1  christos 
      6  1.1  christos    # ./guess.d
      7  1.1  christos    guess.d - Guess a number between 1 and 100
      8  1.1  christos    
      9  1.1  christos    Enter guess 1: 50
     10  1.1  christos    Lower...
     11  1.1  christos    Enter guess 2: 25
     12  1.1  christos    Higher...
     13  1.1  christos    Enter guess 3: 37
     14  1.1  christos    Higher...
     15  1.1  christos    Enter guess 4: 44
     16  1.1  christos    Higher...
     17  1.1  christos    Enter guess 5: 48
     18  1.1  christos    Lower...
     19  1.1  christos    Enter guess 6: 46
     20  1.1  christos    Lower...
     21  1.1  christos    Enter guess 7: 45
     22  1.1  christos    Correct! That took 7 guesses.
     23  1.1  christos    
     24  1.1  christos    Please enter your name: Brendan Gregg
     25  1.1  christos    
     26  1.1  christos    Previous high scores,
     27  1.1  christos    Fred Nurk 7
     28  1.1  christos    Brendan Gregg 7
     29  1.1  christos 
     30  1.1  christos It was written as a demonstration of the same code written in dozens of
     31  1.1  christos languages. It makes a good demonstration, as it covers integer and string
     32  1.1  christos variables, conditional statements, loops, keyboard input, screen output,
     33  1.1  christos and file input and output. 
     34  1.1  christos 
     35  1.1  christos Written in DTrace however, is not such a good demonstration! DTrace doesn't
     36  1.1  christos have loops (it doesn't really need them either) which made the code a 
     37  1.1  christos little odd. DTrace also doesn't have keyboard input... So this script is
     38  1.1  christos somewhat amusing as an example, but not terribly useful.
     39  1.1  christos 
     40