let lower: ContextFunction = Box::new( args { let str = if args.isempty() { return…
- User
let lower: ContextFunction = Box::new(|args| { let str = if args.is_empty() { return String::new(); } else { &args[0] }; str.to_lowercase() });
extract
let str = if args.is_empty() { return String::new(); } else { &args[0] }; ``` into a macro Assistant
Here's how you can extract that code into a macro:
macro_rules! first_arg_or_empty { ($args:ident) => { if $args.is_empty() { return String::new(); } else { &$args[0] } }; } let lower: ContextFunction = Box::new(|args| { let str = first_arg_or_empty!(args); str.to_lowercase() });The macro
first_arg_or_empty!takes an identifier (theargsparameter) and expands to the if-else expression that either returns an empty string or gives a reference to the first argument.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.