diff --git a/src/core/array.c b/src/core/array.c index 789b7363..b2ed9c27 100644 --- a/src/core/array.c +++ b/src/core/array.c @@ -237,11 +237,7 @@ JANET_CORE_FN(cfun_array_ensure, JANET_CORE_FN(cfun_array_slice, "(array/slice arrtup &opt start end)", - "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 array. By default, `start` is 0 and `end` is the length of the array. " - "Note that if the range is negative, it is taken as (start, end] to allow a full " - "negative slice range. Returns a new array.") { + "Same as `tuple/slice`, but returns an array.") { JanetView view = janet_getindexed(argv, 0); JanetRange range = janet_getslice(argc, argv); JanetArray *array = janet_array(range.end - range.start); diff --git a/src/core/buffer.c b/src/core/buffer.c index a9318622..d5c87950 100644 --- a/src/core/buffer.c +++ b/src/core/buffer.c @@ -531,10 +531,7 @@ JANET_CORE_FN(cfun_buffer_popn, JANET_CORE_FN(cfun_buffer_slice, "(buffer/slice bytes &opt start end)", - "Takes a slice of a byte sequence from `start` to `end`. The range is half open, " - "[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 buffer. " - "Returns a new buffer.") { + "Same as `string/slice`, but returns a buffer.") { JanetByteView view = janet_getbytes(argv, 0); JanetRange range = janet_getslice(argc, argv); JanetBuffer *buffer = janet_buffer(range.end - range.start); diff --git a/src/core/corelib.c b/src/core/corelib.c index 297d866a..cdaba373 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -416,7 +416,14 @@ JANET_CORE_FN(janet_core_array, JANET_CORE_FN(janet_core_slice, "(slice x &opt start end)", - "Extract a sub-range of an indexed data structure or byte sequence.") { + "Extract a sub-range of `x`. Sub-ranges may be " + "specified via optional arguments `start` and " + "`end` as in `string/slice`.\n" + "\n" + "If `x` is a bytes or abstract type with a suitable " + "`bytes` method, returns a string.\n" + "\n" + "If `x` is an indexed type, returns a tuple.") { JanetRange range; JanetByteView bview; JanetView iview; diff --git a/src/core/string.c b/src/core/string.c index c480deb6..124ddb1f 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -172,12 +172,19 @@ static int32_t kmp_next(struct kmp_state *state) { JANET_CORE_FN(cfun_string_slice, "(string/slice bytes &opt start end)", - "Returns a substring from a byte sequence. The substring is from " - "index `start` inclusive to index `end`, exclusive. All indexing " - "is from 0. `start` and `end` can also be negative to indicate indexing " - "from the end of the string. Note that if `start` is negative it is " - "exclusive, and if `end` is negative it is inclusive, to allow a full " - "negative slice range.") { + "Returns a string based on a range of a byte " + "sequence `bytes`. The range is specified by " + "optional index arguments `start` and `end` " + "defaulting to 0 and the length of `bytes` " + "respectively. When non-negative, `start` is " + "inclusive and `end` is exclusive, i.e. [`start`, " + "`end`), and their values can range from 0 through " + "the length of `bytes`. When negative, `start` is " + "exclusive and `end` is inclusive, i.e. (`start`, " + "`end`], and their values can range from the " + "negative of one more than the length of `bytes` " + "through -1. If `start` or `end` is out of range, " + "an error is raised.") { JanetByteView view = janet_getbytes(argv, 0); JanetRange range = janet_getslice(argc, argv); return janet_stringv(view.bytes + range.start, range.end - range.start); @@ -185,7 +192,7 @@ JANET_CORE_FN(cfun_string_slice, JANET_CORE_FN(cfun_symbol_slice, "(symbol/slice bytes &opt start end)", - "Same as string/slice, but returns a symbol.") { + "Same as `string/slice`, but returns a symbol.") { JanetByteView view = janet_getbytes(argv, 0); JanetRange range = janet_getslice(argc, argv); return janet_symbolv(view.bytes + range.start, range.end - range.start); @@ -193,7 +200,7 @@ JANET_CORE_FN(cfun_symbol_slice, JANET_CORE_FN(cfun_keyword_slice, "(keyword/slice bytes &opt start end)", - "Same as string/slice, but returns a keyword.") { + "Same as `string/slice`, but returns a keyword.") { JanetByteView view = janet_getbytes(argv, 0); JanetRange range = janet_getslice(argc, argv); return janet_keywordv(view.bytes + range.start, range.end - range.start); diff --git a/src/core/tuple.c b/src/core/tuple.c index 2c18bdb5..5bc827d7 100644 --- a/src/core/tuple.c +++ b/src/core/tuple.c @@ -64,14 +64,20 @@ JANET_CORE_FN(cfun_tuple_brackets, } JANET_CORE_FN(cfun_tuple_slice, - "(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])", - "Take a sub-sequence of an array or tuple from index `start` " - "inclusive to index `end` exclusive. If `start` or `end` are not provided, " - "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 if `start` is negative it is " - "exclusive, and if `end` is negative it is inclusive, to allow a full " - "negative slice range. Returns the new tuple.") { + "(tuple/slice ind &opt start end)", + "Returns a tuple based on a range of an indexed " + "type `ind`. The range is specified by optional " + "index arguments `start` and `end` defaulting to 0 " + "and the length of `ind` respectively. When " + "non-negative, `start` is inclusive and `end` is " + "exclusive, i.e. [`start`, `end`), and their " + "values can range from 0 through the length of " + "`ind`. When negative, `start` is exclusive and " + "`end` is inclusive, i.e. (`start`, `end`], and " + "their values can range from the negative of one " + "more than the length of `ind` through -1. If " + "`start` or `end` is out of range, an error is " + "raised.") { JanetView view = janet_getindexed(argv, 0); JanetRange range = janet_getslice(argc, argv); return janet_wrap_tuple(janet_tuple_n(view.items + range.start, range.end - range.start));