       Re: Scalars Instead of Lists with One Element

• To: mathgroup at smc.vnet.net
• Subject: [mg83455] Re: Scalars Instead of Lists with One Element
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Wed, 21 Nov 2007 02:43:26 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <fhu75c\$72j\$1@smc.vnet.net>

```Gregory Lypny wrote:

> Say I have the list x={2, 7}.  Is there a command I can use to get 2
> rather than {2} when I ask for x[], and 7 rather than {7} when I

Here, I do not follow (or understand) you. You have a list of scalars
and taking any one of its elements with *Part* will produce a scalar and
not a list of one element. Or you may have something else in mind... For
instance,

In:= x = {2, 7}

Out= {2, 7}

In:= x[]

Out= 2

In:= x[]

Out= 7

As you can see above, no list is returned in this case.

> ask for x[]?  Doing so would solve my problem with my tables being
> too deep to be able to cut and paste directly into the table objects
> of other applications like word processors and spread sheets.

You could use the system variable *\$Post* and set up your own post
processing function. (You might be interested in \$PrePrint too.) Here is
an example of such a function that should do what you are looking for,
though you may want to add some additional tests (or remove few of them).

In:= \$Post =
If[Head[#] === List && Length[#] == 1 &&
Depth[#] < 3, #[], #] &;

prob = {.4, {.6}, {.4, .6}, {{.4, .6}}};

prob[] (* Scalar: not a list, depth one *)
prob[] (* List of length one and depth two *)
prob[] (* List of length two and depth two *)
prob[] (* List of length one and depth three *)

\$Post =. (* Reset \$Post *)

Out= 0.4

Out= 0.6

Out= {0.4, 0.6}

Out= {{0.4, 0.6}}

Best regards,
--
Jean-Marc

```

• Prev by Date: Re: Variable-length list?
• Next by Date: Can DSolve handle normalized vectors?
• Previous by thread: Re: Scalars Instead of Lists with One Element
• Next by thread: Re: Scalars Instead of Lists with One Element