Properly supporting locales, even in a small way, would be a good thing to
add.

Factor is currently locale-independent, partly because of a desire for
homoiconicity, and partly because it prevents things like tests that break
depending on the system locale[1].

We have discussed adding a locale vocabulary or a with-locale combinator
that can influence presentation of numbers and strings, maybe looking at
how other languages work[2].  Probably we'd want to keep the math.parser
locale independent, but provide ways for things like present / printf to be
locale-aware.

If this is an issue for something you are building, you could use alien.ffi
to call sprintf or use C++ stringstream or something and call the library
from Factor, or do something slow like this, calling out to Python:

: format-with-locale ( n locale -- s )
    swap [
        "python" , "-c" ,
        "import locale; locale.setlocale(locale.LC_ALL, \"%s\");
print(locale.format(\"%%f\", %s))" sprintf ,
    ] { } make B utf8 [ readln ] with-process-reader ;

IN: scratchpad 1.5 "fr_FR" format-with-locale .
1,500000

---
[1] https://github.com/slavapestov/factor/issues/905
[2] https://docs.python.org/3/library/locale.html



On Tue, Aug 11, 2015 at 3:47 AM, Georg Simon <[email protected]> wrote:

> Am Tue, 11 Aug 2015 12:29:32 +0200
> schrieb Jon Harper <[email protected]>:
>
> Yes, LC_NUMERIC=C gives "1.5" too.
> So number>string is not what I need.
> Are there already any words to convert numbers to locale _dependant_
> strings ?
>
> > Sorry, it's LC_NUMERIC, not LC_CTYPE.
> >
> > Also, the objective is really to always have "1.5" in the listener
> > because we want an homoiconic language, so the listener ouptut
> > numbers in source code format which is locale independant.
> > Le 11 août 2015 10:12 AM, "Georg Simon" <[email protected]> a
> > écrit :
> >
> > > Thank you.
> > >
> > > LC_CTYPE=C does not help.
> > > LC_ALL=C gives "1.5" instead of "1,5"
> > > My system is Ubuntu 14.04.2 LTS .
> > >
> > > But I can just wait for the fix.
> > >
> > > Georg
> > >
> > > Am Tue, 11 Aug 2015 09:37:31 +0200
> > > schrieb Jon Harper <[email protected]>:
> > >
> > > > This is being fixed. Meanwhile, you can adjust your locale
> > > > settings to workaround:
> > > > LC_CTYPE=C ./factor
> > > > Should work. If not, you can try LC_ALL=C
> > > > Jon
> > > > Le 11 août 2015 9:30 AM, "Georg Simon" <[email protected]> a
> > > > écrit :
> > > >
> > > > > IN: scratchpad 1.5 number>string .
> > > > > "1,5.0"
> > > > >
> > > > > I would have expected "1,5"
> > > > >
> > > > >
> > > > >
> > >
> ------------------------------------------------------------------------------
> > > > >
> > > > > _______________________________________________
> > > > > Factor-talk mailing list
> > > > > [email protected]
> > > > > https://lists.sourceforge.net/lists/listinfo/factor-talk
> > > > >
> > > > >
> > >
> > >
> > >
> > >
> ------------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > Factor-talk mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/factor-talk
> > >
> > >
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to