File ExerciseX.html    Author McKeeman    Copyright © 2007    index

X Exercises

After getting a personal copy of xcom:
  • Try the xcom compiler:

    Bring up MATLAB and change directory to mxcom from the xcom distribution. At the prompt, type (no blanks internal to the assignment)

    >> xcom x:=1
    
    The result will be to compile the assignment into machine language and then run it. You should see
    x := 1
    
    which is the correct result for the 4-character program presented to xcom.

    For further information, type

    >> help xcom
    
    or read the X Reference Manual.

  • Look at these typeset examples or this bigger example.

  • In the mxcom x subdirectory, there is a set of X programs. One of them computes π by evaluating a series. Run it. xcom "knows" argument x/pi.x is a file name because it ends in '.x'.

    >> xcom x/pi.x
    
    The xcom runtime asks for the number of terms you want. Try several runs with different settings.

    Because the alternating harmonic series converges so slowly, you will not like the results for small settings.

  • Try each xcom flag (listed by help xcom) on pi.x.

  • Look at the mxcom x directory

    >> ls x/*.x
    
    Run a selection of the programs. Some of the programs call each other and, in that case, must all be named on the command line. For example
    >> xcom x/pi.x x/callpi.x
    
    The last program named is the main program. Once it is in execution it can call the others, and they can call each other, including the main program.

    With a critical eye, read the X source of each program you ran. Suggest changes where appropriate.

  • Improve the accuracy of the program for π. The easiest solution is to present the average of the last two results. Depending on your prior knowledge and ambition, this exercise could take some research.

  • Use the Taylor Series to implement X functions for e(x), sin(x) and cos(x). Use the previous program to compute π to test your new functions. Recall that sin(x) is one of the implemented examples, in case you want to peek.

  • Implement and test an X function abs so that

       pos := abs := signed
    
    gives the positive result for signed input. What type do you want it work for? Maybe you need two abs functions. Could you have used it in the previous exercise?

  • Excuse the poor X pun, but carry out the following meta-program

    do learning ? write(interesting program) 
    od