Skip to content

Text, regex, dictionary and list macros, and %cond - #16

Open
Demonstrandum wants to merge 1 commit into
masterfrom
more-macros
Open

Demonstrandum wants to merge 1 commit into
masterfrom
more-macros

Conversation

@Demonstrandum

@Demonstrandum Demonstrandum commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Fills the gaps in working with text and data.

Text (each keeps the kind of text it's given, so a symbol stays a symbol):

  • %upper, %lower, %capitalize, %trim
  • (%slugify "Hello, World!") → "hello-world"
  • (%replace "a" "o" "banana") → "bonono"
  • %starts-with, %ends-with
  • (%slice start [end] x) for text or lists, with negative indices counting from the end

Regular expressions (the regex crate; a \ is \\ in a seam string):

  • %regex/matches, %regex/find (every match), %regex/captures (first match and its groups, or nothing), %regex/replace (with $1 references), %regex/split

Dictionaries

  • (%set :title X :draft false %page): keys already present keep their place
  • (%remove draft %page)
  • (%merge %defaults %page): later values win

Lists

  • (%chunk 10 %posts) for pagination and grid rows
  • %sum, %index-of (nothing if absent), (%partition f list) → ((yes...) (no...))

Control

  • (%cond (test body...) ...): only the first true clause's test and body are expanded

Adds the regex dependency. Tests, USAGE.md and the README checklist are updated.


Note

Low Risk
New macro surface area and a regex dependency; behavior is covered by tests and does not change auth, I/O, or existing expansion paths.

Overview
Adds a large set of built-in data and text macros to the seam expander, implemented in a new expander/data.rs module and wired through expander.rs.

Text and regex: Case/transform helpers (%upper, %lower, %capitalize, %trim, %slugify), %replace, prefix/suffix checks, and %slice for atoms or lists. Regex support uses the new regex crate via %regex/matches, find, captures, replace, and split.

Dictionaries and lists: %set, %remove, and %merge for keyword dicts; %chunk, %sum, %index-of, and %partition for lists. %cond expands only the first true clause’s body (short-circuiting evaluation).

Shared expander helpers in code.rs are exposed to the new module. Tests, USAGE.md, and the README checklist document the macros.

Reviewed by Cursor Bugbot for commit 084a429. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 084a429. Configure here.

let items = list_of(value, node, "The list")?;
let range = range(items.len());
let sliced = items.into_iter().skip(range.start).take(range.len()).collect();
return Ok(Box::new([list_node(node, without_leading(sliced))]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slice realises entire lazy lists

Medium Severity

%slice on a list collects every item through list_of before taking the range, so slicing a lazy %range or %concat realises the whole source. %index-of does the same before searching. %take, %drop, %get, and %find already avoid that via List::slice and items().

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 084a429. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant