Skip to content

QueryOne!: Support /./ to immediately get term + -default when 0 results#265

Open
osnr wants to merge 2 commits into
mainfrom
osnr/queryone-dot-and-default
Open

QueryOne!: Support /./ to immediately get term + -default when 0 results#265
osnr wants to merge 2 commits into
mainfrom
osnr/queryone-dot-and-default

Conversation

@osnr
Copy link
Copy Markdown
Collaborator

@osnr osnr commented May 29, 2026

Saves a lot of code repetition -- we've been using lindex, dict getdef, and list length comparisons very repetitively when querying imperatively.

image image

See Discord: https://discord.com/channels/956758212152025098/956765077883744266/1510000054507802785

image

Need to test that this didn't break anything.

osnr added 2 commits May 29, 2026 16:22
@osnr osnr requested review from cwervo, ppkn and smj-edison May 29, 2026 20:55
}
set formats [QueryOne! the paper formats are /./]
set formatName [QueryOne! paper format /./ is the default paper format \
-default letter]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you allow flags to be passed in after query parameters? I suppose this is more of an edge case, but -- might be needed in the future.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Generally, I think we allow flags anywhere? + it reads better this way, I think, without the letter right up next to paper

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I like the idea of eventually supporting --

}
try {
dict set options printer \
[QueryOne! printer /./ is the default printer]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would you want a flag like -takefirst instead of try/on here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or I suppose this is just in case nothing is returned, never mind.

@s-ol
Copy link
Copy Markdown
Collaborator

s-ol commented May 29, 2026

Neat. /./ is a new bit of "syntax", right? I'm wondering if using uplevel to match When's binding logic could make sense:

AssignOne! the paper formats are /formats/
# equivalent to
set formats [QueryOne! the paper formats are /./]

# enables multiple capture (still enforcing single overall match)
AssignOne! the /medium/ formats are /formats/

You could also specify defaults inline, although that requires introducing specialized syntax once again:

AssignOne! the /medium=paper/ formats are /formats={letter a4}/

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.

3 participants