From 83e6cc9197bd8e7a19834d291fe4c5e62639db38 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 22 Dec 2025 16:32:40 -0500 Subject: Add Path.writer() and Path.byte_writer() --- man/man3/tomo-Path.3 | 18 ++++++++++++++++- man/man3/tomo-Path.byte_writer.3 | 42 ++++++++++++++++++++++++++++++++++++++++ man/man3/tomo-Path.writer.3 | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 man/man3/tomo-Path.byte_writer.3 create mode 100644 man/man3/tomo-Path.writer.3 (limited to 'man') diff --git a/man/man3/tomo-Path.3 b/man/man3/tomo-Path.3 index ae9b6d51..b916005a 100644 --- a/man/man3/tomo-Path.3 +++ b/man/man3/tomo-Path.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path 3 2025-12-07 "Tomo man-pages" +.TH Path 3 2025-12-22 "Tomo man-pages" .SH NAME Path \- a Tomo type .SH LIBRARY @@ -50,6 +50,14 @@ For more, see: .BR Tomo-Path.by_line (3) +.TP +.BI Path.byte_writer\ :\ func(path:\ Path,\ append:\ Bool\ =\ no,\ permissions:\ Int32\ =\ Int32(0o644)\ ->\ func(bytes:[Byte],\ close:Bool=no\ ->\ Result)) +Returns a function that can be used to repeatedly write bytes to the same file. + +For more, see: +.BR Tomo-Path.byte_writer (3) + + .TP .BI Path.can_execute\ :\ func(path:\ Path\ ->\ Bool) Returns whether or not a file can be executed by the current user/group. @@ -345,3 +353,11 @@ Writes the given bytes to a unique file path based on the specified path. The fi For more, see: .BR Tomo-Path.write_unique_bytes (3) + +.TP +.BI Path.writer\ :\ func(path:\ Path,\ append:\ Bool\ =\ no,\ permissions:\ Int32\ =\ Int32(0o644)\ ->\ func(text:Text,\ close:Bool=no\ ->\ Result)) +Returns a function that can be used to repeatedly write to the same file. + +For more, see: +.BR Tomo-Path.writer (3) + diff --git a/man/man3/tomo-Path.byte_writer.3 b/man/man3/tomo-Path.byte_writer.3 new file mode 100644 index 00000000..595f0156 --- /dev/null +++ b/man/man3/tomo-Path.byte_writer.3 @@ -0,0 +1,42 @@ +'\" t +.\" Copyright (c) 2025 Bruce Hill +.\" All rights reserved. +.\" +.TH Path.byte_writer 3 2025-12-22 "Tomo man-pages" +.SH NAME +Path.byte_writer \- create a byte-based file writer +.SH LIBRARY +Tomo Standard Library +.SH SYNOPSIS +.nf +.BI Path.byte_writer\ :\ func(path:\ Path,\ append:\ Bool\ =\ no,\ permissions:\ Int32\ =\ Int32(0o644)\ ->\ func(bytes:[Byte],\ close:Bool=no\ ->\ Result)) +.fi +.SH DESCRIPTION +Returns a function that can be used to repeatedly write bytes to the same file. + + +.SH ARGUMENTS + +.TS +allbox; +lb lb lbx lb +l l l l. +Name Type Description Default +path Path The path of the file to write to. - +append Bool If set to \fByes\fR, writes to the file will append. If set to \fBno\fR, then the first write to the file will overwrite its contents and subsequent calls will append. no +permissions Int32 The permissions to set on the file if it is created. Int32(0o644) +.TE +.SH RETURN +Returns a function that can repeatedly write bytes to the same file. If `close` is set to `yes`, then the file will be closed after writing. If this function is called again after closing, the file will be reopened for appending. + +.SH NOTES +The file writer will keep its file descriptor open after each write (unless the `close` argument is set to `yes`). If the file writer is never closed, it will be automatically closed when the file writer is garbage collected. + +.SH EXAMPLES +.EX +write := (./file.txt).byte_writer() +write("Hello\[rs]n".utf8())! +write("world\[rs]n".utf8(), close=yes)! +.EE +.SH SEE ALSO +.BR Tomo-Path (3) diff --git a/man/man3/tomo-Path.writer.3 b/man/man3/tomo-Path.writer.3 new file mode 100644 index 00000000..8b3d53d8 --- /dev/null +++ b/man/man3/tomo-Path.writer.3 @@ -0,0 +1,42 @@ +'\" t +.\" Copyright (c) 2025 Bruce Hill +.\" All rights reserved. +.\" +.TH Path.writer 3 2025-12-22 "Tomo man-pages" +.SH NAME +Path.writer \- create a file writer +.SH LIBRARY +Tomo Standard Library +.SH SYNOPSIS +.nf +.BI Path.writer\ :\ func(path:\ Path,\ append:\ Bool\ =\ no,\ permissions:\ Int32\ =\ Int32(0o644)\ ->\ func(text:Text,\ close:Bool=no\ ->\ Result)) +.fi +.SH DESCRIPTION +Returns a function that can be used to repeatedly write to the same file. + + +.SH ARGUMENTS + +.TS +allbox; +lb lb lbx lb +l l l l. +Name Type Description Default +path Path The path of the file to write to. - +append Bool If set to \fByes\fR, writes to the file will append. If set to \fBno\fR, then the first write to the file will overwrite its contents and subsequent calls will append. no +permissions Int32 The permissions to set on the file if it is created. Int32(0o644) +.TE +.SH RETURN +Returns a function that can repeatedly write to the same file. If `close` is set to `yes`, then the file will be closed after writing. If this function is called again after closing, the file will be reopened for appending. + +.SH NOTES +The file writer will keep its file descriptor open after each write (unless the `close` argument is set to `yes`). If the file writer is never closed, it will be automatically closed when the file writer is garbage collected. + +.SH EXAMPLES +.EX +write := (./file.txt).writer() +write("Hello\[rs]n")! +write("world\[rs]n", close=yes)! +.EE +.SH SEE ALSO +.BR Tomo-Path (3) -- cgit v1.2.3 From dbae987f1fb54da795185a03f4c00d56a639f8cd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 31 Dec 2025 15:13:32 -0500 Subject: Changed is_between() to be bidirectional --- man/man3/tomo-Byte.is_between.3 | 9 +++++---- man/man3/tomo-Int.3 | 4 ++-- man/man3/tomo-Int.is_between.3 | 11 ++++++----- man/man3/tomo-Num.is_between.3 | 9 +++++---- 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'man') diff --git a/man/man3/tomo-Byte.is_between.3 b/man/man3/tomo-Byte.is_between.3 index 06e53fb0..3b539ea1 100644 --- a/man/man3/tomo-Byte.is_between.3 +++ b/man/man3/tomo-Byte.is_between.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Byte.is_between 3 2025-11-29 "Tomo man-pages" +.TH Byte.is_between 3 2025-12-31 "Tomo man-pages" .SH NAME Byte.is_between \- test if inside a range .SH LIBRARY @@ -23,15 +23,16 @@ lb lb lbx l l l. Name Type Description x Byte The integer to be checked. -low Byte The lower bound to check (inclusive). -high Byte The upper bound to check (inclusive). +low Byte One end of the range to check (inclusive); +high Byte The other end of the range to check (inclusive); .TE .SH RETURN -`yes` if `low <= x and x <= high`, otherwise `no` +`yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no` .SH EXAMPLES .EX assert Byte(7).is_between(1, 10) == yes +assert Byte(7).is_between(10, 1) == yes assert Byte(7).is_between(100, 200) == no assert Byte(7).is_between(1, 7) == yes .EE diff --git a/man/man3/tomo-Int.3 b/man/man3/tomo-Int.3 index 186c0aae..64ae7bf6 100644 --- a/man/man3/tomo-Int.3 +++ b/man/man3/tomo-Int.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int 3 2025-11-30 "Tomo man-pages" +.TH Int 3 2025-12-31 "Tomo man-pages" .SH NAME Int \- a Tomo type .SH LIBRARY @@ -59,7 +59,7 @@ For more, see: .TP -.BI Int.is_between\ :\ func(x:\ Int,\ low:\ Int,\ high:\ Int\ ->\ Bool) +.BI Int.is_between\ :\ func(x:\ Int,\ a:\ Int,\ b:\ Int\ ->\ Bool) Determines if an integer is between two numbers (inclusive). For more, see: diff --git a/man/man3/tomo-Int.is_between.3 b/man/man3/tomo-Int.is_between.3 index 8087e0d0..fd54eb41 100644 --- a/man/man3/tomo-Int.is_between.3 +++ b/man/man3/tomo-Int.is_between.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.is_between 3 2025-11-29 "Tomo man-pages" +.TH Int.is_between 3 2025-12-31 "Tomo man-pages" .SH NAME Int.is_between \- test if an int is in a range .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Int.is_between\ :\ func(x:\ Int,\ low:\ Int,\ high:\ Int\ ->\ Bool) +.BI Int.is_between\ :\ func(x:\ Int,\ a:\ Int,\ b:\ Int\ ->\ Bool) .fi .SH DESCRIPTION Determines if an integer is between two numbers (inclusive). @@ -23,15 +23,16 @@ lb lb lbx l l l. Name Type Description x Int The integer to be checked. -low Int The lower bound to check (inclusive). -high Int The upper bound to check (inclusive). +a Int One end of the range to check (inclusive). +b Int The other end of the range to check (inclusive). .TE .SH RETURN -`yes` if `low <= x and x <= high`, otherwise `no` +`yes` if `a <= x and x <= b` or `a >= x and x >= b`, otherwise `no` .SH EXAMPLES .EX assert (7).is_between(1, 10) == yes +assert (7).is_between(10, 1) == yes assert (7).is_between(100, 200) == no assert (7).is_between(1, 7) == yes .EE diff --git a/man/man3/tomo-Num.is_between.3 b/man/man3/tomo-Num.is_between.3 index 4276c8e3..ea78d895 100644 --- a/man/man3/tomo-Num.is_between.3 +++ b/man/man3/tomo-Num.is_between.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.is_between 3 2025-11-29 "Tomo man-pages" +.TH Num.is_between 3 2025-12-31 "Tomo man-pages" .SH NAME Num.is_between \- check if a number is in a range .SH LIBRARY @@ -23,15 +23,16 @@ lb lb lbx l l l. Name Type Description x Num The integer to be checked. -low Num The lower bound to check (inclusive). -high Num The upper bound to check (inclusive). +low Num One end of the range to check (inclusive). +high Num The other end of the range to check (inclusive). .TE .SH RETURN -`yes` if `low <= x and x <= high`, otherwise `no` +`yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no` .SH EXAMPLES .EX assert (7.5).is_between(1, 10) == yes +assert (7.5).is_between(10, 1) == yes assert (7.5).is_between(100, 200) == no assert (7.5).is_between(1, 7.5) == yes .EE -- cgit v1.2.3