Re: [Factor-talk] Prettyprinting Numbers
Well, it looks like we have this more or less exact word in ``tools.memory:commas``, and something very close in ``money:format-money``. On Fri, Jun 16, 2017 at 4:38 PM, Alexander Ilinwrote: > Hello! > > Wow, this is way more general than what I came up with: > > ``` > : num>grouped-str ( n -- str ) > number>string 3 "," join reverse ; > ``` > > Maybe your code should be included in the prettyprinter or somewhere > similar, next to `number>string`, perhaps? > > 17.06.2017, 02:33, "John Benediktsson" : > > Note: that word doesn't work properly for negative numbers. This is > better: > > : number>string-with-commas ( str -- str' ) > [ > abs number>string "." split1 > [ reverse 3 "," join reverse ] dip > [ "." glue ] when* > ] [ neg? [ "-" prepend ] when ] bi ; > > > > On Fri, Jun 16, 2017 at 4:29 PM, John Benediktsson > wrote: > > We don't have that kind of locale support right now, but you could use > something like: > > : number>string-with-commas ( str -- str' ) > number>string "." split1 > [ reverse 3 "," join reverse ] dip > [ "." glue ] when* ; > > > > On Fri, Jun 16, 2017 at 4:18 PM, Alexander Ilin wrote: > > Hello! > > Is there a standard way to output a number with comma separators > grouping the thousands? > > ``` > 1,000,000 num>str-grouped > > "1,000,000" > ``` > > ---=--- > Александр > > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > , > > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > , > > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > > > ---=--- > Александр > > > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Prettyprinting Numbers
You see? It could use some limelight! : ) Also, thanks for pointing out the `tools.memory` vocab. Not only will it provide some insight for me as to the memory use pattern for my DB-heavy apps, but also it uses some juicy words like `object-table.` Too bad those aren't documented, I might have discovered them sooner. By coincidence, I'm developing some UI right now that could use exactly that kind of thing (presenting multiple slots of a tuple). 17.06.2017, 02:47, "John Benediktsson":Well, it looks like we have this more or less exact word in ``tools.memory:commas``, and something very close in ``money:format-money``. On Fri, Jun 16, 2017 at 4:38 PM, Alexander Ilin wrote:Hello! Wow, this is way more general than what I came up with: ```: num>grouped-str ( n -- str ) number>string 3 "," join reverse ;``` Maybe your code should be included in the prettyprinter or somewhere similar, next to `number>string`, perhaps? 17.06.2017, 02:33, "John Benediktsson" :Note: that word doesn't work properly for negative numbers. This is better: : number>string-with-commas ( str -- str' ) [ abs number>string "." split1 [ reverse 3 "," join reverse ] dip [ "." glue ] when* ] [ neg? [ "-" prepend ] when ] bi ; On Fri, Jun 16, 2017 at 4:29 PM, John Benediktsson wrote:We don't have that kind of locale support right now, but you could use something like: : number>string-with-commas ( str -- str' ) number>string "." split1 [ reverse 3 "," join reverse ] dip [ "." glue ] when* ; On Fri, Jun 16, 2017 at 4:18 PM, Alexander Ilin wrote:Hello! Is there a standard way to output a number with comma separators grouping the thousands?``` 1,000,000 num>str-grouped "1,000,000"```---=--- Александр--Check out the vibrant tech community on one of the world's mostengaging tech sites, Slashdot.org! http://sdm.link/slashdot___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,--Check out the vibrant tech community on one of the world's mostengaging tech sites, Slashdot.org! http://sdm.link/slashdot,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk ---=---Александр --Check out the vibrant tech community on one of the world's mostengaging tech sites, Slashdot.org! http://sdm.link/slashdot___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk ,--Check out the vibrant tech community on one of the world's mostengaging tech sites, Slashdot.org! http://sdm.link/slashdot,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk ---=---Александр -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] How to introduce factor to java programmers?
This is GREAT! I love the topics covered, the step-through approach, and the overall feeling. I bet that was a great presentation. Best, John. On Fri, Jun 16, 2017 at 5:09 PM, Sankaranarayanan Viswanathan < rationalrev...@gmail.com> wrote: > Hello Everyone, > > Thank you for your inputs. In the end, I decided to focus on the aspects > of Factor that I was most amazed by when I first discovered the language > last year. I presented yesterday, and it was received well. I think I > kindled the interest of a few people who attended. > > The slide I went over are here: > https://github.com/viswans83/stack-based-languages-presentation > > Thanks again, > Sankar > > > On 6/1/17 4:05 AM, Alexander Ilin wrote: > >> John, the question was specifically about the quotation parameter's >> stack effects in general, i.e. `quot: ( x -- x )` vs. simply `quot` in >> the parameter lists. >> >> My take is that the quotation stack effects are not checked separately >> on a per-parameter basis, only the word as a whole is checked. So, they >> are merely for documentation purposes, and may be incorrect with no >> penalty. From the documentation: "For words that are not inline, only >> the number of inputs and outputs carries semantic meaning, and effect >> variables are ignored." >> >> http://docs.factorcode.org/content/article-effects.html >> >> 01.06.2017, 05:33, "John Benediktsson": >> >>> Well, technically neither ``dip`` nor ``keep`` need those stack >>> effects, they are inlined which means the non-inline word that >>> includes them will have it's stack effect checked by the compiler for >>> correctness. >>> >>> There are few reasons why we want to have the ".." variadic stack >>> effects, and those are useful in the stack-checker and visually for >>> documentation, but if you removed them and tried to compile a word >>> that was incorrect, it would give you a worse error message but still >>> give you an error. >>> >>> >>> >>> On Wed, May 31, 2017 at 7:03 PM, Sankaranarayanan Viswanathan >>> > wrote: >>> >>> Thanks for the ideas John! >>> >>> I have been looking at the collection of talks, and they've been >>> quite helpful. Your thoughts about discussing "Java like" things >>> makes a lot of sense and I think contrasting Factor's object >>> system with Java's should be a nice topic. >>> >>> That said, I did run into a question preparing the slides related >>> to stack-effects. I noticed that some combinators do not specify >>> stack effects for quotation inputs. >>> >>> e.g. >>> dip ( x quot -- x ) >>> keep ( ..a x quot: ( ..a x -- ..b ) -- ..b x ) >>> >>> Why does `dip` not need to specify the quotations stack effect, >>> but `keep` did? I suspect they also have something to do with the >>> inline word, but I'm not really sure. Could you explain? >>> >>> Thanks, >>> Sankar >>> >>> >>> >>> On 5/30/17 11:47 PM, John Benediktsson wrote: >>> >>> We have a few "talks" that were given a number of years ago >>> (not all >>> code in them is up to date, but it's mostly good -- if you >>> have problems >>> updating the code let me know and I can help): >>> >>> https://github.com/factor/factor/tree/master/extra/talks >>> >>> https://github.com/slavapestov/boston-lisp-talk >>> >>> https://github.com/slavapestov/emerging-langs-talk >>> >>> You might find it interesting to discuss "Java-like" things, for >>> example, interfaces vs protocols: >>> >>> public interface Foo { >>> String a(); >>> int b(); >>> } >>> >>>public class FooImpl { >>> public String a() { return "hello" } ; >>> public int b() { return 42 } ; >>> } >>> >>> vs a protocol (two generic methods) and a concrete class that >>> implements >>> it... >>> >>> GENERIC: a ( obj -- a ) >>> GENERIC: b ( obj -- a ) >>> >>> TUPLE: foo ; >>> M: foo a "hello" ; >>> M: foo b 42 ; >>> >>> Could also talk about ``SINGLETON:``, so instead of (plus or >>> minus >>> thread safety): >>> >>> public class Foo { >>> private static _instance = null; >>> public static Foo getInstance() { >>> if ( _instance == null ) { _instance = new Foo() }; >>> return _instance; >>> } >>> } >>> >>> vs. >>> >>> SINGLETON: foo >>> >>> So, touching on code generation and higher level concepts. >>> >>> Maybe macros might be interesting? >>> >>> Some other ideas from my blog, not sure of your audience's >>> interest: >>> >>> >>> https://re-factor.blogspot.com/2009/08/calculating-with-ebnf >>>
Re: [Factor-talk] How to introduce factor to java programmers?
I totally agree, the presentation is VERY COOL!Great visual style, great accent on the details in small steps, great topics covered, no clutter. The only minor criticism is the use of the word "breath" instead of "width". If it wasn't some intentional joke, I would at least fix the typo in "brea_d_th". I starred and bookmarked the repo. If I need to show off Factor to someone, that'd be a great starting point. Thank you! 17.06.2017, 03:21, "John Benediktsson":This is GREAT! I love the topics covered, the step-through approach, and the overall feeling. I bet that was a great presentation. Best,John. On Fri, Jun 16, 2017 at 5:09 PM, Sankaranarayanan Viswanathan wrote:Hello Everyone,Thank you for your inputs. In the end, I decided to focus on the aspects of Factor that I was most amazed by when I first discovered the language last year. I presented yesterday, and it was received well. I think I kindled the interest of a few people who attended.The slide I went over are here:https://github.com/viswans83/stack-based-languages-presentationThanks again,SankarOn 6/1/17 4:05 AM, Alexander Ilin wrote:John, the question was specifically about the quotation parameter'sstack effects in general, i.e. `quot: ( x -- x )` vs. simply `quot` inthe parameter lists.My take is that the quotation stack effects are not checked separatelyon a per-parameter basis, only the word as a whole is checked. So, theyare merely for documentation purposes, and may be incorrect with nopenalty. From the documentation: "For words that are not inline, onlythe number of inputs and outputs carries semantic meaning, and effectvariables are ignored."http://docs.factorcode.org/content/article-effects.html01.06.2017, 05:33, "John Benediktsson" :Well, technically neither ``dip`` nor ``keep`` need those stackeffects, they are inlined which means the non-inline word thatincludes them will have it's stack effect checked by the compiler forcorrectness.There are few reasons why we want to have the ".." variadic stackeffects, and those are useful in the stack-checker and visually fordocumentation, but if you removed them and tried to compile a wordthat was incorrect, it would give you a worse error message but stillgive you an error.On Wed, May 31, 2017 at 7:03 PM, Sankaranarayanan Viswanathan > wrote: Thanks for the ideas John! I have been looking at the collection of talks, and they've been quite helpful. Your thoughts about discussing "Java like" things makes a lot of sense and I think contrasting Factor's object system with Java's should be a nice topic. That said, I did run into a question preparing the slides related to stack-effects. I noticed that some combinators do not specify stack effects for quotation inputs. e.g. dip ( x quot -- x ) keep ( ..a x quot: ( ..a x -- ..b ) -- ..b x ) Why does `dip` not need to specify the quotations stack effect, but `keep` did? I suspect they also have something to do with the inline word, but I'm not really sure. Could you explain? Thanks, Sankar On 5/30/17 11:47 PM, John Benediktsson wrote: We have a few "talks" that were given a number of years ago (not all code in them is up to date, but it's mostly good -- if you have problems updating the code let me know and I can help): https://github.com/factor/factor/tree/master/extra/talks https://github.com/slavapestov/boston-lisp-talk https://github.com/slavapestov/emerging-langs-talk You might find it interesting to discuss "Java-like" things, for example, interfaces vs protocols: public interface Foo { String a(); int b(); } public class FooImpl { public String a() { return "hello" } ; public int b() { return 42 } ; } vs a protocol (two generic methods) and a concrete class that implements it... GENERIC: a ( obj -- a ) GENERIC: b ( obj -- a ) TUPLE: foo ; M: foo a "hello" ; M: foo b 42 ; Could also talk about ``SINGLETON:``, so instead of (plus or minus thread safety): public class Foo { private static _instance = null; public static Foo getInstance() { if ( _instance == null ) { _instance = new Foo() }; return _instance; } } vs. SINGLETON: foo So, touching on code generation and higher level concepts. Maybe macros might be interesting? Some other ideas from my blog, not sure of your audience's interest: https://re-factor.blogspot.com/2009/08/calculating-with-ebnf.html https://re-factor.blogspot.com/2010/11/estimating-cpu-speed.html
[Factor-talk] Prettyprinting Numbers
Hello! Is there a standard way to output a number with comma separators grouping the thousands? ``` 1,000,000 num>str-grouped "1,000,000" ``` ---=--- Александр -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Prettyprinting Numbers
Note: that word doesn't work properly for negative numbers. This is better: : number>string-with-commas ( str -- str' ) [ abs number>string "." split1 [ reverse 3 "," join reverse ] dip [ "." glue ] when* ] [ neg? [ "-" prepend ] when ] bi ; On Fri, Jun 16, 2017 at 4:29 PM, John Benediktssonwrote: > We don't have that kind of locale support right now, but you could use > something like: > > : number>string-with-commas ( str -- str' ) > number>string "." split1 > [ reverse 3 "," join reverse ] dip > [ "." glue ] when* ; > > > > On Fri, Jun 16, 2017 at 4:18 PM, Alexander Ilin wrote: > >> Hello! >> >> Is there a standard way to output a number with comma separators >> grouping the thousands? >> >> ``` >> 1,000,000 num>str-grouped >> >> "1,000,000" >> ``` >> >> ---=--- >> Александр >> >> >> -- >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> ___ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> > > -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] How to introduce factor to java programmers?
Hello Everyone, Thank you for your inputs. In the end, I decided to focus on the aspects of Factor that I was most amazed by when I first discovered the language last year. I presented yesterday, and it was received well. I think I kindled the interest of a few people who attended. The slide I went over are here: https://github.com/viswans83/stack-based-languages-presentation Thanks again, Sankar On 6/1/17 4:05 AM, Alexander Ilin wrote: John, the question was specifically about the quotation parameter's stack effects in general, i.e. `quot: ( x -- x )` vs. simply `quot` in the parameter lists. My take is that the quotation stack effects are not checked separately on a per-parameter basis, only the word as a whole is checked. So, they are merely for documentation purposes, and may be incorrect with no penalty. From the documentation: "For words that are not inline, only the number of inputs and outputs carries semantic meaning, and effect variables are ignored." http://docs.factorcode.org/content/article-effects.html 01.06.2017, 05:33, "John Benediktsson": Well, technically neither ``dip`` nor ``keep`` need those stack effects, they are inlined which means the non-inline word that includes them will have it's stack effect checked by the compiler for correctness. There are few reasons why we want to have the ".." variadic stack effects, and those are useful in the stack-checker and visually for documentation, but if you removed them and tried to compile a word that was incorrect, it would give you a worse error message but still give you an error. On Wed, May 31, 2017 at 7:03 PM, Sankaranarayanan Viswanathan > wrote: Thanks for the ideas John! I have been looking at the collection of talks, and they've been quite helpful. Your thoughts about discussing "Java like" things makes a lot of sense and I think contrasting Factor's object system with Java's should be a nice topic. That said, I did run into a question preparing the slides related to stack-effects. I noticed that some combinators do not specify stack effects for quotation inputs. e.g. dip ( x quot -- x ) keep ( ..a x quot: ( ..a x -- ..b ) -- ..b x ) Why does `dip` not need to specify the quotations stack effect, but `keep` did? I suspect they also have something to do with the inline word, but I'm not really sure. Could you explain? Thanks, Sankar On 5/30/17 11:47 PM, John Benediktsson wrote: We have a few "talks" that were given a number of years ago (not all code in them is up to date, but it's mostly good -- if you have problems updating the code let me know and I can help): https://github.com/factor/factor/tree/master/extra/talks https://github.com/slavapestov/boston-lisp-talk https://github.com/slavapestov/emerging-langs-talk You might find it interesting to discuss "Java-like" things, for example, interfaces vs protocols: public interface Foo { String a(); int b(); } public class FooImpl { public String a() { return "hello" } ; public int b() { return 42 } ; } vs a protocol (two generic methods) and a concrete class that implements it... GENERIC: a ( obj -- a ) GENERIC: b ( obj -- a ) TUPLE: foo ; M: foo a "hello" ; M: foo b 42 ; Could also talk about ``SINGLETON:``, so instead of (plus or minus thread safety): public class Foo { private static _instance = null; public static Foo getInstance() { if ( _instance == null ) { _instance = new Foo() }; return _instance; } } vs. SINGLETON: foo So, touching on code generation and higher level concepts. Maybe macros might be interesting? Some other ideas from my blog, not sure of your audience's interest: https://re-factor.blogspot.com/2009/08/calculating-with-ebnf.html https://re-factor.blogspot.com/2010/11/estimating-cpu-speed.html https://re-factor.blogspot.com/2011/02/simple-rpg.html https://re-factor.blogspot.com/2011/04/powers-of-2.html https://re-factor.blogspot.com/2011/04/mail-with-gui.html https://re-factor.blogspot.com/2011/07/concatenative-thinking.html https://re-factor.blogspot.com/2011/07/one-liners.html https://re-factor.blogspot.com/2011/08/printf.html https://re-factor.blogspot.com/2012/02/readability.html https://re-factor.blogspot.com/2012/08/literate-programming.html
Re: [Factor-talk] How to introduce factor to java programmers?
Glad you guys liked it. And, I did not notice that typo until you pointed it out - will fix. Thanks, Sankar -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk