hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 670e0a11e148af39dd442fdaf82f7f95a306e873
parent 98189ab4e70f6d8f93807d2c8e26e94a05740ca7
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  8 Jan 2022 14:01:43 +0100

path: return latest value from mutation functions

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mpath/buffer.ha | 4++--
Mpath/join.ha | 4+++-
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/path/buffer.ha b/path/buffer.ha @@ -20,8 +20,8 @@ export fn reset(buf: *buffer) void = { }; // Sets the value of a path buffer to a list of components, overwriting any -// previous value. -export fn set(buf: *buffer, items: str...) (void | errors::overflow) = { +// previous value. Returns the new string value of the path. +export fn set(buf: *buffer, items: str...) (str | errors::overflow) = { reset(buf); return add(buf, items...); }; diff --git a/path/join.ha b/path/join.ha @@ -3,7 +3,8 @@ use errors; use strings; // Joins several path elements together and copies them into a path buffer. -export fn add(buf: *buffer, items: str...) (void | errors::overflow) = { +// Returns the new string value of the path. +export fn add(buf: *buffer, items: str...) (str | errors::overflow) = { for (let i = 0z; i < len(items); i += 1) { const elem = strings::toutf8(items[i]); const tok = bytes::tokenize(elem, pathsep); @@ -22,6 +23,7 @@ export fn add(buf: *buffer, items: str...) (void | errors::overflow) = { appendnorm(buf, next)?; }; }; + return string(buf); }; @test fn add() void = {