Difference between revisions of "Zip Command"

From GeoGebra Manual
Jump to: navigation, search
Line 4: Line 4:
 
:Creates [[Lists|list]] of objects obtained by substitution of variables in the expression by elements of corresponding lists. Length of the resulting list is minimum of lengths of output lists.
 
:Creates [[Lists|list]] of objects obtained by substitution of variables in the expression by elements of corresponding lists. Length of the resulting list is minimum of lengths of output lists.
 
{{example|1=Let P,Q,R,S,T be some points. <code>Zip[Midpoint[A,B],A,{P,Q},B,{R,S,T}]</code> returns a list containing [[Midpoint Command|midpoints]] of segments ''PR'' and ''QS''.}}
 
{{example|1=Let P,Q,R,S,T be some points. <code>Zip[Midpoint[A,B],A,{P,Q},B,{R,S,T}]</code> returns a list containing [[Midpoint Command|midpoints]] of segments ''PR'' and ''QS''.}}
 +
 +
{{Note|In each list the elements must be of the same type.}}

Revision as of 17:26, 14 July 2011



Zip[<Expression>, <Var1>, <List1>, <Var2>, <List2>, ...]
Creates list of objects obtained by substitution of variables in the expression by elements of corresponding lists. Length of the resulting list is minimum of lengths of output lists.
Example: Let P,Q,R,S,T be some points. Zip[Midpoint[A,B],A,{P,Q},B,{R,S,T}] returns a list containing midpoints of segments PR and QS.


Note: In each list the elements must be of the same type.

Comments

It's actually enough to provide a single list to Zip(). This makes it a shorter alternative to Sequence() when all you want is to traverse a list. For example, Zip(a^2, a, listOfNumbers) is much shorter than Sequence(Element(listOfNumbers, a)^2, a, 1, Length(listOfNumbers)) (albeit in this case it's easier to just do listOfNumbers^2.)

Note Hint: Zip() is similar to a construct known as "map" in other programming languages.
© 2024 International GeoGebra Institute