Open khwilliamson opened 3 years ago
Would it truly be lexical, or would it be dynamically scoped?
On 1/14/21 12:54 PM, Leon Timmermans wrote:
Would it truly be lexical, or would it be dynamically scoped?
I think it would be best to make it fully lexical
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Perl/perl5/issues/18476#issuecomment-760439582, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2DH77WMLFSKANOKVZZE3SZ5DYRANCNFSM4WB2V6LA.
What about following API?
{
use locale 'en_US';
@sorted = sort @array;
$upper = uc $string;
}
Only code inside of the block would use locale changed to 'en_US'.
And true lexical implementation would be the best. There are POSIX _l
functions for it (e.g. toupper_l()
) and also there is CORE module Unicode::Collate::Locale. But you know.
On 1/17/21 7:32 AM, pali wrote:
What about following API?
{ use locale'en_US'; @sorted =sort @array; $upper =uc $string; }
I would want to make it easy for someone to specify the locale at runtime.
Perhaps something like use locale 'lexset'; setlocale(LC_ALL, $ARGV[1]); @sorted = sort @array; $upper = uc $string;
Only code inside of the block would use locale changed to 'en_US'.
And true lexical implementation would be the best. There are POSIX |_l| functions for it (e.g. |toupper_l()|) and also there is CORE module Unicode::Collate::Locale https://metacpan.org/pod/Unicode::Collate::Locale. But you know.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Perl/perl5/issues/18476#issuecomment-761821789, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2DH7OKFI2YBEZWKXORD3S2LYGZANCNFSM4WB2V6LA.
Perhaps something like
use locale 'lexset'; setlocale(LC_ALL, $ARGV[1]); @sorted = sort @array; $upper = uc $string;
This has problems with begin blocks. use locale 'lexset';
is same as:
BEGIN { require locale; locale->import('lexset') }
.
So there is problem how would be following code handled?
use locale 'lexset';
setlocale(LC_ALL, $ARGV[1]);
BEGIN { @sorted = sort @array };
According to which rules would be @array
sorted? At the time of calling sort
function, lexset
is already set, but $ARGV[1]
was not initialized yet. I think this would lead to another issues of understanding how and when to call or set functions...
With use locale 'en_US';
solution there is not such issue.
@pali has requested a lexically scoped setlocale() that would be in effect only for the scope in which it occurs.
This sounds useful to me, and not that hard to implement.
What do you think, and what should the API be?