mirror of
				https://github.com/janet-lang/janet
				synced 2025-11-04 09:33:02 +00:00 
			
		
		
		
	Explain the logic behind negative slice indices.
This commit is contained in:
		@@ -273,7 +273,8 @@ static const JanetReg array_cfuns[] = {
 | 
				
			|||||||
             "Takes a slice of array or tuple from start to end. The range is half open, "
 | 
					             "Takes a slice of array or tuple from start to end. The range is half open, "
 | 
				
			||||||
             "[start, end). Indexes can also be negative, indicating indexing from the end of the "
 | 
					             "[start, end). Indexes can also be negative, indicating indexing from the end of the "
 | 
				
			||||||
             "end of the array. By default, start is 0 and end is the length of the array. "
 | 
					             "end of the array. By default, start is 0 and end is the length of the array. "
 | 
				
			||||||
             "Returns a new array.")
 | 
					             "Note that index -1 is synonymous with index (length arrtup) to allow a full "
 | 
				
			||||||
 | 
					             "negative slice range. Returns a new array.")
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        "array/concat", cfun_array_concat,
 | 
					        "array/concat", cfun_array_concat,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -525,7 +525,8 @@ static const JanetReg string_cfuns[] = {
 | 
				
			|||||||
             "Returns a substring from a byte sequence. The substring is from "
 | 
					             "Returns a substring from a byte sequence. The substring is from "
 | 
				
			||||||
             "index start inclusive to index end exclusive. All indexing "
 | 
					             "index start inclusive to index end exclusive. All indexing "
 | 
				
			||||||
             "is from 0. 'start' and 'end' can also be negative to indicate indexing "
 | 
					             "is from 0. 'start' and 'end' can also be negative to indicate indexing "
 | 
				
			||||||
             "from the end of the string.")
 | 
					             "from the end of the string. Note that index -1 is synonymous with "
 | 
				
			||||||
 | 
					             "index (length bytes) to allow a full negative slice range. ")
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        "string/repeat", cfun_string_repeat,
 | 
					        "string/repeat", cfun_string_repeat,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -143,7 +143,10 @@ static const JanetReg tuple_cfuns[] = {
 | 
				
			|||||||
        JDOC("(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])\n\n"
 | 
					        JDOC("(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])\n\n"
 | 
				
			||||||
             "Take a sub sequence of an array or tuple from index start "
 | 
					             "Take a sub sequence of an array or tuple from index start "
 | 
				
			||||||
             "inclusive to index end exclusive. If start or end are not provided, "
 | 
					             "inclusive to index end exclusive. If start or end are not provided, "
 | 
				
			||||||
             "they default to 0 and the length of arrtup respectively."
 | 
					             "they default to 0 and the length of arrtup respectively. "
 | 
				
			||||||
 | 
					             "'start' and 'end' can also be negative to indicate indexing "
 | 
				
			||||||
 | 
					             "from the end of the input. Note that index -1 is synonymous with "
 | 
				
			||||||
 | 
					             "index '(length arrtup)' to allow a full negative slice range. "
 | 
				
			||||||
             "Returns the new tuple.")
 | 
					             "Returns the new tuple.")
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user