CoCoA:Comp

From ApCoCoAWiki

Comp

the N-th component of a list

Description

This function returns E[X_1,...,X_k] except in the case where there

are no additional arguments X_1,...,X_k, in which case E, itself, is

returned (in other words Comp(E) returns E). Since the square bracket notation works only for variables and indeterminates, this function must be used in all other situations (e.g. directly indexing into, or selecting from, the result of a function call).

Example

  Use R ::= Q[x,y,z];
  L := [4,5,[6,7],8];
  Comp(L,1);
4
-------------------------------
  Comp(L,3);
[6, 7]
-------------------------------
  Comp(L,3,2);
7
-------------------------------
  Define F(X)  Return [X,X^2];  EndDefine;  
  -- the following usage of <quotes>Comp</quotes> is useful for programming
  F(2);
[2, 4]
-------------------------------
  Comp(F(2),2);
4
-------------------------------
  Struct := Record[L := [x,y,z], S := <quotes>string</quotes>];
  Struct[<quotes>L</quotes>,3]; -- <quotes>Comp</quotes> works for records also
z
-------------------------------
  Comp(Struct,<quotes>L</quotes>,3);
z
-------------------------------
  Comp(<quotes>this is a string</quotes>,3);  -- use of <quotes>Comp</quotes> with strings
i
-------------------------------

Syntax

Comp(E:LIST, RECORD, STRING, or VECTOR,X_1:INT,...,X_k:INT):OBJECT
   <type>list</type>
   <type>record</type>
   <type>string</type>
   <type>vector</type>