Re: Appending an element to a list

• To: mathgroup at smc.vnet.net
• Subject: [mg23910] Re: Appending an element to a list
• From: Hartmut Wolf <hwolf at debis.com>
• Date: Fri, 16 Jun 2000 00:56:51 -0400 (EDT)
• Organization: debis Systemhaus
• References: <8i9nta\$27l@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Felix Farkas schrieb:
>
>  i do have a problem, which is probably very easy,  but i couldn't find
> a reasonable way to solve it. I would appreciate very much any hint.
>
> I have a list of lists. My purpose is to append a new elements to this
> list. These elements are generated by some function. Sometimes the
> output of the function is an empty list meaning no element. In this
> situation Append includes the new element in the list. i would like to
> avoid this behaviour.
>
> ex:
>
> In[1]:=           d={}
> Out[1]=         {}
>
> In[2]:=           Append[{{2,2},{3,3}},d]
> Out[2]:=        {{2,2},{3,3},{}}
>

Perhaps this might be useful:

In[1]:= appendnoemptylistTo[expr_, {}] := expr
In[2]:= appendnoemptylistTo[expr_, elem_] := AppendTo[expr, elem]
In[3]:= b = d = e = {};

In[7]:= collector = {};
In[8]:=
Scan[appendnoemptylistTo[Unevaluated[collector], #] &, {a, b, c, d, e, f}]

In[9]:= collector
Out[9]= {a, c, f}

Kind regards,
Hartmut Wolf

```

• Prev by Date: Re: Integrate returns 0
• Next by Date: Manipulating List Elements In Programs
• Previous by thread: RE: Appending an element to a list
• Next by thread: Re: Appending an element to a list