You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First interesting question: Should qt() strings be sub-lexed, or not..?
I.e. what do people feel -should- be the behaviour of a construction like
subf { ... }
say qt(Is this { f(")") } valid syntax?);
Should it:
Yield a parse error similar to the ones given in the example above?
Parse as valid perl code yielding a similar result to:
say'Is this ', f(")"), ' valid syntax?';
Something else?
I feel that interpretation 2 might be most useful and powerful, but would be inconsistent with existing behaviour of existing operators. Interpretation 1 is certainly easier to achieve as it reüses existing parser structures, but given the whole point is to interpolate code inside the {braces} it might lead to weird annoying cases that don't work so well.
Does anyone have any good examples one way or other from other languages that have a similar construction?
FWIW, my implementation at https://metacpan.org/pod/Quote::Code goes with interpretation 2. It recursively parses embedded code blocks as it scans through the string. This is different from how perl does things, but I've never found a case where perl's "scan for the end and reparse" approach is actually useful. All it does is cause bizarre problems (e.g. with source filters that want to rewrite code). I'd welcome a change.
JavaScript's `...` construct also works this way:
console.log(`a ${'b'} c`);// "a b c"console.log(`a ${'}'} c`);// "a } c"console.log(`a ${`}`} c`);// "a } c"console.log(`a ${`} ${'}'}`} c`);// "a } } c"
I've never found a case where perl's "scan for the end and reparse" approach is actually useful.
Oh I don't think anyone ever suggested it was useful. It's relatively simple and cheap to implement which may be why it's done that way currently. I only suggest it as an option for consistency with existing quoting.
First interesting question: Should
qt()
strings be sub-lexed, or not..?I.e. what do people feel -should- be the behaviour of a construction like
Should it:
I feel that interpretation 2 might be most useful and powerful, but would be inconsistent with existing behaviour of existing operators. Interpretation 1 is certainly easier to achieve as it reüses existing parser structures, but given the whole point is to interpolate code inside the
{braces}
it might lead to weird annoying cases that don't work so well.Does anyone have any good examples one way or other from other languages that have a similar construction?
(Cross-posted to https://www.nntp.perl.org/group/perl.perl5.porters/2024/01/msg267671.html)
The text was updated successfully, but these errors were encountered: