Re: [Factor-talk] EOL

2017-02-15 Thread Björn Lindqvist
IMHO, it is better to have newline always be \n. On Windows, the
situation is messy because when you are dealing with Unix files you
want \n but when dealing with DOS files you want \r\n. I think what we
are doing now which is accepting both \n and \r\n when reading and
only emitting \n when writing is fine. Most Windows programs worth
their salt works with either newline sequence.

2017-02-07 18:55 GMT+01:00 John Benediktsson :
> if you want to make a patch and see how it looks, sure we can talk about it!
>
> On Tue, Feb 7, 2017 at 9:53 AM, Alexander Ilin  wrote:
>>
>> I'm all for using \n, but being on Windows, I sometimes need to explicitly
>> produce native text files. In my today's use case I have coded some VS 2005
>> solution file transformations in Factor, after which Git showed the entire
>> file as changed due to EOL conversion that implicitly took place in
>> `change-file-lines`. Explicit setting would satisfy me, although, now that
>> I'm thinking about it, the `change-file-lines` could have preserved the line
>> endings it found in the file, because it has read it in the first place. But
>> that's a pretty high-level feature to ask, which can't happen until a
>> lower-level mechanism is in place.
>>
>> 07.02.2017, 20:29, "John Benediktsson" :
>>
>> maybe, there are some historical differences that make newlines funny
>> business
>>
>> https://blog.codinghorror.com/the-great-newline-schism/
>>
>> I'd love to just use '\n' everywhere.
>>
>>
>> On Tue, Feb 7, 2017 at 9:24 AM, Alexander Ilin  wrote:
>>
>> Helllo, John!
>>
>> Suggestion taken, thank you!
>>
>> Why isn't there a symbol like `eol`, so it would be possible to do
>> something like
>>
>> ```
>> [ "\r\n" eol [ ... ] with-variable ] with-file-writer
>> ```
>>
>> Or even like
>>
>> ```
>> [ crlf [ ... ] with-eol ] with-file-writer
>> ```
>>
>>   Interested in a PR?
>>
>> 07.02.2017, 16:40, "John Benediktsson" :
>> > You could add the line endings yourself:
>> >
>> > "\r\n" join set-file-contents
>> >
>> > or if you are memory constrained, write them:
>> >
>> > [ [ write "\r\n" write ] each ] with-file-writer
>> >
>> >>  On Feb 7, 2017, at 4:15 AM, Alexander Ilin  wrote:
>> >>
>> >>  Hello!
>> >>
>> >>   Is there a way to use `change-file-lines`, but override EOL to be
>> >> CR+LF in the output?
>> >>   If not, what's the alternative solution?
>> >>
>> >>  ---=---
>> >>  Александр
>> >>
>> >>
>> >> --
>> >>  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
>>
>>
>>
>> ---=---
>> Александр
>>
>>
>>
>> --
>> 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
> 

Re: [Factor-talk] Startup time

2017-02-15 Thread Björn Lindqvist
It's like this. You are asking the restaurant to serve you a $1
hamburger and are getting annoyed because the chef is preparing a five
course dinner. :) It is fair to want a $1 hamburger quickly, but a
restaurant not specialized in serving them might not be able to make
one that fast.

In this case, Factor starts a whole integrated development
environment, complete with a compiler and gui, but you are just
interested in running a small script. One solution is running Factor
as a server. It's not bad, I do it all the time and IPC between Emacs
and Factor works really smooth. It could work just as well between
Factor and Bash. But if you aren't willing to accept that solution
then it is hard to solve your problem because Factor's startup time is
IO bound. E.g take a look at:

#include 
#include 

int main(int argc, char *argv[]) {
FILE *f = fopen("/home/bjourne/pubwork/factor-orig/factor.image", "rb");
fseek(f, 0L, SEEK_END);
long size = ftell(f);
fseek(f, 0L, SEEK_SET);
char *heap = malloc(size * 3);
fread(heap, size, 1, f);
long chk = 0;
for (long n = 0; n < size; n += 200) {
chk += heap[n];
}
printf("%ld\n", chk);
free(heap);
fclose(f);
return 0;
}

On my computer, with the factor.image file hot, running this example
takes 140 ms and ./factor -e='' 240 ms. So as you can see, reaching
Bash's startup time isn't realistic. Even an image 1/10th the size of
the standard one (118 mb) would take roughly 24 ms to load which is
still much slower than Bash.

Afaik, almost no language runtime can compile and interpret source
files nearly as fast as Bash.

2017-02-02 10:09 GMT+01:00  :
> No need to apologize, as far as I'm concerned we're just discussing :)
> Now I hope I didn't sound too rude. I'm just trying to get on the same
> page with everyone. The provided solutions are in the line of "if the
> initialization is taking longer than you'd like, here's a way how to
> initialize only once". My focus is somewhere else though - why is the
> initialization taking so long? John is saying there's room for
> improvement, room to do less.
>
> --


-- 
mvh/best regards Björn Lindqvist

--
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


[Factor-talk] Just a test

2017-02-15 Thread fede s
Sorry to pollute the list, this is just a test mail, because I got a 
notification from the list about disabling my account.
>Your membership in the mailing list Factor-talk has been disabled due
>to excessive bounces The last bounce received from you was dated
>01-Feb-2017.  You will not get any more messages from this list until
>you re-enable your membership.  You will receive 1 more reminders like
>this before your membership in the list is deleted.
Not sure what that was about :/
--
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] Macros needed?

2017-02-15 Thread Björn Lindqvist
I think the key is to use the nth word instead of first and second.
Then do it like this:

  { "a" 2 3 } { "b" 5 6 } 2 random 0 = 0 1 ? rot over [ swap nth ] 2bi@

In your code it would be:

  dim chart chart-axes vert? 0 1 ? rot over [ swap nth ] 2bi@

Or

  dim chart chart-axes vert? 0 1 ? [ swap nth ] keep rot nth

Or even:

  dim chart chart-axes vert? 0 1 ? '[ _ swap nth ] bi@


2017-02-04 2:31 GMT+01:00 Alexander Ilin :
> That's great!
>
>   I did this:
>
> : ?[x/y] ( ? -- quot )
> [ x ] [ y ] ? [ call( a -- b ) ] curry ; inline
>
> ...
> dim chart chart-axes vert? ?[x/y] bi@
>
> 04.02.2017, 04:29, "John Benediktsson" :
>> Well I'm not sure about the compiler effect declaration, but you could do 
>> this:
>>
>> vert? [ x ] [ y ] ? [ call( a -- b ) ] curry
>>
>>>  On Feb 3, 2017, at 5:04 PM, Alexander Ilin  wrote:
>>>
>>>  vert? [ x ] [ y ] ? check-effect( a -- b )
>>
>> --
>> 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



-- 
mvh/best regards Björn Lindqvist

--
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] Threaded Code?

2017-02-15 Thread Björn Lindqvist
Yes, you are right! But the Wikipedia article talks about many
different techniques. It talks about storing subroutine addresses into
arrays and having the system execute code by calling each of those
addresses in turn, like a byte-code interpreter. That's not what
Factor does because indirectly calling addresses in arrays is bad for
performance.

The method Factor uses is to generate one CALL instruction for each
word in the quotation being compiled. It's a really trivial technique.
A quotation like [ word-a word-b + ] would become roughly:

(word-prologue)
CALL address-of(word-a)
CALL address-of(word-b)
(word-epilogue)
JMP address-of(+)

2017-02-01 3:13 GMT+01:00 Levi Pearson :
> https://concatenative.org/wiki/view/Factor/Non-optimizing%20compiler
>
> Apparently the JIT for the interactive non-optimizing compiler generates
> subroutine threaded code with some inlining.
>
> I wouldn't call it a compiler optimization; maybe an interpreter
> optimization or a simple compiling technique. I think you hear about it a
> lot with respect to Forth and its family because of the proportion of Forth
> users who implemented the language or at least learned how it was
> implemented, although often modern Forth implementations have optimizing
> compilers. But the earliest academic reference I've seen for threaded code
> was in reference to a Fortran compiler for the PDP-11:
> http://home.claranet.nl/users/mhx/Forth_Bell.pdf
>
> I'm pretty sure that 1971 article was more of a description of a technique
> already widely in practice (i.e. a description of "folklore") rather than a
> new invention, so it's definitely been around a whlie.
>
> I wrote a simple threaded code interpreter in C as an exercise to understand
> them better a while back; including some conditionally-compiled debug code
> and a fairly small complement of core Forth words and an outer interpreter
> loop, it's still well under 1k lines of source.
>
> --Levi
>
> On Tue, Jan 31, 2017 at 3:23 PM, Björn Lindqvist  wrote:
>>
>> Probably not! I've never heard of that technique. From skimming that
>> Wikipedia article it seem to be a compiler optimization invented a
>> long time ago. We have an instruction called ##dispatch, used for
>> method dispatching, but it is not nearly as dynamic as the method
>> described. Probably for the best because on modern processors jumping
>> to addresses kept in memory or in registers is very bad for
>> performance.
>>
>>
>> 2017-01-31 21:11 GMT+01:00 Alexander Ilin :
>> > Hello!
>> >
>> >   Does Factor use threaded code in any way?
>> >   https://en.wikipedia.org/wiki/Threaded_code
>> >
>
>
> --
> 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
>



-- 
mvh/best regards Björn Lindqvist

--
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] Startup time

2017-02-15 Thread petern
On 2017-02-10 01:44, John Benediktsson wrote:
> Right, probably 80-85% of the startup time is in the C++ method
> factor_vm::load_image.
> 
> Breaking it down further:
> 
> - 32% of the startup time is factor_vm::load_data_heap
> - 15% of the startup time is factor_vm::load_code_heap
> - 32% of the startup time is factor_vm::fixup_heaps
> 
> It's on the list to dig into but if you'd like, you could look there 
> and
> see if there are improvements to be made.
> 
> Best,
> John.
> 
> 
> 
> 
> On Sun, Feb 5, 2017 at 7:19 AM,  wrote:
> 
>> On 2017-02-02 09:59, pet...@riseup.net wrote:
>> > On 2017-02-01 22:39, John Benediktsson wrote:
>> >> Feel free to jump in a profile startup and make some patches to
>> >> improve
>> >> things.
>> >>
>> >> Most languages seem to be under 50 milliseconds for the "startup and
>> >> run no
>> >> code" test case, so I would guess that should be fairly achievable.
>> >>
>> >> Best,
>> >> John.
>> >>
>> >> On Wed, Feb 1, 2017 at 2:10 PM,  wrote:
>> >>
>> >>> On 2017-02-01 19:40, Jim Mack wrote:
>> >>> > So why not create a separate small process that passes on its
>> >>> > parameters to
>> >>> > a running factor if it can find it, or starts a new one if it can't?
>> >>> >
>> >>>
>> >>> That's like running a server and sending requests to it. I take
>> >>> several
>> >>> issues with that:
>> >>>
>> >>> 1 - I need one instance to have *all* my libraries, present and
>> >>> future
>> >>> to be pre-loaded. But more importantly:
>> >>> 2 - a typical shell script can call a dozen external executables.
>> >>> Some
>> >>> will be in C, some in bash, some in python, some in perl etc. If
>> >>> every
>> >>> language would need a huge server to run, where would that leave us?
>> >>>
>> >>> > On Wed, Feb 1, 2017 at 7:51 AM, Timothy Hobbs 
>> wrote:
>> >>> >
>> >>> >> Have you tried loading the
>> >>> >> factor interpreter in the background and seeing if factor launches
>> >>> >> quicker while another factor process is running?
>> >>>
>> >>> I did what I think is fair - started it once so everything necessary
>> >>> gets cached in RAM and discard that run. As noted above I don't think
>> >>> running a server for each possible language is a good solution.
>> >>>
>> >>>
>> >>> Feel free to contradict me gentlemen, I'm open to discussion, but I
>> >>> do
>> >>> have my own opinion of what is acceptable and transferable to other
>> >>> PCs
>> >>> / colleagues. I'm not looking for some local hack to speed things up
>> >>> but
>> >>> a general solution that doesn't put any more burden on the end users
>> >>> than it is necessary.
>> >>>
>> >>> --
>> >>> 
>> >>>Peter Nagy
>> >>> 
>> >>>
>> >>> 
>> >>> --
>> >>> 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
>> >
>> > I'd gladly take a look. Could you give me a hint how could I get
>> > profiling statistics of the boot? I guess most of the startup time is
>> > spent in factor code so I'd need to jack in a call to profile
>> > somewhere and rebuild?
>> 
>> I did a quick check with sysdig on the time of system calls - it shows
>> the base image takes ~50ms to load from my 180ms startup time (which
>> isn't too bad for 115MB file I guess). No other interesting syscalls, 
>> so
>> I guess the leftover 130ms are spent in factor. I'll try to take a 
>> look
>> how could I get profiling statistics on the startup of the listener.
>> 
>> --
>> 
>>Peter Nagy
>> 
>> 
>> 
>> --
>> 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
>