File r37/lisp/csl/html/r37_0043.html artifact 83796aed2e part of check-in b7c3de82ef



<A NAME=CONS>

<TITLE>CONS</TITLE></A>
<b><a href=r37_idx.html>INDEX</a></b><p><p>



<B>CONS</B> _ _ _  _ _ _  _ _ _  _ _ _ <B>operator</B><P>
<P>
 
The <em>cons</em> operator adds a new element to the beginning of a 

<A HREF=r37_0302.html>list</A>. Its 
operation is identical to the symbol 
<A HREF=r37_0023.html>dot</A> (dot). It can be used 
infix or prefix. 
<P>
<P>
 <P> <H3> 
syntax: </H3>
<em>cons</em>(&lt;item&gt;,&lt;list&gt;) or &lt;item&gt; <em>cons</em> &lt;list
&gt; 
<P>
<P>
<P>
&lt;item&gt; can be any REDUCE scalar expression, including a list; &lt;list&gt;
 
must be a list. 
<P>
<P>
 <P> <H3> 
examples: </H3>
<P><PRE><TT>

liss := cons(a,{b}); 

  {A,B} 



liss := c cons liss; 

  {C,A,B} 



newliss := for each y in liss collect cons(y,list x);
 


  NEWLISS := {{C,X},{A,X},{B,X}} 



for each y in newliss sum (first y)*(second y);
 


  X*(A + B + C)

</TT></PRE><P>If you want to use <em>cons</em> to put together two elements into
 a new list, 
you must make the second one into a list with curly brackets or the <em>list
</em> 
command. You can also start with an empty list created by <em>{}</em>. 
<P>
<P>
The <em>cons</em> operator is right associative: <em>a cons b cons c</em> is val
id 
if <em>c</em> is a list; <em>b</em> need not be a list. The list produced is 
<em>{a,b,c}</em>. 
<P>
<P>
<P>
<P>


REDUCE Historical
REDUCE Sourceforge Project | Historical SVN Repository | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]