In Maple, the cleanest way to list the items of an array is to convert it to a list and print it: convert(A, list) returns a comma-separated list of elements in index order, which the worksheet displays directly. If you want custom formatting rather than Maple's default 2-D output, loop over the array with seq, for, or map and print each element.

That short answer covers most situations, but "list items in an array" can mean several different things in Maple: dumping values to the screen, flattening a multidimensional structure into one sequence, printing indices alongside values, writing rows to a file, or building formatted output for a report. Each has a reliable idiom and a few traps. The sections below walk through them in the order you'd typically need them, with checks you can run to confirm the output is what you intended.

What "listing an array" means in Maple, and why the obvious command fails

Maple distinguishes several container types. An Array is a fixed-shape, indexable structure with declared bounds, and it can carry a datatype. A list is an immutable, ordered sequence enclosed in square brackets. A Vector is a one-dimensional Array, and a Matrix is a two-dimensional one. Printing an Array variable directly shows the structure with its index ranges and datatype metadata in the worksheet, not a plain row of values, so print(A) is rarely the "list" most users want.

Two consequences follow. First, you almost always want either convert(A, list) for a flat, comma-separated presentation, or seq for controlled iteration. Second, arrays can have non-default index origins — an Array created with Array(1..3) starts at 1, while one declared Array(0..2) starts at 0 — so any loop that assumes indices run 1 to n will silently miss or misreport the first element. Real Maple output for a three-element integer Array looks like a bracketed row [1, 2, 3] after conversion, whereas the raw Array prints as an indexed construct. If you are comparing screenshots from different worksheet versions, the exact 2-D rendering has varied across releases, so judge success by the values and count, not by pixel layout.

Before you start: know your array's shape, bounds, and dimension

Run these checks first; they determine which listing technique is even valid.

1: Confirm the container type. whattype(A) returns Array, Vector, or Matrix depending on construction. A plain list will return list, which needs no conversion at all. 2: Read the bounds. ArrayDims(A) gives the index ranges as a sequence like 1..3 for a vector or 1..2, 1..3 for a matrix. Check lowerbound(A, 1) and upperbound(A, 1) if you only care about one dimension. 3: Check the dimension count. op(2, ArrayDims(A)) exists only for two or more dimensions; for a Vector, ArrayDims yields a single range. Knowing this prevents dimension-mismatch errors later. 4: Note the datatype if it matters. An Array declared with datatype=float stores machine floats, and converting or printing it will show decimal forms rather than exact rationals.

Success check: you can state the array's dimensions and both bounds out loud before writing any loop. If ArrayDims returns something unexpected, rebuild the array — patching a listing routine around wrong bounds is the usual source of off-by-one output.

Method 1: Convert to a list for the simplest display

The single most direct way to "list items" is:

convert(A, list)

For a Vector A := Array(1..3, [10, 20, 30]), this returns [10, 20, 30]. For a two-dimensional Array, convert flattens in column-major order — Maple stores and traverses the first index fastest — so a 2×3 Array with rows <1,2,3> and <4,5,6> converts to [1, 4, 2, 5, 3, 6]. That ordering surprises people who expect row-major (reading-order) output. If you need rows, list each row separately:

[seq(convert(A[i, ..], list), i = 1 .. 2)]

which yields [[1, 2, 3], [4, 5, 6]]. Note that A[i, ..] extracts a row as a Vector, and converting that Vector to a list gives the row's values.

A caution on immutability: converting is a copy. For a large Array — say a million float entries — convert(A, list) doubles memory use for the duration and takes measurable time. If you only want to display rather than store, seq with printing (Method 2) avoids the full copy. Use convert freely for small arrays and in interactive sessions; for bulk data, iterate.

Success check: after L := convert(A, list), nops(L) equals the total element count from ArrayDims (product of range lengths), and the first and last entries match A[lowerbound(A,1), ...] and the corresponding upper corner.

Method 2: Loop and print, with control over separators and indices

When you want formatted output — one item per line, indices attached, or a custom separator — use a for loop or seq with printf:

This prints A = 10 and so on, one per line. Starting from lowerbound rather than 1 is the habit that survives index-origin changes. For a single line with custom separation, seq inside a cat or printf works:

printf("%a, ", seq(A[i], i = 1 .. upperbound(A,1)))

which produces a trailing comma you can trim, or use ListTools:-Join-style string building with cat(seq(...)) and a ", " glue inserted between elements via seq and nops. For matrices, a nested loop over both bounds and a newline after each row is the standard pattern:

The %a format specifier prints in a Maple-readable algebraic form; %d forces integer formatting and will error or truncate on non-integer entries, so match the specifier to the datatype.

Success check: count the printed lines (or separators) against the element total. If a matrix row prints with the wrong number of entries, you have swapped the row and column bounds — a frequent error because ArrayDims returns them in index order, not visual order.

Method 3: Build a list with seq or map, then display it once

If you want a list for further computation rather than immediate printing, seq and map are the idiomatic builders:

seq(A[i], i = 1 .. upperbound(A,1)) builds a flat list from a Vector. [seq(A[i,j], j = 1 .. 3)] builds one row of a matrix as a list; wrapping the outer seq in brackets yields a list of row lists. map(f, convert(A, list)) applies a function to every element — useful when "listing" really means "listing transformed values."

One trap: map over an Array returns an Array of the same shape, not a list, so if downstream code expects a list, convert afterward. Likewise, seq over a two-dimensional Array with a single index variable is not meaningful; supply both ranges. These are cheap to verify by wrapping the result in whattype.

Success check: type(result, list) should return true, and nops(result) should equal the element count or row count you intended. If whattype says Array, you applied map without converting.

Method 4: Print the whole structure, all dimensions, with indices

Sometimes the request is literally "show me everything, including where each item sits." The print command on the un-converted Array shows structure metadata; to get indices and values together, use printf inside Array-aware iteration, or the lprint command, which prints in linear (1-D) form without 2-D typesetting. On a two-dimensional Array, lprint(A) emits the indexed constructor form, which is verbose but unambiguous about bounds.

For a compact indexed dump, nested printf as in Method 2 with A[%d,%d] = %a in the format string covers it. Avoid trying to force convert(A, list) to carry indices; it cannot, because a list has no index metadata. A small helper procedure — take the Array, loop over ArrayDims, printf each pair — is the maintainable version if you do this repeatedly, and it keeps the index-origin logic in one place.

Success check: the number of index-value pairs printed equals the product of the dimension lengths, and the first pair uses the lower bounds, not 1,1.

Removing or skipping items while you list them

Real arrays often contain zeros, FAIL, or undefined entries you don't want in the output. Two approaches:

1: Filter after converting. select(x -> x <> 0, convert(A, list)) drops zeros; remove(undefined, ...) drops undefined entries. select and remove preserve order, so the surviving items appear in traversal order. 2: Filter during iteration. Add an if guard inside the for loop before printing. This avoids building an intermediate list and is the better choice for big arrays.

Ordering caveat: filtering does not renumber anything, so if you need original indices in the output, keep them explicit (if A[i] <> 0 then printf("A[%d] = %a\n", i, A[i]) end if). Filtering silently reindexes only if you build a fresh Array from the survivors — don't do that if index identity matters.

Success check: the difference between the total element count and the printed count equals the number of items your predicate should have excluded. If they disagree, your predicate is catching more (or less) than intended — test it on a tiny array first.

Writing array items to a file or exporting them

For output that outlives the session, the linear form is easiest:

ExportMatrix("out.txt", A) handles Matrices and writes delimited text; check the delimiter and orientation options, since the default may write transpose-style relative to what you expect. writeline or fprintf in a loop gives exact control: open with fopen, loop as in Method 2 using fprintf, then fclose. Always close the file — an unclosed handle can leave the tail of a buffer unwritten. For a plain list, writedata accepts a list and writes one element per line by default.

Path caveats: relative paths resolve against the current working directory, which in a worksheet may not be where the file sits on disk. Use an absolute path or set the directory explicitly (currentdir) before writing, and re-read the file once to confirm the number of lines matches the element count.

Success check: reopen the written file and count records against nops(convert(A, list)). A short file almost always means the buffer wasn't flushed because fclose was skipped.

Common mistakes and how to confirm the list is correct

Index-origin assumptions. Loops hardcoded 1..n miss element 0 of a 0-based Array or hit an out-of-bounds error. Symptom: an index out of range message or a first element that doesn't match. Fix: derive bounds from ArrayDims. Flattened order confusion. convert(A, list) on a matrix goes column-major; expecting row-major is the single most common "wrong output" report. Symptom: interleaved values. Fix: row-wise seq extraction. Datatype display. Integer-typed arrays printing as floats, or very large integers printed with scientific notation under an inappropriate format specifier. Symptom: values look rounded. Fix: use %a or convert to exact rationals first. Shared-memory surprises. "Shared" Arrays can appear to change while you iterate if another assignment references them; if your printed values drift mid-loop, that's the cause, and converting first snapshots the content. Evaluation-order surprises. Indexing with an unevaluated name or a symbolic index prints the index expression rather than the value. Symptom: A[i] literally in the output. Fix: ensure the index is a concrete integer at print time.

A dependable verification pattern for any method: compute expected := nops(convert(A, list)), then compare against the printed line or item count. That single comparison catches bounds, dimension, and filter errors at once.

Frequently asked questions

Why does print(A) not show a plain list? Because print renders the Array structure itself, including bounds and datatype, not just values. Use convert(A, list) or a loop for value-only output; use lprint for a linear structural view.

How do I list elements of a 0-based Array? Always take bounds from ArrayDims(A) or lowerbound/upperbound and loop between them. Hardcoding 1..n is the usual failure; the first element at index 0 will be omitted or produce an out-of-range error.

Does convert(A, list) preserve row order for a Matrix? No. It traverses column-major (first index fastest), so rows interleave. Extract rows individually with seq if reading order matters, and verify with a small test matrix.

Can I list items without making a copy? Yes — iterate with for and print, or use seq inside printf, rather than converting. This matters for large arrays where the converted list roughly doubles memory during the operation.