Skip to content

Commit

Permalink
fix: range -> rg
Browse files Browse the repository at this point in the history
All other type are abbreviation, no reason to use a full word for ranges
  • Loading branch information
giann committed May 15, 2024
1 parent 7863f07 commit d0b71a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var value = from {
- By default, imported symbols from another script will be under `libprefix.XXXX`
- When importing something, you can still redefine its namespace prefix with `import "..." as mynewnamespace` or remove it altogether with `import "..." _`
- Ranges are now an actual buzz value (https://github.com/buzz-language/buzz/issues/170)
- new `range` type
- new `rg` type
- `myrange.toList()` transforms a range into a list of integers
- `myrange.low` and `myrange.high` to get a range bounds
- works with `foreach`
Expand Down
2 changes: 1 addition & 1 deletion src/Token.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub const keywords = std.StaticStringMap(Type).initComptime(
.{ "out", .Out },
.{ "pat", .Pat },
.{ "protocol", .Protocol },
.{ "range", .Range },
.{ "rg", .Range },
.{ "resolve", .Resolve },
.{ "resume", .Resume },
.{ "return", .Return },
Expand Down
4 changes: 2 additions & 2 deletions src/obj.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2524,7 +2524,7 @@ pub const ObjRange = struct {
.{
.{ "toList", "extern Function toList() > [int]" },
.{ "len", "extern Function len() > int" },
.{ "invert", "extern Function invert() > range" },
.{ "invert", "extern Function invert() > rg" },
},
);

Expand Down Expand Up @@ -4025,7 +4025,7 @@ pub const ObjTypeDef = struct {
.String => try writer.writeAll("str"),
.Pattern => try writer.writeAll("pat"),
.Any => try writer.writeAll("any"),
.Range => try writer.writeAll("range"),
.Range => try writer.writeAll("rg"),
.Fiber => {
try writer.writeAll("fib<");
try self.resolved_type.?.Fiber.return_type.toStringRaw(writer, qualified);
Expand Down
26 changes: 13 additions & 13 deletions tests/053-range.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import "std";

test "Range" {
int limit = 10;
range rg = 0..limit;
rg range = 0..limit;

std.assert(rg == 0..10, message: "Could compare ranges");
std.assert(rg.low == 0, message: "Could get low limit of range");
std.assert(rg.high == 10, message: "Could get high limit of range");
std.assert(range == 0..10, message: "Could compare ranges");
std.assert(range.low == 0, message: "Could get low limit of range");
std.assert(range.high == 10, message: "Could get high limit of range");

[int] list = rg.toList();
[int] list = range.toList();
std.assert(list.len() == 10, message: "Could create list from range");

int sum = 0;
Expand All @@ -17,18 +17,18 @@ test "Range" {
}
std.assert(sum == 45, message: "Could iterate over range");

std.assert(rg.len() == 10, message: "Could get range length");
std.assert(range.len() == 10, message: "Could get range length");
}

test "Inverted range" {
int limit = 0;
range rg = 10..limit;
rg range = 10..limit;

std.assert((0..10).invert() == rg, message: "Could invert range");
std.assert(rg.low == 10, message: "Could get low limit of range");
std.assert(rg.high == 0, message: "Could get high limit of range");
std.assert((0..10).invert() == range, message: "Could invert range");
std.assert(range.low == 10, message: "Could get low limit of range");
std.assert(range.high == 0, message: "Could get high limit of range");

[int] list = rg.toList();
[int] list = range.toList();
std.assert(list.len() == 10, message: "Could create list from inverted range");

int sum = 0;
Expand All @@ -37,5 +37,5 @@ test "Inverted range" {
}
std.assert(sum == 55, message: "Could iterate over inverted range");

std.assert(rg.len() == 10, message: "Could get range length");
}
std.assert(range.len() == 10, message: "Could get range length");
}

0 comments on commit d0b71a9

Please sign in to comment.