extracting elements [+#], [+#..+#], [-#], [-#..-#], ..

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 554
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

extracting elements [+#], [+#..+#], [-#], [-#..-#], ..

Message par compsystems » mar. janv. 14, 2020 8:55 pm

Hi

There are some outputs that I cannot understand when extracting elements, please review the following script

Code : Tout sélectionner

seq1 := ( a, b, c )

/* SIMPLE []
USE OF POSITIVE INDICES [0, ...] */

seq1[ 0 ] -> a
seq1[ 1 ] -> b
seq1[ 2 ] -> c

/* USE OF  NEGATIVE INDICES [..., - 1] */

seq1[ -1 ] -> c
seq1[ -2 ] -> b
seq1[ -3 ] -> a

/* DOUBLE [[]]
USE OF POSITIVE INDICES [[0, ...]] */

seq1[[1]] -> a
seq1[[2]] -> b
seq1[[3]] -> c

/* SUBSEQUENCES OR PORTIONS OF A SEQUENCE
SIMPLE []
USE OF  POSITIVE INDICES [0, ...] and operator (..)
 */

seq1[ 0 .. 1 ] -> ( a, b )
seq1[ 1 .. 2 ] -> ( b, c )
seq1[ 0 .. 0 ] -> a
seq1[ 1 .. 3 ] -> ( b, c )
seq1[ 0 .. 2 ] -> ( a, b, c )
seq1[ 2 .. 2 ]  -> c

/* Combination of signs */

seq1[ 2 .. 0 ] -> seq[ ] //  expected 2, from element 2 to element 0 on the left
seq1[ 2 .. -1 ] -> c // expected ( b, c )
seq1[ 2 .. -2 ] -> seq[ ] // expected ( a, b, c )


/* USE OF NEGATIVE INDICES [..., - 1] */

seq1[ -2 .. -1 ] -> ( b, c )
seq1[ -3 .. -1 ] -> ( a, b, c ) 

/* Combination of signs */

seq1[ -3 .. 0 ] -> a  // from element -3 to element 0 on the right
seq1[ -3 .. 1 ] -> ( a, b ) // from element -3 to 1 element on the right
seq1[ -3 .. 2 ] -> ( a, b, c ) // from element -3 to 2 element on the right
seq1[ -3 .. 3 ] -> ( a, b, c )
seq1[ -2 .. 0 ] -> seq[ ] // expected ( b )
seq1[ -2 .. 1 ] -> b // expected ( b, c )

Répondre