Vector Printer

Overview

The Vector printer depends on the two variables *print-array* and *print-readably*. If *print-array* is true and *print-readably* is false, any vector other than a string or bit vector is printed using general-vector syntax. This means that information about specialized vector representations does not appear. It will basically print using the default T printer’s layout.

The printed representation of a zero-length vector is #(). The printed representation of a non-zero-length vector begins with #(. Following that, the first element of the vector is printed. If there are any other elements, they are printed in turn, with each such additional element preceded by a space. A right paranthesis after the last element terminates the printed representation of the Vector.

The printing of vectors is affected by *print-level* and *print-length*. If the vector has a fillpointer then only those elements below the fillpointer are printed.

If both *print-array* and *print-readably* are false, the vector is not printed as described above, but in the format: #<simple.vector @??????>

Where the 'simple.vector' is the class type, for single dimensional Vectors (Multiple dimensional Vectors are Arrays). The '@??????' represents the system identity hashcode, and the '?' is replaced by any integer value.

Implementation

Before determining on how to print the current Vector we first make a check whether or not *print-level* and *print-length* are integers, if they are not, then we print all levels and all elements of the current Vector.

Next, we check to see whether or not the variables *print-array* and *print-readably* are set to true or not. If both of them are false then the printer will output the Vector using the class and identity hashcode format.

If one of them are true then the printer outputs the Vector using a for loop and prints the elements as long as *print-length* and *print-level* allows it. However, because the Vector can have any sort of type, we are using recursion and are calling the printObject function and letting that function take care of which printer to use, to get the correct output. If *print-level* and *print-length* are both set to Null, then the entire Vector is printed without any restrictions.

If there are more elements in the Vector than *print-length*'s value then those element exceeding that value is printed represented by a '...'.
If there are more depth or level to any of the elements in the Vector than *print-level*'s value then those elements exceeding that level is printed represented by a '#'.

For example: We have a Vector with (1 2 ((3)) 4)
And *print-length* is set to 3
Then it would print: #(1 2 ((3)) ...)
And if *print-level* was set to 2
Then it would print: #(1 2 # ...)

Back to LispPrinter

-- PeterNguyen - 27 Apr 2006

Topic revision: r4 - 2009-03-11 - 20:26:23 - MadelineWilliams
 
Home
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback