Re: [Factor-talk] Saving an image file with extra vocabularies loaded

2020-11-29 Thread Alexander Ilin
Is it possible to merge the range and interval concepts into one thing? Not sure if a good idea, but would resolve the confusion. https://math.stackexchange.com/questions/2056510/what-is-the-mathematical-symbol-for-range It seems that for integer values there is also the notation of {a..b}, which includes both ends.Maybe we could also add {a..b-1} to exclude the last value, and add the commonly used {0..b-1}, although there is already the shorter  for the latter. 29.11.2020, 18:12, "John Benediktsson" :The common ambiguity between math.ranges and math.intervals has also bothered us.  I did like the syntax aside from that issue that, but we are experimenting with new range syntax: [a..b](a..b](a..b)[a..b) What do you think of that instead? Some other variants discussed from other languages: a..ba...ba..a..=b What does everyone think? Any feedback? Best,John.  On Nov 29, 2020, at 5:56 AM, Alexander Ilin <ajs...@yandex.ru> wrote: Here's the full code for .factor-rc: USING: listener namespaces sequences ;! Add math.ranges to the Scratchpad vocab of the Listener.interactive-vocabs [ "math.ranges" suffix ] change-global  29.11.2020, 16:50, "Alexander Ilin" <ajs...@yandex.ru>:See the SYMBOL: interactive-vocabs in the basis\listener.factor. 29.11.2020, 15:25, "Alexander Ilin" <ajs...@yandex.ru>:I think you need to somehow edit the vocabs preloaded into the Scratchpad vocab of the Listener. 29.11.2020, 12:07, "kevin" <kevinpat...@gmail.com>:Hello fellow Factor users. Today, I finally became fed up with having to load the math.ranges vocabulary in the listener every time I want to use a word like [a,b]. Especially since it needs to disambiguate with math.intervals and I have to stop and think about which one to pick. I was under the impression that simply going USE: math.ranges    save Would save to the default image with math.ranges loaded, but when I exit and start the listener up again, the change does not take. I then figured that maybe I could save a custom image with "myimage.image" save-image and indeed, it does save a file named myimage.image in the factor directory. Then when I try to invoke factor like factor -i=myimage.image  it complains about not being able to locate the file. I then figured I wouldn't mind waiting for vocabs to load and maybe I could just try loading them in my .factor-rc or .factor-boot-rc, but that doesn't work either. Any ideas on how I can get this to work? Thanks!,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Saving an image file with extra vocabularies loaded

2020-11-29 Thread Alexander Ilin
Here's the full code for .factor-rc: USING: listener namespaces sequences ;! Add math.ranges to the Scratchpad vocab of the Listener.interactive-vocabs [ "math.ranges" suffix ] change-global  29.11.2020, 16:50, "Alexander Ilin" :See the SYMBOL: interactive-vocabs in the basis\listener.factor. 29.11.2020, 15:25, "Alexander Ilin" <ajs...@yandex.ru>:I think you need to somehow edit the vocabs preloaded into the Scratchpad vocab of the Listener. 29.11.2020, 12:07, "kevin" <kevinpat...@gmail.com>:Hello fellow Factor users. Today, I finally became fed up with having to load the math.ranges vocabulary in the listener every time I want to use a word like [a,b]. Especially since it needs to disambiguate with math.intervals and I have to stop and think about which one to pick. I was under the impression that simply going USE: math.ranges    save Would save to the default image with math.ranges loaded, but when I exit and start the listener up again, the change does not take. I then figured that maybe I could save a custom image with "myimage.image" save-image and indeed, it does save a file named myimage.image in the factor directory. Then when I try to invoke factor like factor -i=myimage.image  it complains about not being able to locate the file. I then figured I wouldn't mind waiting for vocabs to load and maybe I could just try loading them in my .factor-rc or .factor-boot-rc, but that doesn't work either. Any ideas on how I can get this to work? Thanks!,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Saving an image file with extra vocabularies loaded

2020-11-29 Thread Alexander Ilin
See the SYMBOL: interactive-vocabs in the basis\listener.factor. 29.11.2020, 15:25, "Alexander Ilin" :I think you need to somehow edit the vocabs preloaded into the Scratchpad vocab of the Listener. 29.11.2020, 12:07, "kevin" <kevinpat...@gmail.com>:Hello fellow Factor users. Today, I finally became fed up with having to load the math.ranges vocabulary in the listener every time I want to use a word like [a,b]. Especially since it needs to disambiguate with math.intervals and I have to stop and think about which one to pick. I was under the impression that simply going USE: math.ranges    save Would save to the default image with math.ranges loaded, but when I exit and start the listener up again, the change does not take. I then figured that maybe I could save a custom image with "myimage.image" save-image and indeed, it does save a file named myimage.image in the factor directory. Then when I try to invoke factor like factor -i=myimage.image  it complains about not being able to locate the file. I then figured I wouldn't mind waiting for vocabs to load and maybe I could just try loading them in my .factor-rc or .factor-boot-rc, but that doesn't work either. Any ideas on how I can get this to work? Thanks!,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Saving an image file with extra vocabularies loaded

2020-11-29 Thread Alexander Ilin
I think you need to somehow edit the vocabs preloaded into the Scratchpad vocab of the Listener. 29.11.2020, 12:07, "kevin" :Hello fellow Factor users. Today, I finally became fed up with having to load the math.ranges vocabulary in the listener every time I want to use a word like [a,b]. Especially since it needs to disambiguate with math.intervals and I have to stop and think about which one to pick. I was under the impression that simply going USE: math.ranges    save Would save to the default image with math.ranges loaded, but when I exit and start the listener up again, the change does not take. I then figured that maybe I could save a custom image with "myimage.image" save-image and indeed, it does save a file named myimage.image in the factor directory. Then when I try to invoke factor like factor -i=myimage.image  it complains about not being able to locate the file. I then figured I wouldn't mind waiting for vocabs to load and maybe I could just try loading them in my .factor-rc or .factor-boot-rc, but that doesn't work either. Any ideas on how I can get this to work? Thanks!,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Peg Parser Definition

2020-11-22 Thread Alexander Ilin
Thanks for the [=[ suggestion, it works just as well! 22.11.2020, 19:17, "John Benediktsson" :Yes, here's how (currently depending on the implementation behavior, but this has worked for a long time). For example, in the urls.private vocabulary there's a parser for URLs, and you can get the peg parser from an EBNF: word. \ parse-url "ebnf-parser" word-prop main of Most of our EBNF: words have been converted to use multiline strings, which avoid the escaping issue if you want to do the same: EBNF-PARSER: word [=[ ... EBNF string ... ]=] I've gone back and forth with triple-quote strings.  They exist in some languages, but they also make parsing single quote strings a bit more difficult.  We removed them while working on some new parser techniques, and the multilline vocabulary has a few other options like the example above.  If people think we really should have them, we could revisit it. Best,John.  On Sun, Nov 22, 2020 at 1:44 AM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  I'd like to use the peg.search vocab, and for that I need to pass it a parser.  Most of the parsing words in peg.ebnf produce either a quotation that is immediately called inline (EBNF[[), or produce a word that calls a parser hidden inside it (EBNF:).  There are only two ways to pass a parser to peg.search:search: construct it from words without using the EBNF syntax, or by using the undocumented EBNF-PARSER: word.  I managed to figure out how the EBNF-PARSER: works, and the unfortunate thing about it is that the syntax is the following:EBNF-PARSER: word "...EBNF string..."  The word will be what we need: ( -- parser ).  The unfortunate part is that it's very annoying having to escape all the double quotes in the "EBNF string".  So, now I have two questions.  1. Is it possible to convert a word defined with EBNF: into a word returning a parser, or to somehow extract the parser from inside it? Is there maybe an undocumented word that could help with that, like by making a wrapper?  2. Is it possible to return the """ (triple double quoted) string syntax, which doesn't require escaping single double quotes inside them?---=--- Александр___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Peg Parser Performance

2020-11-22 Thread Alexander Ilin
If I remove all => actions, the time goes down to 120 seconds.  23.11.2020, 00:18, "John Benediktsson" :I suspect it’s a lot of “swap prefix >string” type stuff that’s different, but I can help you profile this a little later today or tomorrow.   On Nov 22, 2020, at 1:07 PM, Alexander Ilin <ajs...@yandex.ru> wrote: Hello!  I put the code into a vocab, restarted the Listener and repeated the test like so: IN: log-db EBNF: parse-csv-line [=[   quotedColumn = "\""~ (!("\"") .)* "\""~ quotedColumn*       => [[ first2 swap prefix [ >string ] map "\"" join ]]   unquotedColumn = (!("\t") .)*   column = ( quotedColumn | unquotedColumn ) => [[ >string ]]   rule = column ( "\t"~ column )* => [[ first2 swap prefix ]]]=]: parse ( file -- ast )   [ utf8 [       input-stream get [ parse-csv-line , ] each-stream-line   ] with-file-reader ] { } make ;   In Listener: USE: log-db now "file-name.csv" parse now rot time- The resulting run time is 180 seconds, which is fewer than 200, but not that much closer to 2.Somehow the optimizations don't seem to be helping a lot here. 22.11.2020, 22:51, "John Benediktsson" <mrj...@gmail.com>:When you run that in the listener it uses the non optimizing compiler.You should use the EBNF: word [=[ ... ]=] form and then refer to word for it to be a compiled parser.It’ll be much faster.Or wrap all that in a : foo ( — ) ... ;  On Nov 22, 2020, at 11:49 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Hello!   I've got my first test results, and I'm having some doubts.   The following code runs almost 200 seconds on a 20Mb file:  "file-name.csv" [ utf8 [ input-stream get[EBNF[=[  quotedColumn = "\""~ (!("\"") .)* "\""~ quotedColumn*=> [[ first2 swap prefix [ >string ] map "\"" join ]]  unquotedColumn = (!("\t") .)*  column = ( quotedColumn | unquotedColumn ) => [[ >string ]]  rule = column ( "\t"~ column )* => [[ first2 swap prefix ]]]=] ,] each-stream-line ] with-file-reader ] { } makeThe following equivalent code using the csv vocab runs about 2 seconds on the same file:  "file-name.csv" [ utf8 [ input-stream get CHAR: \t [[ string>csv [ first , ] unless-empty ] each-stream-line ] with-delimiter ] with-file-reader ] { } makeThe difference is 100x, and the question is: is the speed difference related to the fact that I'm running the code in the Listener? Could it be that if I put it all into a vocab as opposed to running interactively it would get better optimized and reach the performance of the csv vocab?  ---=--- Александр___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Peg Parser Performance

2020-11-22 Thread Alexander Ilin
Hello!  I put the code into a vocab, restarted the Listener and repeated the test like so: IN: log-db EBNF: parse-csv-line [=[   quotedColumn = "\""~ (!("\"") .)* "\""~ quotedColumn*       => [[ first2 swap prefix [ >string ] map "\"" join ]]   unquotedColumn = (!("\t") .)*   column = ( quotedColumn | unquotedColumn ) => [[ >string ]]   rule = column ( "\t"~ column )* => [[ first2 swap prefix ]]]=]: parse ( file -- ast )   [ utf8 [       input-stream get [ parse-csv-line , ] each-stream-line   ] with-file-reader ] { } make ;   In Listener: USE: log-db now "file-name.csv" parse now rot time- The resulting run time is 180 seconds, which is fewer than 200, but not that much closer to 2.Somehow the optimizations don't seem to be helping a lot here. 22.11.2020, 22:51, "John Benediktsson" :When you run that in the listener it uses the non optimizing compiler.You should use the EBNF: word [=[ ... ]=] form and then refer to word for it to be a compiled parser.It’ll be much faster.Or wrap all that in a : foo ( — ) ... ;  On Nov 22, 2020, at 11:49 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Hello!   I've got my first test results, and I'm having some doubts.   The following code runs almost 200 seconds on a 20Mb file:  "file-name.csv" [ utf8 [ input-stream get[EBNF[=[  quotedColumn = "\""~ (!("\"") .)* "\""~ quotedColumn*=> [[ first2 swap prefix [ >string ] map "\"" join ]]  unquotedColumn = (!("\t") .)*  column = ( quotedColumn | unquotedColumn ) => [[ >string ]]  rule = column ( "\t"~ column )* => [[ first2 swap prefix ]]]=] ,] each-stream-line ] with-file-reader ] { } makeThe following equivalent code using the csv vocab runs about 2 seconds on the same file:  "file-name.csv" [ utf8 [ input-stream get CHAR: \t [[ string>csv [ first , ] unless-empty ] each-stream-line ] with-delimiter ] with-file-reader ] { } makeThe difference is 100x, and the question is: is the speed difference related to the fact that I'm running the code in the Listener? Could it be that if I put it all into a vocab as opposed to running interactively it would get better optimized and reach the performance of the csv vocab?  ---=--- Александр___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Peg Parser Performance

2020-11-22 Thread Alexander Ilin
Hello!

  I've got my first test results, and I'm having some doubts.

  The following code runs almost 200 seconds on a 20Mb file:

"file-name.csv" [ utf8 [ input-stream get
[
EBNF[=[
  quotedColumn = "\""~ (!("\"") .)* "\""~ quotedColumn*
=> [[ first2 swap prefix [ >string ] map "\"" join ]]
  unquotedColumn = (!("\t") .)*
  column = ( quotedColumn | unquotedColumn ) => [[ >string ]]
  rule = column ( "\t"~ column )* => [[ first2 swap prefix ]]
]=] ,
] each-stream-line
] with-file-reader ] { } make


  The following equivalent code using the csv vocab runs about 2 seconds on the 
same file:

"file-name.csv" [ utf8 [ input-stream get CHAR: \t [
[ string>csv [ first , ] unless-empty ] each-stream-line
] with-delimiter ] with-file-reader ] { } make


  The difference is 100x, and the question is: is the speed difference related 
to the fact that I'm running the code in the Listener? Could it be that if I 
put it all into a vocab as opposed to running interactively it would get better 
optimized and reach the performance of the csv vocab?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Peg Parser Definition

2020-11-21 Thread Alexander Ilin
Hello!

  I'd like to use the peg.search vocab, and for that I need to pass it a parser.
  Most of the parsing words in peg.ebnf produce either a quotation that is 
immediately called inline (EBNF[[), or produce a word that calls a parser 
hidden inside it (EBNF:).
  There are only two ways to pass a parser to peg.search:search: construct it 
from words without using the EBNF syntax, or by using the undocumented 
EBNF-PARSER: word.

  I managed to figure out how the EBNF-PARSER: works, and the unfortunate thing 
about it is that the syntax is the following:

EBNF-PARSER: word "...EBNF string..."

  The word will be what we need: ( -- parser ).
  The unfortunate part is that it's very annoying having to escape all the 
double quotes in the "EBNF string".

  So, now I have two questions.
  1. Is it possible to convert a word defined with EBNF: into a word returning 
a parser, or to somehow extract the parser from inside it? Is there maybe an 
undocumented word that could help with that, like by making a wrapper?
  2. Is it possible to return the """ (triple double quoted) string syntax, 
which doesn't require escaping single double quotes inside them?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Peg Parsing Files

2020-11-21 Thread Alexander Ilin
I have another question to follow this up. I want to create a multilayer parser.The first layer would read a bunch of textual log files (with date-time in their names) and search for various types of events using PEG patterns per line and skipping noise. This would produce a stream of interesting events.The next layer of parsing will process this stream searching for higher level patterns that can be folded into, say, meta-events comprised of a tree of sub-events detected on the first parsing level. This layer will produce an AST that can be queried by the user to find out details about various aspects of what actually happened.So, the question is, is it possible to use the peg vocab to create this layered parsing architecture, where the first layer would consume a stream of file input, and the second would consume a stream of tokens from the first layer? 21.11.2020, 02:17, "Alexander Ilin" :Hello!  I see that the peg vocab operates on strings. Can it operate on streams?  I want to parse some log files, and thought it would make sense not to load them all at once.  Especially since I want to stream multiple files concatenated as one.---=--- Александр___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Packrat Homepage

2020-11-20 Thread Alexander Ilin
Hello!

Chris Double, why don't you announce the Factor implementation to the creator 
of packrat here?  
https://bford.info/packrat

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Peg Parsing Files

2020-11-20 Thread Alexander Ilin
Hello!

  I see that the peg vocab operates on strings. Can it operate on streams?
  I want to parse some log files, and thought it would make sense not to load 
them all at once.
  Especially since I want to stream multiple files concatenated as one.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] ?change-value for assocs

2020-08-17 Thread Alexander Ilin
It's perfect! Thank you! 17.08.2020, 20:17, "John Benediktsson" :Hi Alex, I pushed a commit to master for ?change-at with two slight changes. 1) I kept the ( key assoc quot -- ) stack effect that ?change-at has. 2) I used ``at*`` so that it works with keys that have a value of ``f``.  Your version uses ``of`` which is like ``at`` and doesn't distinguish values set to false with unset values. See what you think! Best,John. On Mon, Aug 17, 2020 at 4:29 PM John Benediktsson <mrj...@gmail.com> wrote:Ah, gotcha!That could be cool. I’ll push a commit later for that!> On Aug 17, 2020, at 9:22 AM, Jon Harper <jon.harpe...@gmail.com> wrote:>> I think Alex wanted the conditional execution of the quot.> if the key doesn't exist in the assoc, change-at provides f as value,> but still stores the newvalue in the assoc at the given key.>> Jon>>> On Mon, Aug 17, 2020 at 6:18 PM John Benediktsson <mrj...@gmail.com> wrote:>>>> https://docs.factorcode.org/content/word-change-at,assocs.html>>>> On Aug 17, 2020, at 8:31 AM, Alexander Ilin <ajs...@yandex.ru> wrote:>>>> Hello!>>>> I came up with this code, because I could not quickly find an existing word for this.>> Did I miss it? If not, would it be a useful addition to the assocs vocab?>>>> ! If key exists in the assoc, change its value with quot.>> : ?change-value ( assoc key quot: ( value -- value' ) -- assoc' )>>   [ swap pick set-at ] compose [ 2dup of ] dip [ drop ] if* ; inline>>>> ! Usage example:>> : ?decode-opt ( assoc -- assoc' )>>   "opt" [ string>options ] ?change-value ;>>>>>> ---=--->> Александр>>>>>>>> ___>> Factor-talk mailing list>> Factor-talk@lists.sourceforge.net>> https://lists.sourceforge.net/lists/listinfo/factor-talk>>>> ___>> Factor-talk mailing list>> Factor-talk@lists.sourceforge.net>> https://lists.sourceforge.net/lists/listinfo/factor-talk>>> ___> Factor-talk mailing list> Factor-talk@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] ?change-value for assocs

2020-08-17 Thread Alexander Ilin
Hello!

  I came up with this code, because I could not quickly find an existing word 
for this.
  Did I miss it? If not, would it be a useful addition to the assocs vocab?

! If key exists in the assoc, change its value with quot.
: ?change-value ( assoc key quot: ( value -- value' ) -- assoc' )
[ swap pick set-at ] compose [ 2dup of ] dip [ drop ] if* ; inline

! Usage example:
: ?decode-opt ( assoc -- assoc' )
"opt" [ string>options ] ?change-value ;


---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] concatenative.org

2020-08-17 Thread Alexander Ilin
Any chance of a follow-up on this topic? 04.08.2020, 23:06, "Benjamin Pollack" :I think that’d ideally be best done by adding an extra alloy/modifying the existing auth alloy to support it. I’ll need to take a look later tonight or perhaps tomorrow, but I can give you some pointers, because I was in there a year ago in a (failed) attempt to make auth support CouchDB in addition to SQLs. On Aug 4, 2020, at 3:45 PM, Alexander Ilin <ajs...@yandex.ru> wrote: No, that's why I'm asking. If you could give me a pointer into which vocabs implement the wiki authorization, I could give it a shot. 04.08.2020, 21:49, "John Benediktsson" <mrj...@gmail.com>:Have you integrated it with the http.server web responder login system? That would be a nice feature to support!Thanks!John.  On Aug 4, 2020, at 11:28 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Now that we have TOTP working, would it be a nice idea to protect the concatenative.org wiki with it? If we require all newly registered users to have TOTP enabled to login, would that help against the spam?  ---=--- Александр___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Dwarf

2020-08-04 Thread Alexander Ilin
What is extra/dwarf? I see no docs, not even a summary, and git-blame reveals 
nothing useful.
Is it related to the ELF format?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] concatenative.org

2020-08-04 Thread Alexander Ilin
That would be great, because I don't have much experience with web development (neither front- nor back-end), so I need all the help I can get. 04.08.2020, 23:06, "Benjamin Pollack" :I think that’d ideally be best done by adding an extra alloy/modifying the existing auth alloy to support it. I’ll need to take a look later tonight or perhaps tomorrow, but I can give you some pointers, because I was in there a year ago in a (failed) attempt to make auth support CouchDB in addition to SQLs. On Aug 4, 2020, at 3:45 PM, Alexander Ilin <ajs...@yandex.ru> wrote: No, that's why I'm asking. If you could give me a pointer into which vocabs implement the wiki authorization, I could give it a shot. 04.08.2020, 21:49, "John Benediktsson" <mrj...@gmail.com>:Have you integrated it with the http.server web responder login system? That would be a nice feature to support!Thanks!John.  On Aug 4, 2020, at 11:28 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Now that we have TOTP working, would it be a nice idea to protect the concatenative.org wiki with it? If we require all newly registered users to have TOTP enabled to login, would that help against the spam? ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] concatenative.org

2020-08-04 Thread Alexander Ilin
No, that's why I'm asking. If you could give me a pointer into which vocabs implement the wiki authorization, I could give it a shot. 04.08.2020, 21:49, "John Benediktsson" :Have you integrated it with the http.server web responder login system? That would be a nice feature to support!Thanks!John.  On Aug 4, 2020, at 11:28 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Now that we have TOTP working, would it be a nice idea to protect the concatenative.org wiki with it? If we require all newly registered users to have TOTP enabled to login, would that help against the spam?  ---=--- Александр___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] concatenative.org

2020-08-04 Thread Alexander Ilin
Now that we have TOTP working, would it be a nice idea to protect the 
concatenative.org wiki with it?
If we require all newly registered users to have TOTP enabled to login, would 
that help against the spam?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Qualified identifiers

2020-08-01 Thread Alexander Ilin
I could not figure out whether the `:` word creates the alias with the `vocab:` prefix, or it's somehow supported by the parser, so I didn't update the documentation for `:`, only for the `USE:` and `USING:` words. 01.08.2020, 22:52, "Alexander Ilin" :Created PR #2320. 01.08.2020, 16:41, "John Benediktsson" <mrj...@gmail.com>:Good point. When that feature was added, probably the documentation was not improved in the places you mention. Let’s fix that!Best,John.  On Aug 1, 2020, at 6:29 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Hello!   Is it documented anywhere that the Factor words can be qualified by prefixing them with the "vocab:"?  This may be self-evident to people familiar with the Forth family of languages, but I studied Factor by its built-in documentation before any other such languages, and was quite surprised when I discovered that this trick works. This tells me that it was probably never mentioned in the docs.   I think it should be stated somewhere, otherwise it's not clear that the use of words like QUALIFIED: is extra syntax, which amends the already existing basis.   To rephrase what I mean, here's an example from the QUALIFIED: docs: USING: prettyprint ; QUALIFIED: math 1 2 math:+ . 3   What I missed in the _other_ Factor syntax documentation, is that even without using QUALIFIED: it's possible to qualify and disambiguate with the following syntax: USING: prettyprint math ; 1 2 math:+ . 3   Here, the "math:" prefix is optional, but it can be used.   For example, in the "Factor handbook » The language » Words » Colon definitions" article it could be mentioned that both "word" and "vocab:word" aliases are defined, if that's indeed how it works. The USE:/USING: documentation at "Factor handbook » The language » Syntax » Parse-time word lookup » Syntax to control word lookup" also doesn't mention that all the imported words can be used with the optional vocab name prefix, even though it mentions the possible ambiguity issues.  ---=--- Александр ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Qualified identifiers

2020-08-01 Thread Alexander Ilin
Created PR #2320. 01.08.2020, 16:41, "John Benediktsson" :Good point. When that feature was added, probably the documentation was not improved in the places you mention. Let’s fix that!Best,John.  On Aug 1, 2020, at 6:29 AM, Alexander Ilin <ajs...@yandex.ru> wrote:  Hello!   Is it documented anywhere that the Factor words can be qualified by prefixing them with the "vocab:"?  This may be self-evident to people familiar with the Forth family of languages, but I studied Factor by its built-in documentation before any other such languages, and was quite surprised when I discovered that this trick works. This tells me that it was probably never mentioned in the docs.   I think it should be stated somewhere, otherwise it's not clear that the use of words like QUALIFIED: is extra syntax, which amends the already existing basis.   To rephrase what I mean, here's an example from the QUALIFIED: docs: USING: prettyprint ; QUALIFIED: math 1 2 math:+ . 3   What I missed in the _other_ Factor syntax documentation, is that even without using QUALIFIED: it's possible to qualify and disambiguate with the following syntax: USING: prettyprint math ; 1 2 math:+ . 3   Here, the "math:" prefix is optional, but it can be used.   For example, in the "Factor handbook » The language » Words » Colon definitions" article it could be mentioned that both "word" and "vocab:word" aliases are defined, if that's indeed how it works. The USE:/USING: documentation at "Factor handbook » The language » Syntax » Parse-time word lookup » Syntax to control word lookup" also doesn't mention that all the imported words can be used with the optional vocab name prefix, even though it mentions the possible ambiguity issues.  ---=--- Александр ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Qualified identifiers

2020-08-01 Thread Alexander Ilin
Hello!

  Is it documented anywhere that the Factor words can be qualified by prefixing 
them with the "vocab:"?
  This may be self-evident to people familiar with the Forth family of 
languages, but I studied Factor by its built-in documentation before any other 
such languages, and was quite surprised when I discovered that this trick 
works. This tells me that it was probably never mentioned in the docs.

  I think it should be stated somewhere, otherwise it's not clear that the use 
of words like QUALIFIED: is extra syntax, which amends the already existing 
basis.

  To rephrase what I mean, here's an example from the QUALIFIED: docs:
USING: prettyprint ;
QUALIFIED: math
1 2 math:+ .
3

  What I missed in the _other_ Factor syntax documentation, is that even 
without using QUALIFIED: it's possible to qualify and disambiguate with the 
following syntax:
USING: prettyprint math ;
1 2 math:+ .
3

  Here, the "math:" prefix is optional, but it can be used.

  For example, in the "Factor handbook » The language » Words » Colon 
definitions" article it could be mentioned that both "word" and "vocab:word" 
aliases are defined, if that's indeed how it works. The USE:/USING: 
documentation at "Factor handbook » The language » Syntax » Parse-time word 
lookup » Syntax to control word lookup" also doesn't mention that all the 
imported words can be used with the optional vocab name prefix, even though it 
mentions the possible ambiguity issues.

---=--- 
 Александр




___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Package Factor into a DLL

2020-07-18 Thread Alexander Ilin
Hello!

  Is it possible to create a DLL in Factor and define exported functions that 
can be called from other Windows processes who load that DLL?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Nice! I'm also using RipGrep.Thank you! 06.06.2020, 01:37, "Doug Coleman" :Yes, you can see this using ripgrep: ➜  factor-master git:(master) ✗ cd vm➜  vm git:(master) ✗ rg nano_countos-genunix.cpp30:uint64_t nano_count() {os-windows.hpp       <---70:uint64_t nano_count();os-macosx.mm77:uint64_t nano_count() {vm.cpp31:      last_nano_count(0),os-unix.hpp49:uint64_t nano_count();os-windows.cpp         <147:uint64_t nano_count() {155:  // nano_count calls would show a difference of about 1 second,factor.cpp67:  srand((unsigned int)nano_count());gc.cpp10:      start_time(nano_count()),14:  start_time = nano_count();17:void gc_event::reset_timer() { temp_time = nano_count(); }20:  times[phase] = (cell)(nano_count() - temp_time);26:  total_time = (cell)(nano_count() - start_time);32:    start_time = nano_count();run.cpp12:void factor_vm::primitive_nano_count() {13:  uint64_t nanos = nano_count();14:  if (nanos < last_nano_count) {16:    std::cout << std::hex << last_nano_count;21:  last_nano_count = nanos;primitives.hpp32:      _(minor_gc) _(modify_code_heap) _(nano_count) _(quotation_code)          \vm.hpp140:  uint64_t last_nano_count;176:  void primitive_nano_count();  On Fri, Jun 5, 2020 at 5:14 PM Alexander Ilin <ajs...@yandex.ru> wrote:Does it also return 8 bytes in 32-bit Windows? 06.06.2020, 01:09, "Doug Coleman" <doug.cole...@gmail.com>:Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so you need 8 bytes. In vm/os-genunix.cpp: uint64_t nano_count() {  struct timespec t;  int ret = clock_gettime(CLOCK_MONOTONIC, );  if (ret != 0)    fatal_error("clock_gettime failed", 0);  return (uint64_t)t.tv_sec * 10 + t.tv_nsec;} On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman <doug.cole...@gmail.com> wrote:As long as you can fully round-trip the integer, it doesn't matter how many bytes you use. nano-count dup 4 >be be> = .f nano-count dup 8 >be be> = .t nano-count dup 128 >be be> = .t   ``log2 1 +`` will give you the required number of bits to store an integer. You will want to round up to a power of 8 bits or a power of two bytes. USE: math.bitwisenano-count dup dup log2 1 + bits = On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin <ajs...@yandex.ru> wrote:Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a `byte-array` there are `>le` and `>be`, but they require the number of bytes as a parameter. The question is, what should I supply for the value received from `nano-count`?  And the bigger question is, given an integer value, is there a way to interrogate it about its byte size, i.e. the minimum number of bytes it takes to hold the value without truncation and without leading zeroes:  Value -- MinSize 0 -- 1 255 -- 1 256 -- 2 65535 -- 2 65536 -- 3 etc.  I would expect such information to be available somewhere without doing the power of two calculations in a loop. 23.03.2020, 05:41, "Doug Coleman" <doug.cole...@gmail.com>:For Factor, integers are either fixnum or bignum size. For C, you tell it how many bytes it occupies according to the C header. Generally the sizes are the same across platforms. If they aren't, you might need two different STRUCT: declarations like in basis/unix/stat/linux/32/32.factor and basis/unix/stat/linux/64/64.factor. The main point -- function signatures and struct declarations usually handle the integer sizes and you shouldn't have to think much about it. Do you have a specific example?Earlier I wrote: One more question. I want to convert an integer into a byte-array containing its bytes. In my use case it was the return value of the nano-count, but the question is general: how can I get the bytes of an integer.  For floats there are primitives like float>bits and double>bits, and for integers there is >le and >be, but for the latter two I need to specify the size in bytes. Is there a way to ask an integer how many bytes it occupies? Because from the documentation it's not clear at all how many bytes nano-count would return, and it may vary depending on the current platform. What am I missing?___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-ta

Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Does it also return 8 bytes in 32-bit Windows? 06.06.2020, 01:09, "Doug Coleman" :Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so you need 8 bytes. In vm/os-genunix.cpp: uint64_t nano_count() {  struct timespec t;  int ret = clock_gettime(CLOCK_MONOTONIC, );  if (ret != 0)    fatal_error("clock_gettime failed", 0);  return (uint64_t)t.tv_sec * 10 + t.tv_nsec;} On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman <doug.cole...@gmail.com> wrote:As long as you can fully round-trip the integer, it doesn't matter how many bytes you use. nano-count dup 4 >be be> = .f nano-count dup 8 >be be> = .t nano-count dup 128 >be be> = .t   ``log2 1 +`` will give you the required number of bits to store an integer. You will want to round up to a power of 8 bits or a power of two bytes. USE: math.bitwisenano-count dup dup log2 1 + bits = On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin <ajs...@yandex.ru> wrote:Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a `byte-array` there are `>le` and `>be`, but they require the number of bytes as a parameter. The question is, what should I supply for the value received from `nano-count`?  And the bigger question is, given an integer value, is there a way to interrogate it about its byte size, i.e. the minimum number of bytes it takes to hold the value without truncation and without leading zeroes:  Value -- MinSize 0 -- 1 255 -- 1 256 -- 2 65535 -- 2 65536 -- 3 etc.  I would expect such information to be available somewhere without doing the power of two calculations in a loop. 23.03.2020, 05:41, "Doug Coleman" <doug.cole...@gmail.com>:For Factor, integers are either fixnum or bignum size. For C, you tell it how many bytes it occupies according to the C header. Generally the sizes are the same across platforms. If they aren't, you might need two different STRUCT: declarations like in basis/unix/stat/linux/32/32.factor and basis/unix/stat/linux/64/64.factor. The main point -- function signatures and struct declarations usually handle the integer sizes and you shouldn't have to think much about it. Do you have a specific example?Earlier I wrote: One more question. I want to convert an integer into a byte-array containing its bytes. In my use case it was the return value of the nano-count, but the question is general: how can I get the bytes of an integer.  For floats there are primitives like float>bits and double>bits, and for integers there is >le and >be, but for the latter two I need to specify the size in bytes. Is there a way to ask an integer how many bytes it occupies? Because from the documentation it's not clear at all how many bytes nano-count would return, and it may vary depending on the current platform. What am I missing?___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Integer to Bytes

2020-06-05 Thread Alexander Ilin
Hello again!  My specific example is the following. I want to put the output of `nano-count` into a `byte-array`, which is fed into a hash. The current value of `nano-count` is one of the sources of randomness gathered from the system and poured into the hash. To convert the integer value into a `byte-array` there are `>le` and `>be`, but they require the number of bytes as a parameter. The question is, what should I supply for the value received from `nano-count`?  And the bigger question is, given an integer value, is there a way to interrogate it about its byte size, i.e. the minimum number of bytes it takes to hold the value without truncation and without leading zeroes:  Value -- MinSize 0 -- 1 255 -- 1 256 -- 2 65535 -- 2 65536 -- 3 etc.  I would expect such information to be available somewhere without doing the power of two calculations in a loop. 23.03.2020, 05:41, "Doug Coleman" :For Factor, integers are either fixnum or bignum size. For C, you tell it how many bytes it occupies according to the C header. Generally the sizes are the same across platforms. If they aren't, you might need two different STRUCT: declarations like in basis/unix/stat/linux/32/32.factor and basis/unix/stat/linux/64/64.factor. The main point -- function signatures and struct declarations usually handle the integer sizes and you shouldn't have to think much about it. Do you have a specific example?Earlier I wrote: One more question. I want to convert an integer into a byte-array containing its bytes. In my use case it was the return value of the nano-count, but the question is general: how can I get the bytes of an integer.  For floats there are primitives like float>bits and double>bits, and for integers there is >le and >be, but for the latter two I need to specify the size in bytes. Is there a way to ask an integer how many bytes it occupies? Because from the documentation it's not clear at all how many bytes nano-count would return, and it may vary depending on the current platform. What am I missing?___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Platform Max Int

2020-05-10 Thread Alexander Ilin
Thank you for the tips, Doug, I have used the code in my latest "sodium" PR. 23.03.2020, 03:13, "Doug Coleman" :You could do this: : SODIUM_SIZE_MAX ( -- x ) cell-bits on-bits ; where cell-bits gives 32/64 and on-bits turns them to ones.  On Sun, Mar 22, 2020 at 6:44 PM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  I'm creating the sodium library FFI for Factor, and I found the following definition in the Sodium C headers:#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)  I think SODIUM_SIZE_MAX is used as platform-dependent macro constant, which represents a maximum value for array sizes and similar memory limits.  It'll have the max value of the size_t type, which is either 16-bit, 32-bit or 64-bit depending on the compilation target platform.  How should I define the SODIUM_SIZE_MAX constant in Factor?---=--- Александр___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Is there a default way to generate the k-partitions of a sequence?

2020-04-26 Thread Alexander Ilin
Some thoughts out loud. So, basically we need to take the length of the input sequence N, and split it into k numbers >= 1, so that the sum total of them will be = N. Let's say N = 10, k = 3. What kind of outputs can we get? Start with major number M = N - k + 1 = 8. Here the list of combinations will be the shortest, with only k combinations:{ 8 1 1 }{ 1 8 1 }{ 1 1 8 } Next major number is M = N - k = 7:{ 7 2 1 }{ 7 1 2 }{ 1 7 2 }{ 2 7 1 }{ 1 2 7 }{ 2 1 7 } Next major is M = N - k - 1 = 6:{ 6 3 1 }{ 6 1 3 }{ 3 6 1 }{ 1 6 3 }{ 3 1 6 }{ 1 3 6 }{ 6 2 2 }{ 2 6 2 }{ 2 2 6 } Then M = 5:{ 5 4 1 }...{ 5 3 2 }.. When we get below N div 2, the combinations will repeat earlier ones. If we look at the case with major number 6, we can see that we need to compute all permutations of { 6 3 1 } and { 6 2 2 }. The code for this exists in Factor library.How does on get the numbers to combine with the major number M? Those are the (k - 1) numbers with sum total = N - M. A simple recursive formula can return all such numbers. When we have the array of lengths, such as { 6 3 1 }, we can apply it to the original sequence with `cum-sum split-indices but-last`:"1234567890" { 6 3 1 } cum-sum split-indices but-last{ "123456" "789" "0" }  26.04.2020, 07:03, "Luca Di Sera" :For my current use case I would need the set to be ordered and to not allow null values ( I will further along need to build one that is still ordered but allows null values to work with epsilon-producing rules but I'll look at that case later ). I see. If there is no word I have no problem implementing one, but I would gladly receive feedback or provide a specification to look at how you would implement it. So, for the specification case: I'm looking for a word that, given a positive integer k and a sequence of objects seq of length n, with 1 <= k <= n, builds a sequence of all the k-partitions of seq. With partitions as defined above and with the remark at the top of this message that the set is ordered. ( I've seen that for integer partitions, if the order matters, the result is called a composition instead. I'm not sure if this is the same for set-partittions as I couldn't find any relevant terminology, but I'm intending a set-partition to be akin to an integer composition rather than to integer partition ) For example: "pqrs" 3 k-partitions . { { "pq" "r" "s" } { "p" "qr" "s" } { "p" "q" "rs" } } "(i+i)xi"  3 k-partitions .{  {  "(" "i" "+i)xi" }   {  "(" "i+" "+)xi" }  {  "(" "i+i" ")xi" }  {  "(" "i+i)" "xi" }  {  "(" "i+i)x" "i" }  {  "(i" "+" "i)xi" }   {  "(i" "+i" ")xi" }  {  "(i" "+i)" "xi" }  {  "(i" "+i)x" "i" }  {  "(i+" "i" ")xi" }   {  "(i+" "i)" "xi" }  {  "(i+" "i)x" "i" }   {  "(i+i" ")" "xi" }  {  "(i+i" ")x" "i" }   {  "(i+i)" "x" "i" }}  This is what I would request if it is someone else who will do the implementation. If I am the one to do the implementation, then I'm a slave to the whims of my curiosity.Thus, even if in practice I need the above, I'm much more interested in implementing the paper I linked to in my first post ( as It seems to have inspired me in different ways for both factor and idris ) and would, then, ask help with improving code that is related to this task.  For example, this is the stub implementation that I've done for the general case of generating all unrestricted partitions: : expanding-child ( partition -- seq )    unclip 1 - prefix 1 suffix ;: preserving-child ( partition -- seq )    unclip 1 - prefix unclip-last 1 + suffix ;: has-an-expanding-child? ( partition -- ? )    first2 > ;: has-a-preserving-child? ( partition -- ? )    [ 2 tail* first2 [ > ] [ - 1 > ] 2bi ]    [ length 2 > ]    bi or and ;: children ( partition -- )    [ has-an-expanding-child? ] [        [ expanding-child [ , ] [ children ] bi ]        [ [ has-a-preserving-child? ] [ preserving-child [ children ] [ , ] bi ] smart-when* ] bi    ] smart-when* ;PRIVATE>: partitions ( n -- partitions )    [        1 - 1 2array [ [ children ] { } make ] [ prefix ] bi    ] [ 1array prefix ] bi ;: split-partitions ( seq -- partitions )    dup length partitions [ 0 [ + ] accumulate* split-indices harvest ] with map ; IN: scratchpad 8 partitions .{    { 8 }    { 7 1 }    { 6 1 1 }    { 5 1 1 1 }    { 4 1 1 1 1 }    { 3 1 1 1 1 1 }    { 2 1 1 1 1 1 1 }    { 1 1 1 1 1 1 1 1 }    { 5 2 1 }    { 4 2 1 1 }    { 3 2 1 1 1 }    { 2 2 1 1 1 1 }    { 3 2 2 1 }    { 2 2 2 1 1 }    { 2 2 2 2 }    { 4 2 2 }    { 4 3 1 }    { 3 3 1 1 }    { 3 3 2 }    { 4 4 }    { 5 3 }    { 6 2 }}IN: scratchpad { 1 2 3 4 5 6 7 8 } split-partitions .{    { { 1 2 3 4 5 6 7 8 } }    { { 1 2 3 4 5 6 7 } { 8 } }    { { 1 2 3 4 5 6 } { 7 } { 8 } }    { { 1 2 3 4 5 } { 6 } { 7 } { 8 } }    { { 1 2 3 4 } { 5 } { 6 } { 7 } { 8 } }    { { 1 2 3 } { 4 } { 5 } { 6 } { 7 } { 8 } }    { { 1 2 } { 3 } { 4 } { 5 } { 6 } { 7 } { 8 } }    { { 1 } { 2 } { 3 } { 4 } { 5 } { 6 } { 7 } { 8 } }    { { 1 2 3 4 5 } { 6 7 } { 8 } }    { { 1 2 3 4 } { 5 6 } { 7 } { 8 } }    { { 1 2 3 } { 4 5 } { 6 } { 7 } { 8 

Re: [Factor-talk] She-bang

2020-04-20 Thread Alexander Ilin
Thanks for the quick reply! I think it should be in the docs, but either it's 
self-evident and not worth mentioning, or I failed to find it.
I was searching around the command-line parameters (-e, -run, etc.)

21.04.2020, 02:15, "John Benediktsson" :
> Yes, if you put a she-bang at the top you can just run it.
>
> $ cat hello
> #!/path/to/factor
> USE: io ;
> “HELLO WORLD” print
>
> $ ./hello
>
>>  On Apr 20, 2020, at 4:10 PM, Alexander Ilin  wrote:
>>
>>  Hey, guys!
>>
>>   I could not find this in the help. Does Factor support she-bang style 
>> scripts?
>>
>>  ---=---
>>  Александр
>>
>>  ___
>>  Factor-talk mailing list
>>  Factor-talk@lists.sourceforge.net
>>  https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] She-bang

2020-04-20 Thread Alexander Ilin
Hey, guys!

  I could not find this in the help. Does Factor support she-bang style scripts?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Secure Memory

2020-04-12 Thread Alexander Ilin
(Sorry, I accidentally sent the previous message before it was finished.) I will revive this old thread of mine to say that any copying GC creates an issue with sensitive data, which higher level application code can't overcome. If there is a piece of sensitive data, which the application wants to keep hidden - for example, by only decrypting it briefly before use, or by zeroing it when it's no longer needed - the GC can enter at the worst possible moment and create a copy of such data when it's exposed - that is, after decryption or before zeroing. When this weakness is combined with other vulnerabilities, sensitive data can be leaked. Therefore, to mitigate such issues there has to be support on the GC level, it has to be a feature of the runtime environment. I agree that performance of the copying GC is proportional to the number of surviving objects. If we add the extra "sensitive" bit, the performance will be proportional to the number of surviving objects plus the number of the objects tagged with the bit. The latter number is typically very small. I agree that it's foolish to delay cleanup of the sensitive memory to the GC time, but on the other hand it's not always possible to know if all the clients are done with the data. In any case, if GC is able to copy the sensitive data during memory compaction, it prevents the application code from zeroing the old copy. I'd like to reply to the Doug's argument once again. He wrote: "if they could read your memory after a gc why not just read it before gc instead?"You see, normally "they" can't arbitrarily read my memory. But sometimes due to application bugs they can get some extra memory, or some uninitialized memory. Remember the Heartbleed vulnerability? The server would return a block of freshly allocated, uninitialized memory, and sometimes that memory would contain data previously submitted by other clients of the server, or even the server's own cryptographic secrets: https://en.wikipedia.org/wiki/Heartbleed#Behavior. So, it's important that freshly allocated, uninitialized memory doesn't contain any sensitive data, and the only way to assure that in a system with a relocating GC, is to make the GC wipe such data before returning it to the unallocated pool. It's not about preventing other applications on the same system from accessing the memory, and it's not about potential ability of reading random memory addresses by some Factor code that I can write. It's about mitigating the consequences of bugs that can occur in the normal course of the events. As the situation is now, I think it is not difficult, but impossible to adequately mitigate such security risks in the Factor's memory management. I would like it to be possible. Unfortunately, I lack the knowledge to change the Factor runtime/GC, having only some limited experience with it. That's why I'm trying to convince you guys to have another look at the matter. In the meantime I have added a library support for the secure memory, which requires libsodium. Essentially, it's a way to allocate memory outside of the Factor's GC, and then manage a wrapper to that memory with the destructors vocab. The memory is wiped on deallocation, it's possible to make it read-only or inaccessible, and it's marked in a way that prevents the OS from swapping it out to disk: https://libsodium.gitbook.io/doc/memory_management. Here's the PR: https://github.com/factor/factor/pull/2277I'm not sure if I should have tagged the subvocab with "not loaded", or if the tag in the parent is sufficient. 19.01.2018, 23:39, "Björn Lindqvist" :Yes, there is (byte-array) which allocates uninitialized memory. User code is not supposed to call that word. But there are many other ways to get hold of memory you don't own. For example, you can just read it:     1234  0 alien-cell That would attempt to read 4 or 8 bytes from address 1234. It will produce a memory protection fault because the process doesn't own the address at 1234, but it would have worked fine if it did. It is as doug says, if you can read it after the gc has run you can read it before too. Try running:     "it works" kernel.private:context vm:context memory>struct datastack>>      0 alien-cell alien-address 0xf unmask 32 +  alien>native-string 2018-01-17 23:11 GMT+01:00 Alexander Ilin <ajs...@yandex.ru>:Doug and Björn, I'd like to point out the following use case for your consideration, and then you can tell me if the selective zeroing of sensitive memory buffers by the GC makes sense. Some sensitive data is stored in a networked application (let's say, a Web Server with its security certificates).The data in the application is surrounded with some `with-destructors` combinators that will clear it when it's no longer needed.But - the GC comes along and relocates the sensitive data in memory by copying it and not erasing it in the old place. The old location is marked as free memory.

Re: [Factor-talk] Secure Memory

2020-04-12 Thread Alexander Ilin
I will revive this old thread of mine to say that any copying GC creates an issue with sensitive data, which application code can't overcome. If there is a piece of sensitive data, which the application wants to keep hidden - for example, by only decrypting it briefly before use, or by zeroing it when it's no longer needed - the GC can enter at the worst possible moment and create a copy of such data when it's exposed - that is, after decryption or before zeroing. 19.01.2018, 23:39, "Björn Lindqvist" :Yes, there is (byte-array) which allocates uninitialized memory. User code is not supposed to call that word. But there are many other ways to get hold of memory you don't own. For example, you can just read it:     1234  0 alien-cell That would attempt to read 4 or 8 bytes from address 1234. It will produce a memory protection fault because the process doesn't own the address at 1234, but it would have worked fine if it did. It is as doug says, if you can read it after the gc has run you can read it before too. Try running:     "it works" kernel.private:context vm:context memory>struct datastack>>      0 alien-cell alien-address 0xf unmask 32 +  alien>native-string 2018-01-17 23:11 GMT+01:00 Alexander Ilin <ajs...@yandex.ru>:Doug and Björn, I'd like to point out the following use case for your consideration, and then you can tell me if the selective zeroing of sensitive memory buffers by the GC makes sense. Some sensitive data is stored in a networked application (let's say, a Web Server with its security certificates).The data in the application is surrounded with some `with-destructors` combinators that will clear it when it's no longer needed.But - the GC comes along and relocates the sensitive data in memory by copying it and not erasing it in the old place. The old location is marked as free memory. Now I assume that there is a way in Factor to allocate a `byte-array` without initializing the memory. This means that by requesting enough "free" memory from the runtime we will at some point get a hold of the block containing the released copy of the sensitive data. This is a problem, especially if our application is downloading and running scripts from the network, like, say, a Web Browser would do all the time. That combination of not clearing the memory on release and not clearing the memory on allocation (both expensive things to do if you do them all the time) creates the potential for the leakage. Adding a single bit flag that would tell GC to zero a particular object's memory on release (or reallocation) would be a great security feature, I think. Not a global command-line argument, but a per-object-instance flag.What do you think? Does it make sense? Is it difficult to implement? As to the Java finalizers argument - I'm not suggesting to rely on GC for the cleanup, as indeed it may never happen. I'd only want it not to leave old copies of some specific buffers hanging around when it's done its invisible (to the application code) magic. 17.01.2018, 22:40, "Doug Coleman" <doug.cole...@gmail.com>:We actually had a command-line argument to the vm to optionally zero the gc after collection but we removed the feature somewhere around when we dropped BSD support. It's probably better than nothing but if they could read your memory after a gc why not just read it before gc instead? Doug On Wed, Jan 17, 2018 at 1:34 PM Björn Lindqvist <bjou...@gmail.com> wrote:Factor when run in debug mode actually clears memory. See bump_allocator.hpp. Unfortunately clearing memory is slow as hell. The time complexity of copying gc is proportional to the number of surviving objects. But if you want to clear memory too it becomes proportional to the total number of allocated objects.  Plus, relying on the gc to zero out sensitive memory is a bad idea. You never know when the gc runs or if it runs at all. That's why it is considered bad practice in Java to use finalizers. I think it would be better to use the destructors vocab to implement zeroing out of sensitive memory.     2018-01-16 23:17 GMT+01:00 Alexander Ilin <ajs...@yandex.ru>:Hello!  I was reading a manual on the `8th` language, and noticed an interesting feature.  Apparently, it's possible to call a word on a memory buffer and thereby mark it as "sensitive information".  GC would zero the memory upon release.  Zeroing every bit of memory on release would add a lot of overhead (as I understand), but selectively clearing it like this could help with security applications that deal with certificates and passwords and stuff. This is especially useful, because in Factor GC can relocate (= copy) objects in memory. Does it clean up the memory it copied?  Do we have such a feature? Is it difficult to implement?  Bjourne, you've seen a lot of the runtime, can you comment?---=--- Александр--Check out the vi

Re: [Factor-talk] Integer to Bytes

2020-03-22 Thread Alexander Ilin
Thank you!  One more question. I want to convert an integer into a byte-array containing its bytes. In my use case it was the return value of the nano-count, but the question is general: how can I get the bytes of an integer.  For floats there are primitives like float>bits and double>bits, and for integers there is >le and >be, but for the latter two I need to specify the size in bytes. Is there a way to ask an integer how many bytes it occupies? Because from the documentation it's not clear at all how many bytes nano-count would return, and it may vary depending on the current platform. What am I missing? 23.03.2020, 03:13, "Doug Coleman" :You could do this: : SODIUM_SIZE_MAX ( -- x ) cell-bits on-bits ; where cell-bits gives 32/64 and on-bits turns them to ones.  On Sun, Mar 22, 2020 at 6:44 PM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  I'm creating the sodium library FFI for Factor, and I found the following definition in the Sodium C headers:#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX)  I think SODIUM_SIZE_MAX is used as platform-dependent macro constant, which represents a maximum value for array sizes and similar memory limits.  It'll have the max value of the size_t type, which is either 16-bit, 32-bit or 64-bit depending on the compilation target platform.  How should I define the SODIUM_SIZE_MAX constant in Factor?---=--- Александр___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Platform Max Int

2020-03-22 Thread Alexander Ilin
Hello!

  I'm creating the sodium library FFI for Factor, and I found the following 
definition in the Sodium C headers:

#define SODIUM_MIN(A, B) ((A) < (B) ? (A) : (B))
#define SODIUM_SIZE_MAX SODIUM_MIN(UINT64_MAX, SIZE_MAX) 

  I think SODIUM_SIZE_MAX is used as platform-dependent macro constant, which 
represents a maximum value for array sizes and similar memory limits.
  It'll have the max value of the size_t type, which is either 16-bit, 32-bit 
or 64-bit depending on the compilation target platform.

  How should I define the SODIUM_SIZE_MAX constant in Factor?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Plotting in Factor

2019-11-04 Thread Alexander Ilin
"ui.gadgets.charts.demos" run

04.11.2019, 10:11, "Sanjay Jain via Factor-talk" 
:
> I am new to Factor and am planning to use Factor scientific and engineering 
> data analysis. I have noted that Factor supports words for matrix algebra and 
> BLAS as well as bignum. Is there a facility to plot data for visualization? I 
> could not find it in index of libraries.
>
> Sanjay Jain
> Agra, India
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] logica -- a prolog-like library

2019-10-12 Thread Alexander Ilin
Hello!

  I like the idea, and I will definitely keep in mind that such a thing exists, 
but at the moment don't have a use for it.

  The words like "semper", etc. - is there a tradition behind it? I've never 
seen such terminology in computing before.

12.10.2019, 13:46, "KUSUMOTO Norio" :
> Hello everyone.
>
> I wrote an explanation about logica.
>
> 
>
> I would appreciate it if you could give me your opinions and comments.
>
> Also, I would appreciate it if you could think about how to use it. ;-)
>
> --
> KUSUMOTO Norio
>
>>  2019/10/03 21:40、KUSUMOTO Norio のメール:
>>
>>  logica is a library that implements the functionality of a subset of Prolog.
>>  It's still in the making and there's no documentation. Some features are
>>  written, but not tried, or not implemented well.
>>
>>  However, it has been confirmed that it works meaningfully to some extent,
>>  so I make the repository public as it is now.
>>
>>  
>>
>>  logica is a port from tiny_prolog and its descendants, ruby-prolog.
>>
>>  For example, to solve a zebra puzzle
>>  (  ) :
>>
>>  USING: locica logica.test.zebra ;
>>  { houseso Hs X Y } query .
>>
>>  --
>>  KUSUMOTO Norio
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Escapable each

2019-10-02 Thread Alexander Ilin
I like the LGBT reference, well done! : )

02.10.2019, 16:14, "KUSUMOTO Norio" :
>  2019/09/23 18:03、Alexander Ilin のメール:
>>  Have you used the `backtrack` vocab for this?
>>  https://re-factor.blogspot.com/2015/06/send-more-money.html
>
> I ported a Prolog program to solve the same puzzle.
>
> USING: logica lists assocs sequences kernel math
> locals formatting io ;
> IN: logica.test.money
>
> LOGIC-PREDS: sumo sum1o digitsumo delo nonzeroo donaldo moneyo ;
> LOGIC-VARS: S E N D M O R Y A L G B T
> N1 N2 C C1 C2 D1 D2 L1
> Digits Digs Digs1 Digs2 Digs3 ;
>
> { sumo N1 N2 N } {
> { sum1o N1 N2 N 0 0 L{ 0 1 2 3 4 5 6 7 8 9 } __ }
> } si
>
> { sum1o L{ } L{ } L{ } 0 0 Digits Digits } semper
> { sum1o [ D1 N1 cons ] [ D2 N2 cons ] [ D N cons ] C1 C Digs1 Digs } {
> { sum1o N1 N2 N C1 C2 Digs1 Digs2 }
> { digitsumo D1 D2 C2 D C Digs2 Digs }
> } si
>
> { digitsumo D1 D2 C1 D C Digs1 Digs } {
> { delo D1 Digs1 Digs2 }
> { delo D2 Digs2 Digs3 }
> { delo D Digs3 Digs }
> [ [ [ D1 of ] [ D2 of ] [ C1 of ] tri + + ] S is ]
> [ [ S of 10 mod ] D is ]
> [ [ S of 10 / >integer ] C is ]
> } si
>
> { delo A L L } { { nonvaro A } | } si
> { delo A [ A L cons ] L } semper
> { delo A [ B L cons ] [ B L1 cons ] } { delo A L L1 } si
>
> { moneyo L{ 0 S E N D }
>  L{ 0 M O R E }
>  L{ M O N E Y }
> } semper
>
> { donaldo L{ D O N A L D }
>    L{ G E R A L D }
>    L{ R O B E R T }
> } semper
>
> :: S-and-M-can't-be-zero ( seq -- seq' )
> seq [| hash |
>  1 hash N1 of list>array nth 0 = not
>  1 hash N2 of list>array nth 0 = not and
> ] filter ;
>
> :: print-puzzle ( hash-array -- )
> hash-array
> [| hash |
>  " " printf hash N1 of list>array [ "%d " printf ] each nl
>  "+ " printf hash N2 of list>array [ "%d " printf ] each nl
>  "" printf nl
>  " " printf hash N of list>array [ "%d " printf ] each nl nl
> ] each ;
>
> IN: scratchpad [ { { moneyo N1 N2 N } { sumo N1 N2 N } } query
>   S-and-M-can't-be-zero
>   print-puzzle
> ] time
>    0 9 5 6 7
> + 0 1 0 8 5
> 
>    1 0 6 5 2
>
> Running time: 0.320353468 seconds
>
> --
> KUSUMOTO Norio
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Escapable each

2019-09-23 Thread Alexander Ilin
Have you used the `backtrack` vocab for this?
https://re-factor.blogspot.com/2015/06/send-more-money.html

23.09.2019, 10:43, "KUSUMOTO Norio" :
>>  2019/09/22 20:21、Alexander Ilin のメール:
>>
>>  I use `loop` or `while`, depending on the details.
>
> Hello. Thank you for your answer.
>
> I rewrote my program using `loop 'and `while'. The library I'm currently
> building is an extended port from Ruby's one, and I used `with-return`
> to mimic the code.
>
> The use of `with-return` in this code, which does a lot of repetition,
> seems to have been a very bad choice.
> The zebra puzzle is now running about 20 times faster than before.
>
> USING: factor-logica lists ;
> IN: factor-logica.test.zebra
> LOGIC-PREDS: houseso neighboro zebrao watero nexto lefto ;
> LOGIC-VARS: Hs A B Ls X Y ;
> SYMBOLS: red blue green white yellow ;
> SYMBOLS: english swede dane norwegian german ;
> SYMBOLS: dog cat birds horse zebra ;
> SYMBOLS: tea coffee beer milk water ;
> SYMBOLS: pall-mall dunhill blue-master prince blend ;
> TUPLE: house color nationality drink smoke pet ;
>
> { houseso Hs X Y } {
> { (=) Hs L{ ! #1
>   T{ house f _ norwegian _ _ _ } ! #10
>   T{ house f blue _ _ _ _ } ! #15
>   T{ house f _ _ milk _ _ } _ _ } } ! #9
> { membero T{ house f red english _ _ _ } Hs } ! #2
> { membero T{ house f _ swede _ _ dog } Hs } ! #3
> { membero T{ house f _ dane tea _ _ } Hs } ! #4
> { lefto T{ house f green _ _ _ _ } T{ house f white _ _ _ _ } Hs } ! #5
> { membero T{ house f green _ coffee _ _ } Hs } ! #6
> { membero T{ house f _ _ _ pall-mall birds } Hs } ! #7
> { membero T{ house f yellow _ _ dunhill _ } Hs } ! #8
> { nexto T{ house f _ _ _ blend _ } T{ house f _ _ _ _ cat } Hs } ! #11
> { nexto T{ house f _ _ _ dunhill _ } T{ house f _ _ _ _ horse } Hs } ! #12
> { membero T{ house f _ _ beer blue-master _ } Hs } ! #13
> { membero T{ house f _ german _ prince _ } Hs } ! #14
> { nexto T{ house f _ _ water _ _ } T{ house f _ _ _ blend _ } Hs } ! #16
> { membero T{ house f _ X water _ _ } Hs }
> { membero T{ house f _ Y _ _ zebra } Hs }
> } si
>
> { nexto A B Ls } {
> { appendo _ [ A B _ cons cons ] Ls } vel
> { appendo _ [ B A _ cons cons ] Ls }
> } si
>
> { lefto A B Ls } { appendo _ [ A B _ cons cons ] Ls } si
>
> IN: scratchpad { houseso Hs X Y } query .
> {
> H{
> {
> Hs
> L{
> T{ house
> { color yellow }
> { nationality norwegian }
> { drink water }
> { smoke dunhill }
> { pet cat }
> }
> T{ house
> { color blue }
> { nationality dane }
> { drink tea }
> { smoke blend }
> { pet horse }
> }
> T{ house
> { color red }
> { nationality english }
> { drink milk }
> { smoke pall-mall }
> { pet birds }
> }
> T{ house
> { color green }
> { nationality german }
> { drink coffee }
> { smoke prince }
> { pet zebra }
> }
> T{ house
> { color white }
> { nationality swede }
> { drink beer }
> { smoke blue-master }
> { pet dog }
> }
> }
> }
> { X norwegian }
> { Y german }
> }
> }
> IN: scratchpad [ 1000 [ { houseso Hs X Y } query drop ] times ] time
>
> Running time: 20.393989632 seconds
>
> --
> KUSUMOTO Norio
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Escapable each

2019-09-23 Thread Alexander Ilin
Wow, this looks very cool!
: ))

23.09.2019, 10:43, "KUSUMOTO Norio" :
>>  2019/09/22 20:21、Alexander Ilin のメール:
>>
>>  I use `loop` or `while`, depending on the details.
>
> Hello. Thank you for your answer.
>
> I rewrote my program using `loop 'and `while'. The library I'm currently
> building is an extended port from Ruby's one, and I used `with-return`
> to mimic the code.
>
> The use of `with-return` in this code, which does a lot of repetition,
> seems to have been a very bad choice.
> The zebra puzzle is now running about 20 times faster than before.
>
> USING: factor-logica lists ;
> IN: factor-logica.test.zebra
> LOGIC-PREDS: houseso neighboro zebrao watero nexto lefto ;
> LOGIC-VARS: Hs A B Ls X Y ;
> SYMBOLS: red blue green white yellow ;
> SYMBOLS: english swede dane norwegian german ;
> SYMBOLS: dog cat birds horse zebra ;
> SYMBOLS: tea coffee beer milk water ;
> SYMBOLS: pall-mall dunhill blue-master prince blend ;
> TUPLE: house color nationality drink smoke pet ;
>
> { houseso Hs X Y } {
> { (=) Hs L{ ! #1
>   T{ house f _ norwegian _ _ _ } ! #10
>   T{ house f blue _ _ _ _ } ! #15
>   T{ house f _ _ milk _ _ } _ _ } } ! #9
> { membero T{ house f red english _ _ _ } Hs } ! #2
> { membero T{ house f _ swede _ _ dog } Hs } ! #3
> { membero T{ house f _ dane tea _ _ } Hs } ! #4
> { lefto T{ house f green _ _ _ _ } T{ house f white _ _ _ _ } Hs } ! #5
> { membero T{ house f green _ coffee _ _ } Hs } ! #6
> { membero T{ house f _ _ _ pall-mall birds } Hs } ! #7
> { membero T{ house f yellow _ _ dunhill _ } Hs } ! #8
> { nexto T{ house f _ _ _ blend _ } T{ house f _ _ _ _ cat } Hs } ! #11
> { nexto T{ house f _ _ _ dunhill _ } T{ house f _ _ _ _ horse } Hs } ! #12
> { membero T{ house f _ _ beer blue-master _ } Hs } ! #13
> { membero T{ house f _ german _ prince _ } Hs } ! #14
> { nexto T{ house f _ _ water _ _ } T{ house f _ _ _ blend _ } Hs } ! #16
> { membero T{ house f _ X water _ _ } Hs }
> { membero T{ house f _ Y _ _ zebra } Hs }
> } si
>
> { nexto A B Ls } {
> { appendo _ [ A B _ cons cons ] Ls } vel
> { appendo _ [ B A _ cons cons ] Ls }
> } si
>
> { lefto A B Ls } { appendo _ [ A B _ cons cons ] Ls } si
>
> IN: scratchpad { houseso Hs X Y } query .
> {
> H{
> {
> Hs
> L{
> T{ house
> { color yellow }
> { nationality norwegian }
> { drink water }
> { smoke dunhill }
> { pet cat }
> }
> T{ house
> { color blue }
> { nationality dane }
> { drink tea }
> { smoke blend }
> { pet horse }
> }
> T{ house
> { color red }
> { nationality english }
> { drink milk }
> { smoke pall-mall }
> { pet birds }
> }
> T{ house
> { color green }
> { nationality german }
> { drink coffee }
> { smoke prince }
> { pet zebra }
> }
> T{ house
> { color white }
> { nationality swede }
> { drink beer }
> { smoke blue-master }
> { pet dog }
> }
> }
> }
> { X norwegian }
> { Y german }
> }
> }
> IN: scratchpad [ 1000 [ { houseso Hs X Y } query drop ] times ] time
>
> Running time: 20.393989632 seconds
>
> --
> KUSUMOTO Norio
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Escapable each

2019-09-22 Thread Alexander Ilin
I use `loop` or `while`, depending on the details.

22.09.2019, 13:05, "KUSUMOTO Norio" :
> Hello all,
>
> 'each 'and' 2each 'are very useful for writing iterative processes, but 
> sometimes
> I want to get out of a process before repeating it to the end under certain 
> conditions.
>
> I think it would be possible to write such a combinator because 'find' stops 
> iterating
> when it finds something that satisfies the condition, but I don't know how to 
> write
> 'each' that can escape.
>
> What code do you write for such a process?
> I use 'with-return' to handle such situations. But I suspect it's costing 
> time.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Co-operative threading

2019-09-14 Thread Alexander Ilin
You open a file, read one line, then reopen the file and do the same again.Since you are reopening the stream, there's always data available, thus there is no reason to yield. 14.09.2019, 21:04, "murray.calavera--- via Factor-talk" :Hello all, I'm a bit confused about how threads work with IO in factor.  This: https://docs.factorcode.org/content/article-threads.html seems to imply that functions such as readln will yield  to other threads unless data is available on a stream, but the following program only ever reads from the fifo: USING: kernel threads io io.files io.encodings.utf8 ;
IN: test

: read-fifo ( -- )
    "fifo" utf8 [ readln print flush ] with-file-reader read-fifo ;

: read-stdin ( -- )
    readln print flush read-stdin ;

[ read-fifo ] "fifo-thread" spawn drop
read-stdin

 What am I misunderstanding here?
Thanks.
Murray.
 ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр 

___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] directly writing to pref-dim slot of gadget

2019-07-25 Thread Alexander Ilin
See the documentation for the `pref-dim` word.If you read/write the `pref-dim` slot for random gadgets, you will mess up the caching of the value and possibly the layout logic of the `ui.gadgets` vocab.It's OK to set the initial value if you don't want to override the `pref-dim*` method for that purpose. 25.07.2019, 15:59, "John Benediktsson" :It's probably to set the default / initial size of the gadget. Some gadgets do it by overriding the ``pref-dim*`` word like so: ./extra/tetris/tetris.factor:M: tetris-gadget pref-dim* drop { 200 400 } ; And a few do it by setting it like that... I think the ``pref-dim*`` approach was the intended approach, but even the ``MAIN-WINDOW:`` word sets the pref-dim slot on the world for its initial size (and the world is a track gadget...). I kind of think a constructor type word should be able to just do { 200 400 } >>pref-dim and then later that slot can be changed dynamically, etc... dunno.  On Thu, Jul 25, 2019 at 5:15 AM Georg Simon  wrote:https://docs.factorcode.org/content/word-gadget,ui.gadgets.html says"pref-dim -a cached value for pref-dim; do not read or write this slot directly."But in extra/gesture-logger/gesture-logger.factorand extra/rosetta-code/animate-pendulum/animate-pendulum.factorI find{ 450 500 } >>pref-dimand{ 500 500 } >>pref-dimWhat is right ?___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Executable version information

2019-06-18 Thread Alexander Ilin
Well, I surely didn't mean to dig THAT deep! : )) Here's the code that works for me. Please have a look and see if I missed something. I'm out of my comfort zone dealing with the aliens, always afraid of leaking memory, etc.Also, is there an elegant way to replace the tail of multiple `] [ f ] if`? USING:   alien alien.data alien.libraries alien.syntax   destructors formatting io.binary kernel libc locals math sequences   windows.types;IN: winver<< "version" "version.dll" stdcall add-library >>LIBRARY: versionFUNCTION: DWORD GetFileVersionInfoSizeA (   LPCSTR  lptstrFilename,   LPDWORD lpdwHandle )FUNCTION: DWORD GetFileVersionInfoSizeW (   LPCWSTR lptstrFilename,   LPDWORD lpdwHandle )ALIAS: GetFileVersionInfoSize GetFileVersionInfoSizeWFUNCTION: BOOL GetFileVersionInfoA (   LPCSTR lptstrFilename,   DWORD  dwHandle,   DWORD  dwLen,   LPVOID lpData )FUNCTION: BOOL GetFileVersionInfoW (   LPCWSTR lptstrFilename,   DWORD  dwHandle,   DWORD  dwLen,   LPVOID lpData )ALIAS: GetFileVersionInfo GetFileVersionInfoWFUNCTION: BOOL VerQueryValueA (   LPCVOID pBlock,   LPCSTR  lpSubBlock,   LPVOID  *lplpBuffer,   PUINT   puLen )FUNCTION: BOOL VerQueryValueW (   LPCVOID pBlock,   LPCSTR  lpSubBlock,   LPVOID  *lplpBuffer,   PUINT   puLen )ALIAS: VerQueryValue VerQueryValueW: translation-prefix ( alien -- string )   LPDWORD deref 4 memory>byte-array 2 cut [ le> ] bi@   "\\StringFileInfo\\%04x%04x\\" sprintf ;: version-query ( alien -- string )   translation-prefix "FileVersion" append ;:: (file-version) ( path data-size -- string/f )   [       data-size malloc  :> data       path 0 data-size data GetFileVersionInfo [           f LPVOID  :> translation           data "\\VarFileInfo\\Translation" translation f VerQueryValue [               f LPCSTR  :> result               data translation version-query result f VerQueryValue               [ result LPCSTR deref ] [ f ] if           ] [ f ] if       ] [ f ] if   ] with-destructors ;: file-version ( path -- string/f )   dup f GetFileVersionInfoSize dup 0 > [ (file-version) ] [ 2drop f ] if ;  18.06.2019, 21:09, "John Benediktsson" :I don't think so, but that'd be a cool thing to add! https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format On Tue, Jun 18, 2019 at 10:37 AM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  Is there a vocab in Factor to extract the Version Information resource from an executable file on Windows?  I'm writing an app that needs to know the "FileVersion" string from the "StringFileInfo" block.---=--- Александр  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Executable version information

2019-06-18 Thread Alexander Ilin
Hello!

  Is there a vocab in Factor to extract the Version Information resource from 
an executable file on Windows?
  I'm writing an app that needs to know the "FileVersion" string from the 
"StringFileInfo" block.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin

08.06.2019, 16:11, "Alexander Ilin" :
> I have also pushed an experimental commit to support transparency in the 
> foreground text color.
> It seems there is still an issue with the correct handling of foreground 
> color. For example, instead of light blue I get a yellow.

  Found the reason. It was the extra "swap rot" from John's suggested code.

  I have removed the color mix-up and pushed the branch again.

  https://github.com/AlexIljin/factor/tree/win-transparent-text-background

  I consider this code to be complete, unless someone wants to comment on some 
unconventional formatting.
  Also, I didn't actually test the text output with transparent foreground 
color. If you do some testing, let me know if it works as expected. I've 
removed transparent foreground handling into a separate if branch to reduce the 
performance impact on the most usual code path.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
I have also pushed an experimental commit to support transparency in the 
foreground text color.
It seems there is still an issue with the correct handling of foreground color. 
For example, instead of light blue I get a yellow.

08.06.2019, 15:12, "KUSUMOTO Norio" :
>>  2019/06/08 20:04、Alexander Ilin のメール:
>>
>>   Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
>> here are the new results from commit fa57d052:
>>   Opaque background: 143 ms
>>   Transparent background: 150 ms
>>
>>   In general, the Transparent test runs about 6-7 ms longer than the Opaque 
>> test, i.e. about 4.6% slower, which is a much better performance 
>> characteristic compared to the previous approaches.
>>
>>   The updated code is posted here: 
>> https://github.com/AlexIljin/factor/tree/win-transparent-text-background
>
> How wonderful!
>
> If it's this fast, it shouldn't be a problem in terms of speed to implement 
> imperfectly
> transparent foreground text.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
I have updated the code. There was the "24 bits" missing after "3byte-array 
uint32_t deref", so the random top byte used to mix in with the transparency 
via "bitor".

08.06.2019, 15:03, "Alexander Ilin" :
> Unfortunately, the posted code doesn't work as expected: the text labels 
> randomly have colored background. I'm looking for a reason.
>
> 08.06.2019, 14:04, "Alexander Ilin" :
>>  Hello, Norio, and thank you for the benchmark code!
>>
>>    I was able to use it, and here are results from my tests. I took the 
>> typical output values.
>>
>>    Your code from commit a16eb2f6:
>>    Opaque background: 146 ms
>>    Transparent background: 1083 ms
>>
>>    My code from commit 26516f97:
>>    Opaque background: 142 ms
>>    Transparent background: 1800 ms
>>
>>    Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
>> here are the new results from commit fa57d052:
>>    Opaque background: 143 ms
>>    Transparent background: 150 ms
>>
>>    In general, the Transparent test runs about 6-7 ms longer than the Opaque 
>> test, i.e. about 4.6% slower, which is a much better performance 
>> characteristic compared to the previous approaches.
>>
>>    The updated code is posted here: 
>> https://github.com/AlexIljin/factor/tree/win-transparent-text-background
>>
>>  08.06.2019, 10:11, "KUSUMOTO Norio" :
>>>   Ouch, an e-mail wasn't sent to the mailing list because I sent it direct.
>>>   I rewrite the wrong part and send it again.
>>>
>>>   On 2019/06/05 22:24, John Benediktsson wrote:
>>>>    Or clear the cache each time, so you don’t have to be lower level 
>>>> code...
>>>>>    On Jun 5, 2019, at 4:24 AM, Alexander Ilin wrote: I 
>>>>> think the pairs of {font, string} are cached and only drawn once by the 
>>>>> GUI framework. I think you need to call the drawing code more directly to 
>>>>> get real performance data.
>>>
>>>   Thank you, Alexander and John.
>>>   I decided to measure only internal processing time.
>>
>>  ---=---
>>   Александр
>>
>>  ___
>>  Factor-talk mailing list
>>  Factor-talk@lists.sourceforge.net
>>  https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> ---=---
>  Александр
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-08 Thread Alexander Ilin
Hello, Norio, and thank you for the benchmark code!

  I was able to use it, and here are results from my tests. I took the typical 
output values.

  Your code from commit a16eb2f6:
  Opaque background: 146 ms
  Transparent background: 1083 ms

  My code from commit 26516f97:
  Opaque background: 142 ms
  Transparent background: 1800 ms

  Then I incorporated the optimizations suggested by Jonh Benediktsson, and 
here are the new results from commit fa57d052:
  Opaque background: 143 ms
  Transparent background: 150 ms

  In general, the Transparent test runs about 6-7 ms longer than the Opaque 
test, i.e. about 4.6% slower, which is a much better performance characteristic 
compared to the previous approaches.

  The updated code is posted here: 
https://github.com/AlexIljin/factor/tree/win-transparent-text-background

08.06.2019, 10:11, "KUSUMOTO Norio" :
> Ouch, an e-mail wasn't sent to the mailing list because I sent it direct.
> I rewrite the wrong part and send it again.
>
> On 2019/06/05 22:24, John Benediktsson wrote:
>>  Or clear the cache each time, so you don’t have to be lower level code...
>>>  On Jun 5, 2019, at 4:24 AM, Alexander Ilin wrote: I 
>>> think the pairs of {font, string} are cached and only drawn once by the GUI 
>>> framework. I think you need to call the drawing code more directly to get 
>>> real performance data.
>
> Thank you, Alexander and John.
> I decided to measure only internal processing time.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Recourse to Composure

2019-06-06 Thread Alexander Ilin
Hi, Jack!  I think what you are doing is really cool, and I would love to read the book one day! 06.06.2019, 15:16, "Jack Lucas via Factor-talk" :Yesterday I was trying to create this adjacency system for one of the games I'm working on.  I have no idea if this will stay like this,  but, at the time, it sure felt like I was trying to jam first class words into Factor,  and I'd like to know if there's a better method. The goal of this snippet of code is to take some originating coordinates on the stack like 40 40 and convert it into the adjacent square coordinates in my grid.  So from 40 40 we might get a sequence back like { { 0 0 } { 80 0 } { 0 80 } { 80 80 } } describing the coordinates of squares adjacent ( in the corner going diagonally ).  I obviously didn't want to rewrite adjacent 4 times with a different combination of +'s and -'s so I instead wrote it as you see here. Thinking in terms of sequences and matrices, this is the solution I came up with for you: : adjacent-diagonals ( pos step -- seq )   { - + } [ execute( x y -- n ) ] with cartesian-map   first2 cartesian-product concat ;  Test code:IN: scratchpad { 40 40 } 40 adjacent-diagonals .{ { 0 0 } { 0 80 } { 80 0 } { 80 80 } }  Correspondingly, if the player is facing "left", you could pick the necessary pair of coordinates by doing something like : left-squares ( square -- seq )   grid-size get adjacent-diagonals { 0 2 } swap nths ;  or, generalizing over the directions, : player-direction-squares ( -- seq )   {       { "down" { 0 1 } }       { "up"    { 2 3 } }       { "left"   { 0 2 } }       { "right" { 1 3 } }   } player-sym get direction>> of ; : adjacent-squares ( pos -- seq )   grid-size get adjacent-diagonals player-direction-squares swap nths ;  What do you think?  Another approach could revolve around the following definition, I think you can figure out the rest of the details: : player-direction-squares ( -- seq )   {       { "down" { { + - } { - - } } }       { "up"    { { + + } { - + } } }       { "left"   { { - - } { - + } } }       { "right" { { + - } { + + } } }   } player-sym get direction>> of ;   :: adjacent ( x y ex ex2 -- quot )    [ x grid-size get ex execute ,  y grid-size get ex2 execute , ] { } make ; inline : upper-left ( x y -- seq )    \ - \ - adjacent ; : upper-right ( x y -- seq )    \ + \ - adjacent ; : bottom-left ( x y -- seq )    \ - \ + adjacent ; : bottom-right ( x y -- seq )    \ + \ + adjacent ; ! player-sym is just a tuple holding the players state! Whatever direction the player is facing is the side! we want him to be able to grab items from.: player-direction-squares ( -- squares )    player-sym get direction>>    {    { "left"   [ { bottom-left upper-left   } ]  }    { "right" [ { bottom-right upper-right  } ] }    } case ; ! square-coordinates ( square -- x y ) : adjacent-squares ( square -- list )    square-coordinates [ rot execute( x y -- seq ) ] 2curry    player-direction-squares    swap map ; inline   In this way,  depending on which direction the player is facing, finding the adjacent squares  is literally a matter of mapping over the words themselves rather than the data.  Since it would look like... { "bottom-left" "upper-left" } [ x y rot execute( x y -- seq ) ] map The question for me becomes,  is this an over-complicated way of achieving a simple effect?  I wonder if there's a way to do it like lisp-macros where I can just syntactically insert the words I want without evaluating them.  In any case,  I'm mostly posting this to see if I'm going off the deep end of only having a problem because I'm thinking about the issue the wrong way or if this genuinely is the right direction to go in trying to solve a problem like this in Factor.  Either way it was fun to try to make without repeating myself 4 times.  Copiously Caffeinated,  Sequentially Coordinated, ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-06-05 Thread Alexander Ilin
I think the pairs of {font, string} are cached and only drawn once by the GUI 
framework.
I think you need to call the drawing code more directly to get real performance 
data.

04.06.2019, 07:39, "KUSUMOTO, Norio" :
> My code was uploaded.
>
> https://github.com/kusumotonorio/factor/blob/win-transparent-background-text/basis/windows/uniscribe/uniscribe.factor
>
> I want to know how slow the code when it draws transparent background
> texts. So I am writing
> a test app to know it. But it has an issue.
> I try to measure time by actually drawing a label with a transparent
> background over and over again, and that happens very quickly.
> Creating an image from text takes a long time (3: and 4:) , so it should
> actually take longer.
> What's wrong with my code?
>
> ! Copyright (C) 2019 KUSUMOTO Norio.
> ! See http://factorcode.org/license.txt for BSD license.
> USING: kernel accessors locals math formatting ui ui.gadgets.labels
> ui.commands ui.gadgets ui.gadgets.toolbar ui.gadgets.tracks ui.gestures
> fonts colors tools.time memory math.ranges namespaces arrays sequences
> windows.uniscribe windows.uniscribe.private ;
> IN: uni-bench
>
> TUPLE: uni-bench-gadget < track
>  opaque-label
>  transparent-label
>  opaque-time
>  transparent-time ;
>
> SYMBOL: test-strings
> V{ } clone test-strings set-global
> 1 5000 [a,b]  [
>  "%04d" sprintf test-strings get push
> ] each
> test-strings get >array test-strings set-global
>
> :  ( -- gadget )
>  vertical uni-bench-gadget new-track
>   {
>   "  Press any of the keys listed below"
>   ""
>   "    1: Opaque background label (5000 times)"
>   "    2: Transparent background label (5000 times)"
>   "    3: Opaque script-string>image (5000 times)"
>   "    4: Transparent script-string>image (5000 times)"
>   ""
>  }  f track-add
>
>  ""  >>opaque-label
>  ""  >>transparent-label
>  ""  >>opaque-time
>  ""  >>transparent-time
>
>  dup opaque-label>>
>  
>  "monospace" >>name
>  T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
>  T{ rgba f 0.0 0.0 1.0 1.0 } >>background
>  36 >>size
>  >>font f track-add
>
>  dup transparent-label>>
>  
>  "monospace" >>name
>  T{ rgba f 0.0 0.0 0.0 1.0 } >>foreground
>  T{ rgba f 0.0 0.0 1.0 0.0 } >>background
>  36 >>size
>  >>font f track-add
>
>  dup opaque-time>> " Opaque:" label-on-left f track-add
>  dup transparent-time>> " Transparent:" label-on-left f track-add ;
>
> :: com-benchmark-opaque ( gadget -- )
>  gadget opaque-label>> :> test-label
>  gc
>  [
>  test-strings get-global [
>  test-label swap >>text relayout-1
>  ] each
>  ] benchmark
>  gadget opaque-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> :: com-benchmark-transparent ( gadget -- )
>  gadget transparent-label>> :> test-label
>  gc
>  [
>  test-strings get-global [
>  test-label swap >>text relayout-1
>  ] each
>  ] benchmark
>  gadget transparent-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> :: com-benchmark-opaque-script-string>image ( gadget -- )
>  gadget opaque-label>> font>> :> test-font
>  gc
>  [
>  test-strings get-global [
>  test-font swap  script-string>image drop
>  ] each
>  ] benchmark
>  gadget opaque-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> :: com-benchmark-transparent-script-string>image ( gadget -- )
>  gadget transparent-label>> font>> :> test-font
>  gc
>  [
>  test-strings get-global [
>  test-font swap  script-string>image drop
>  ] each
>  ] benchmark
>  gadget transparent-time>>
>  swap 100 / "%d ms" sprintf >>text relayout-1 ;
>
> uni-bench-gadget "gestures" f {
>  { T{ key-down { sym "1" } } com-benchmark-opaque }
>  { T{ key-down { sym "2" } } com-benchmark-transparent }
>  { T{ key-down { sym "3" } } com-benchmark-opaque-script-string>image }
>  { 

Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-30 Thread Alexander Ilin
Hello!

  I think I have figured out the algorithm for the image processing. I'm not 
sure
  if it's the same one that you came up with.

  https://github.com/factor/factor/issues/152#issuecomment-497292323

  Also, I don't know if there are standard WinApi functions to perform the
  necessary operation, namely copying a color channel into the alpha
  channel, but I suspect there might be, in which case we won't lose
  performance there.

30.05.2019, 03:50, "KUSUMOTO Norio" :
> Although it seems that to transfer the appropriate data to the device context 
> is
> the 'right' solution, I have a hunch that it will be a difficult task.
> So I am beginning to think that we should take another, a cheat, approach.
>
> It's like a chroma key. Uniscribe draws text with a color background instead 
> of
> transparency, and a word replaces the color with transparency when converting
> from the bitmap to an Factor's image.
>
> It may be slow, but we don't have many chances to draw characters on a 
> transparent
> background. And for example, on a button label, once Factor creates an image 
> with
> such characters, Factor use the image again, so I think there are few 
> problems.
>
> This approach can localize changes. I can't define the word for image 
> conversion to do
> such a special action, but I think that it's not a difficult task for someone 
> familiar with
> image processing words.


---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-29 Thread Alexander Ilin
Wow, you are making a very valuable contribution!
Thank you very much for the effort you are making!

It would be really great to have a solution for this issue.

29.05.2019, 05:39, "KUSUMOTO Norio" :
> It seems that the direction to solve the problem is not wrong.
> But, we will need to transfer the appropriate data with the appropriate 
> offset to the device context
> where Uniscribe writes a text.
>
> 
>

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Transparent background texts and Windows Factor

2019-05-28 Thread Alexander Ilin
Hello!

28.05.2019, 08:37, "KUSUMOTO Norio" :
> Hello all,
>
> I've been researching for a while about Windows Factor's inability to 
> correctly render texts on
> transparent backgrounds. I haven't solved the problem yet, but I've just come 
> to an idea.
> I'd be happy to hear your opinions on that.
>
> For example, labels for button widgets are tentatively drawn with gray 
> background text because
> they cannot draw labels with a transparent background. I disabled this 
> behavior and tried to make
> transparent drawing work correctly, but only on a black background. I kept 
> trying to figure
> out what was behind the black background, but I couldn't find the widget.
>
> That's why I came up with the idea that Uniscribe works to make the 
> background transparent,
> but where the characters are written is black. At first it seemed like a 
> silly idea, but I wrote
> the code to confirm it.

  Is it possible to tell Uniscribe to render the text in white color?
  If such text shows up on the black background, that would confirm part of the 
theory.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Factor UI and Input Method

2019-04-10 Thread Alexander Ilin
nil is f, the canonical false value.

10.04.2019, 15:52, "KUSUMOTO Norio" :
> Hmm, "text" may be a NSAttributedString.
> I would like to return nil at validAttributesForMarkedText.
> Can I express nil in the Factor code? How should I write it?
>
> --
> KUSUMOTO Norio
>
>>  2019/04/10 10:29、KUSUMOTO Norio のメール:
>>
>>  I will post the contents written to github.
>>
>>  I think the replacement from NSTextInput to NSTextInputClient can't solve 
>> this problem
>>  unless its methods are implemented appropriately.
>>  In an opposite way, even with NSTextInput, I anticipate the appropriate 
>> implementation
>>  of methods can solve it.
>>
>>  I'm writing a experimental code for it. But I'm in trouble.
>>  In setMarkedText:selectedRange: , I can't convert text from a NSString to a 
>> factor string
>>  by CF>string. I got the error "Unix signal #6 (SIGABRT)".
>>  The word works fine in insertText: .
>>
>> ! Text input
>> METHOD: void insertText: id text
>> [
>> self window :> window
>> window [
>> text CF>string window user-input
>> ] when
>> ] ;
>>
>> METHOD: char hasMarkedText [ 0 ] ;
>>
>> METHOD: NSRange markedRange [ 0 0  ] ;
>>
>> METHOD: NSRange selectedRange [ 0 0  ] ;
>>
>>  ! METHOD: void setMarkedText: id text selectedRange: NSRange range [ ] ;
>>
>> METHOD: void setMarkedText: id text selectedRange: Nsrange range
>>  [
>> self window :> window
>> window [
>>  ! ok --> "abc"
>>  ! ok --> "xyz"  CF>string
>>  ! "alien " text class-of "%s " sprintf
>> text CF>string ! Error Unix signal #6 (SIGABRT)
>> window world-focus user-input* drop
>> ] when
>>  ] ;
>>
>>  --
>>  KUSUMOTO Norio
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] key-up event on Windows Factor

2019-03-30 Thread Alexander Ilin
Hello!

  Nice investigation!

30.03.2019, 12:26, "KUSUMOTO Norio" :
> It seems to me key-down and key-up events are not desirable, not only in 
> Windows Factor.
> For example, on Mac Factor, when the "Q" key is pressed with a shift key, 
> gesture-logger
> reports:
>
>   T{ key-down { sym "Q" } }
>   User input: Q
>   T{ key-up { sym "Q" } }
>
> I think it should be:
>
>   T{ key-down { mods { S+ } } { sym "q" } }
>   User input: Q
>   T{ key-up { mods { S+ } } { sym "q" } }

  I think you are right, and this would solve a long-standing issue 
https://github.com/factor/factor/issues/1565
  I guess nobody had the time to dig into this, so your effort is much 
appreciated!

> I changed key-codes which is in 
> /Applications/factor/basis/ui/backend/cocoa/views/views.factor
> like this:
>
> CONSTANT: key-codes
> H{
> { 29 "0" } ! <- added
> { 18 "1" } ! <- added
> { 19 "2" } ! <- added
>
> { 0 "a" } ! <- added
> { 11 "b" } ! <- added
> { 9 "c" } ! <- added
>
> { 71 "CLEAR" }
> { 36 "RET" }
> { 76 "ENTER" }
> { 53 "ESC" }
> { 48 "TAB" }
> { 51 "BACKSPACE" }
> { 115 "HOME" }
> { 117 "DELETE" }
> { 119 "END" }
> { 122 "F1" }
> { 120 "F2" }
> { 99 "F3" }
> { 118 "F4" }
> { 96 "F5" }
> { 97 "F6" }
> { 98 "F7" }
> { 100 "F8" }
> { 123 "LEFT" }
> { 124 "RIGHT" }
> { 125 "DOWN" }
> { 126 "UP" }
> { 116 "PAGE_UP" }
> { 121 "PAGE_DOWN" }
> }
>
> Then events about "0", "1", "2", "a", "b" and "c" key are desirable for me.
>
> In conclusion, I think all keys which can exist should be added in key-codes.

  I'll try to see if I can fix the same for the Windows platform.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] make-pane with the prettyprinter

2019-03-19 Thread Alexander Ilin
Hello!

  The prettyprinter is pretty powerful, but can it be used to create rich-text 
GUIs?
  For example, is it possible to use the `flow` section to make the text in the 
following pane automatically adapt to the window width as user resizes the 
window?

MAIN-WINDOW: set-version-window {
{ title "set-version" }
{ window-controls { normal-title-bar close-button minimize-button 
resize-handles } }
} [
"So, you decided to make a release..." print nl
"Does it only contain bug fixes and no new functions? No new buttons, menu 
items or algorithms, only correction of errors in the existing functionality?" 
print
"If so, " write "release with increased PATCH number" [ drop ] 
 gadget. nl
"Does the new release contain new functions, but requires no DB schema 
update, doesn't change the folder or ini-file structure? The key question is, 
if the users install this new version, will they be able to revert to the 
previous one by only replacing the exe-files?" print
"If so, " write "release with increased MINOR version number" [ drop ] 
 gadget. nl
"Will this release update the DB schema in an incompatible way, so that 
it'll be impossible to run the older application version? Will it make similar 
backwards-incompatible changes to the configuration files or the folder 
structure of the application?" print
"If so, " write "release with increased MAJOR version number" [ drop ] 
 gadget.
] make-pane >>gadgets ;

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Kungfuguration Files

2019-03-19 Thread Alexander Ilin
I love it how everything is so simple in Factor . Thank you! : )) 19.03.2019, 21:18, "Doug Coleman" :USE: ini-file :p On Tue, Mar 19, 2019 at 1:09 PM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  I need to load a configuration from a simple text file.  I would not want to employ anything too complex (XML), and the thing must work in a deployed application, into which I would not want to include the Factor compiler.  Something like a traditional ini-file would work perfectly.  Do we have ini-file support in the standard library? What are my options?---=--- Александр___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Kungfuguration Files

2019-03-19 Thread Alexander Ilin
Hello!

  I need to load a configuration from a simple text file.
  I would not want to employ anything too complex (XML), and the thing must 
work in a deployed application, into which I would not want to include the 
Factor compiler.

  Something like a traditional ini-file would work perfectly.

  Do we have ini-file support in the standard library? What are my options?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] key-up event on Windows Factor

2019-03-09 Thread Alexander Ilin
I confirm the same behavior on Windows 10, latest development build of 64-bit 
Factor.
It doesn't depend on the numpad or on physical keys.

For example, when I use the normal English/US layout, the keys for semicolon 
and comma (";" and ",") generate only the "key-down" events. Pressing "q" and 
"w" generates both "key-down" and "key-up".
If I switch to the Programmer Dvorak layout, the physical keys that used to be 
"q" and "w" in the US layout now will produce the ";" and "," correspondingly, 
and they will again produce only the "key-down" events in the gesture-logger. 
Pressing the keys that formerly produced only "key-downs" as ";" and "," will 
now produce both "key-down" and "key-up", being mapped to "s" and "w".

It seems that the physical keyboard or the layout is not to blame. For some 
reason Factor eats some of the key-up events for punctuation characters.

There are many such characters that I can see treated differently by Factor: 
#&$^-=\`:;~/'"?@_[]{}(*+
These Factor's treatment of these keys is not dependent on the physical key, 
but on the logically mapped character it produces under the currently selected 
layout.

Numpad keys may be different in that even when Programmer Dvorak produces 
"a"-"f" or "x", they still don't give a ""key-up" event.

09.03.2019, 09:08, "John Benediktsson" :
> Interesting! Okay.
>
> Any details of the keyboard type or language settings you can share? Windows 
> 7? Is it 32-bit or 64-bit Factor?
>
> Thanks,
> John.
>
> On Mar 8, 2019, at 8:26 PM, KUSUMOTO Norio  wrote:
>
>>>  On my windows machine (Windows 7), when I hit 1 key which was in a 
>>> separate numeric pad,
>>>  Gesture log window showed :
>>>
>>>  T{ key-down { sym “1” } }
>>>  User input: 1
>>>
>>>  per one hit.
>>
>>  Normal minus, dot, comma, colon, semi-colon key are also similar.
>>  There are not notifications about key-up.
>>
>>  --
>>  KUSUMOTO Norio
>>
>>>  2019/03/09 13:00、KUSUMOTO Norio  のメール:
>>>
>>>  Hi,
>>>
  2019/03/09 10:02、John Benediktsson  のメール:

  If you'd like to play around with how Factor receives various inputs, 
 including the keyboard events, you can run the gesture-logger debug tool. 
 It prints out a log of all gestures received by the window so you can see 
 mouse movement, mouse clicks, key-up, key-down, etc:

    IN: scratchpad "gesture-logger” run
>>>
>>>  Oh, nice tool! I did it.
>>>
>>>  On my windows machine (Windows 7), when I hit 1 key which was in a 
>>> separate numeric pad,
>>>  Gesture log window showed :
>>>
>>>  T{ key-down { sym “1” } }
>>>  User input: 1
>>>
>>>  per one hit. The other hand, when I hit normal 1 key, it showed :
>>>
>>>  T{ key-down { sym “1” } }
>>>  User input: 1
>>>  T{ key-up { sym “1” } }
>>>
>>>  per one hit.
>>
>>  ___
>>  Factor-talk mailing list
>>  Factor-talk@lists.sourceforge.net
>>  https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Mailing List

2019-02-26 Thread Alexander Ilin
Hello!

  This mailing list is not listed in the Community section of the README.md 
(https://github.com/factor/factor/blob/master/README.md).

  Is this or purpose (to fight spam), or an omission that should be fixed?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Drag-and-Drop

2019-02-26 Thread Alexander Ilin
Hello!

  Do we have any drag-and-drop gestures? I'd like to be able to drag a Factor 
tuple between different UI windows of one process (extra cool if it would work 
between processes, but not necessary).

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] How to use local variable

2019-02-04 Thread Alexander Ilin
This will work as you expected:

 USE: locals
:: fnc ( -- ) 0 :> i! 3 [ i 1 + i! i . ] times ;
fnc

1
2
3


04.02.2019, 09:17, "KUSUMOTO, Norio" :
> Hello to all,
>
> I’m writing a hierarchical finite state machine library as my first Factor 
> program.
> It seems to me that It works for once now! But, there are some questions in 
> my mind.
>
> I could not handle local variables well, so I tried below words in a listener.
>
> USE: locals
> :: fnc ( -- ) 0 :> i 3 [ i 1 + :> i i . ] times ;
> fnc
>
> These words returned:
> 1
> 1
> 1
>
> Originally, I wanted to know that why the below words didn’t perform as 
> expected.
>
> USE: locals
> :: fnc2 ( -- ) 0 :> i [ i 3 < ] [ i 1 + :> i i . ] while ;
>
> It will perform as a infinite loop.
>
> In these cases, how should I write them?
>
> --
> KUSUMOTO Norio
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] [ drop ] if

2018-12-24 Thread Alexander Ilin
Hello!

  I notice that many times we do something with an object if a condition is 
true, and otherwise we drop it. Search for "[ drop ] if", and you'll find many 
instances of what I'm talking about, it's a fairly common occurrence. I am 
often tempted to use `when` in those cases, but it doesn't match the profile, 
because it doesn't drop the object when the condition is `f`.

  So, my question is: do we have such a word? Could we borrow one from a 
similar language? Could we invent it?
  Something like `1if` or `if'`.

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] unexpected integer from a float sum

2018-12-18 Thread Alexander Ilin
USE: math.functions:round instead

18.12.2018, 15:14, "Georg Simon" :
> Below I pasted a result from my listener I do not understand.
>
> The result of sum looks like 137.99 which is right.
> But the integer I made out of it is 13798 which is wrong.
>
> A typed in 137.99 gives the result I expect.
>
> What am I missing ?
> --
> Press F1 at any time for help.
> Factor 0.99 x86.64 (1889, heads/master-f77d46f0c8, Dec 1 2018 21:02:41)
> [GCC 7.3.0] on linux
>
> IN: scratchpad { -13.8 -21.8 -3.99 -3.0 -15.7 126.98 -8.9 100.0 -21.8 }
> sum
>
> --- Data stack:
> 137.99
> IN: scratchpad 100 *
>
> --- Data stack:
> 13799.0
> IN: scratchpad >integer .
> 13798
> IN: scratchpad 137.99 100 * >integer .
> 13799

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Path in graph, or something

2018-12-11 Thread Alexander Ilin
Hi, all! Little did I know when I asked about a solution to the "path-finding task", that we actually have a vocab named `path-finding`, which does exactly what I wanted!This is some next-level API : ) Anyway, I was able to implement my `db.upgrade` vocab in just a few lines of code: IN: db.upgrade! If DB has no version, simply storing the version number will give us! v0.9. The version is stored automatically, so this word is empty.: 0>0.9 ( -- ) ;: 0.9>1 ( -- )   [       persisted-tuple new [           [ trim-head-separators ] change-path       ] update-tuples   ] ignore-table-missing ;ALIAS: 0>1 0.9>1CONSTANT: transitions {   { "0" { { "0.9" 0>0.9 } { "1" 0>1 } } }   { "0.9" { { "1" 0.9>1 } } }}: search-map ( -- assoc )   transitions [ keys ] assoc-map ;: words ( graph-path -- assoc )   2  [ first2 swap transitions at dupd at ] { } map>assoc ;: (upgrade-db) ( word-assoc -- )   [       [ execute( -- ) db-version boa store* drop ] with-transaction   ] assoc-each ;: upgrade-db ( current-version required-version -- done? )   2dup = [ 2drop t ] [       search-map  find-path dup [ words (upgrade-db) ] when*       >boolean   ] if ;  All I need going forward is to keep adding new upgrading words and registering them in the `transitions` map. Then one call to `upgrade-db`, and I have the latest version of the DB structure/contents. I guess at some point I'll have to move the upgrading words into separate vocab(s) when the code would get too big or would require extra scaffolding, tuples, etc. 11.12.2018, 05:49, "John Benediktsson" :We have some path finding stuff in the ``path-finding`` vocabulary, as well as some directed graph stuff in ``graphs`` vocabulary that is used by the compiler. On Mon, Dec 10, 2018 at 11:43 AM Alexander Ilin <ajs...@yandex.ru> wrote:Hey, guys!  I have a new task, and I want to know if there are existing vocabs that can be employed for solving it.  Let's say there are versions of a DB format, and there are quotations that can be executed to convert DB from one version to another. A bunch of these quotations are edges of a directed graph, and DB versions are nodes. The task is to find the shortest path in the graph (meaning with the smallest number of edges), or to declare that the path does not exist.  Do we have a vocab that could be employed for the path-finding task? ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] maximum of a seq

2018-12-11 Thread Alexander Ilin
Hi, Peter!

> Any reason why supremum-by and infimum-by are not on the "Searching
> sequences" doc page? If you agree I can add these together with supremum
> and infimum.

A link in the help system would be useful, I think. I remember myself 
discovering those functions by word of mouth, after having read the 
documentation multiple times. It would have been nicer if I read about them in 
the help.

> I'll take a look at map-reduce, thanks. I switched from using the factor
> IDE REPL to emacs with Fuel because today I kept creating an infinite
> loop and couldn't break it for the life of me in the IDE. In emacs it
> was C-c C-c. Since I couldn't break it I didn't even know it's an
> infinite loop. That led me to open a file and save the definitions for
> debugging purposes, so I kind of broke my rules at this point. Oh well,
> at least I solved another "day" today, although I'm rather behind at
> this point, not enough time.

  If you work in Windows, there is experimental support for C-Break.
  Here's how I enable it in my .factor-rc:

! Enable handling of the Ctrl-Break interrupt
USE: listener
t handle-ctrl-break set-global

  Only works on Windows, though. There is no such thing as a global hotkey in 
Linus, AFAIK.

> Another thing that tricked me:
>
> IN: aoc V{ 1 2 3 } 2 head-slice* 3 suffix! >array .
> { 1 }
> IN: aoc V{ 1 2 3 } rest-slice 3 suffix! >array .
> { 2 3 }
>
> Slices work differently than I expected :) Are there clojure-like data
> structures that are immutable and structurally share most of their
> content?

  Not sure about clojure-like. Arrays { } are immutable, while vectors V{ } are 
mutable.
  You can also have read-only TUPLE: members:

TUPLE: hello-tuple
  { var1 read-only }
  { var2 string read-only }
...
;

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Path in graph, or something

2018-12-10 Thread Alexander Ilin
Hey, guys!

  I have a new task, and I want to know if there are existing vocabs that can 
be employed for solving it.

  Let's say there are versions of a DB format, and there are quotations that 
can be executed to convert DB from one version to another. A bunch of these 
quotations are edges of a directed graph, and DB versions are nodes. The task 
is to find the shortest path in the graph (meaning with the smallest number of 
edges), or to declare that the path does not exist.

  Do we have a vocab that could be employed for the path-finding task?

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] maximum of a seq

2018-12-10 Thread Alexander Ilin
Hey there!

  Sure, you can ask us here. I'm on sick leave, so got plenty of time.
  Coincidentally, working on my Factor hobby project.

  What you're looking for is called supremum-by.

  Terminology is a bit uncommon. Look up supremum and infimum in the help 
system.

10.12.2018, 17:06, "pet...@riseup.net" :
> Hello fellow concatenative fans.
>
> I'm working my way through this year's advent of code[0]. I'm doing it
> in factor with a small twist - everything happening inside the REPL.
> Makes it more fun and challenging (for me), although I don't have any
> code to show for it in the end.
>
> I'm trying to find the right tools for the job since there's a lot of
> words already available. Sometimes I reinvent something before I find
> it, e.g. I wrote a last-n before finding last*.
>
> Would it be OK if I sometimes ask you for tips on what would be
> idiomatic/simpler/shorter/faster than what I have(n't) found?
>
> The first problem I really couldn't find is picking a maximum from a
> sequence based on a quotation pulling out the key. An example will say
> it the best I guess:
>
>>  { { 1 2 } { 1 3 } { -1 4 } } [ second ] max-by .
>
> { -1 4 }
>
> Here is my definition:
>
> : max-by ( seq quot -- result ) [ unclip-slice ] dip '[ [ [ _ call ] bi@
>>  ] 2keep ? ] reduce ; inline
>
> Using fry for such a general word would be a bit of an overkill but for
> demonstration purposes it's OK I guess.
>
> Is there no standard word that already does something similar? Or is
> there a way to write this with the existing sequence combinators that
> it's so short there was no need to create this generic word?
>
> --
> 
>   Peter Nagy
> 
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Some beginner questions with a focus on stack effects

2018-10-07 Thread Alexander Ilin
A shorter way to write `other-quote`: : other-quote ( quote -- quote' )   "''" = "``" "''" ? ; 07.10.2018, 15:21, "Alexander Ilin" :Hello, Luca!  Such a humble email, I could not leave without an answer. Questions like this are completely appropriate on this mailing list.  Here are a few changes I made to make your code compilable: WAS:: gather-input ( mapping -- seq\f )    readln ; CORRECT:: gather-input ( -- seq\f )   readln ;  After that fix, the error you mentioned comes up, the one with the incorrect stack-effects in the `while` call. WAS:: solve ( -- )   quote-mapping [ gather-input ] [ prepare-input process-input ] while drop ; CORRECT:: solve ( -- )   quote-mapping [ gather-input dup ] [ prepare-input process-input ] while 2drop ;  The `while` word consumes one output of the first quotation (the `?` parameter), so you need to `dup` the output of `gather-input` to keep a copy on the stack for the next quotation.  The general approach you took is fine in Factor, as far as I can see. Here is my solution, similar to yours, but with a slightly different choice of the stream reading method. It uses recursion instead of the `while` loop:  USING: kernel io ;IN: 00272_TEX_Quotes: other-quote ( quote -- quote' )   "''" = [ "``" ] [ "''" ] if ;: process-input ( quote -- )   "\"" read-until swap [ write ] when* [       dup write other-quote process-input   ] [ drop ] if ;: solve ( -- )   "``" process-input ;MAIN: solve  This is how I tested it in the listener:"272.txt" utf8 [ solve nl ] with-file-reader 07.10.2018, 13:21, "Luca Di Sera" <bloodtype.si...@gmail.com>:Hello to all, I'm a beginner factor programming.I learned about factor in the "Seven More Languages in Seven Weeks" book and could not avoid falling in love with it.I'm trying to learn it at work in my lunch-breaks and one of the projects I'm following as a didactical exercise is to use it as a secondary language ( to C++ ) to solve competitive programming exercises. Now, It is a few days that I'm stuck on some non-working code that I can't seem to solve on my own, for how embarrassing that is.First of all this is the code: USING: syntax sequences kernel io splitting ;IN: UVa.00272_TEX_Quotes.Factor.00272_TEX_Quotes CONSTANT: quote-mapping { "``" "''" }  : switch-quote ( mapping x -- mapping x )    [ reverse ] dip ; : print-quote ( mapping x -- mapping x )   [ dup first write ] dip ; : gather-input ( mapping -- seq\f )    readln ; : prepare-input ( str -- seq )    "\"" split ; : process-input ( mapping seq -- mapping )    [ print-quote switch-quote write ] each ; : solve ( -- )    quote-mapping [ gather-input ] [ prepare-input process-input ] while drop ; MAIN: solve This code is a, currently in testing, solution to UVa 272.What I was trying to do is the following :  Read all lines of input one by oneFor each line that is read split it in a sequence where the " arePrint the sequence back with quotes between each element ( changing between closing and opening quotes )  Now, the main problems I'm getting with this codes are related to stack-effects. In particular after solving some of the errors the one I can't currently solve is the following: The word solve cannot be executed because it failed to compile The input quotations to “while” don't match their expected effectsInput                           Expected         Got[ gather-input ]                ( ..a -- ..b ? ) ( x -- x )[ prepare-input process-input ] ( ..b -- ..a )   ( x x -- x ) From my understanding, this is an unbalanced-branches-error.By reading the documentation I can see what this error is about, yet the reasons it is appearing and the method to correct the code are still flying over my head.I supposed it may have something to do with the way I'm passing the values around on the stack. Hoping this is an accepted topic on this mailing list, I was hoping someone could help me by explaining, or by providing resources I can deepen my understanding with,  how this code should actually be written to work and if there is some essential-error I'm doing in using factor in this code ( And I would be most thankful for suggestion on how to actually write something like this in a Factor way ).  ---=---Александр ,,___Factor-talk mailing listFactor-talk@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/factor-talk  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Some beginner questions with a focus on stack effects

2018-10-07 Thread Alexander Ilin
Hello, Luca!  Such a humble email, I could not leave without an answer. Questions like this are completely appropriate on this mailing list.  Here are a few changes I made to make your code compilable: WAS:: gather-input ( mapping -- seq\f )    readln ; CORRECT:: gather-input ( -- seq\f )   readln ;  After that fix, the error you mentioned comes up, the one with the incorrect stack-effects in the `while` call. WAS:: solve ( -- )   quote-mapping [ gather-input ] [ prepare-input process-input ] while drop ; CORRECT:: solve ( -- )   quote-mapping [ gather-input dup ] [ prepare-input process-input ] while 2drop ;  The `while` word consumes one output of the first quotation (the `?` parameter), so you need to `dup` the output of `gather-input` to keep a copy on the stack for the next quotation.  The general approach you took is fine in Factor, as far as I can see. Here is my solution, similar to yours, but with a slightly different choice of the stream reading method. It uses recursion instead of the `while` loop:  USING: kernel io ;IN: 00272_TEX_Quotes: other-quote ( quote -- quote' )   "''" = [ "``" ] [ "''" ] if ;: process-input ( quote -- )   "\"" read-until swap [ write ] when* [       dup write other-quote process-input   ] [ drop ] if ;: solve ( -- )   "``" process-input ;MAIN: solve  This is how I tested it in the listener:"272.txt" utf8 [ solve nl ] with-file-reader 07.10.2018, 13:21, "Luca Di Sera" :Hello to all, I'm a beginner factor programming.I learned about factor in the "Seven More Languages in Seven Weeks" book and could not avoid falling in love with it.I'm trying to learn it at work in my lunch-breaks and one of the projects I'm following as a didactical exercise is to use it as a secondary language ( to C++ ) to solve competitive programming exercises. Now, It is a few days that I'm stuck on some non-working code that I can't seem to solve on my own, for how embarrassing that is.First of all this is the code: USING: syntax sequences kernel io splitting ;IN: UVa.00272_TEX_Quotes.Factor.00272_TEX_Quotes CONSTANT: quote-mapping { "``" "''" }  : switch-quote ( mapping x -- mapping x )    [ reverse ] dip ; : print-quote ( mapping x -- mapping x )   [ dup first write ] dip ; : gather-input ( mapping -- seq\f )    readln ; : prepare-input ( str -- seq )    "\"" split ; : process-input ( mapping seq -- mapping )    [ print-quote switch-quote write ] each ; : solve ( -- )    quote-mapping [ gather-input ] [ prepare-input process-input ] while drop ; MAIN: solve This code is a, currently in testing, solution to UVa 272.What I was trying to do is the following :  Read all lines of input one by oneFor each line that is read split it in a sequence where the " arePrint the sequence back with quotes between each element ( changing between closing and opening quotes )  Now, the main problems I'm getting with this codes are related to stack-effects. In particular after solving some of the errors the one I can't currently solve is the following: The word solve cannot be executed because it failed to compile The input quotations to “while” don't match their expected effectsInput                           Expected         Got[ gather-input ]                ( ..a -- ..b ? ) ( x -- x )[ prepare-input process-input ] ( ..b -- ..a )   ( x x -- x ) From my understanding, this is an unbalanced-branches-error.By reading the documentation I can see what this error is about, yet the reasons it is appearing and the method to correct the code are still flying over my head.I supposed it may have something to do with the way I'm passing the values around on the stack. Hoping this is an accepted topic on this mailing list, I was hoping someone could help me by explaining, or by providing resources I can deepen my understanding with,  how this code should actually be written to work and if there is some essential-error I'm doing in using factor in this code ( And I would be most thankful for suggestion on how to actually write something like this in a Factor way ).  ---=---Александр ___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] with-http-request* sometimes fails

2018-09-05 Thread Alexander Ilin
Hello!

  Have you tried removing the leading slash before the "https://;?

05.09.2018, 16:05, "Georg Simon" :
> As it seems there are websites that make
>
>  with-http-request*
>
> throw an error :
>
> IN: scratchpad USING: http.client ;
>
> With
> "/https://fussballimtv.de;  [ . ] with-http-request* .
>
> I get the error "Bad store to specialized slot".
>
> With
> "http://factorcode.org;  [ . ] with-http-request* .
>
> all works fine.
>
> Is there a way to avoid the error ?
>
> --
> 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] Factor 0.98 now available

2018-07-31 Thread Alexander Ilin
Hi, John! 31.07.2018, 20:12, "John Benediktsson" : https://re-factor.blogspot.com/2018/07/factor-098-now-available.html I think the line "ui.tools.listener: support Ctrl-Break interruption on Windows" should be in the Improved Libraries section, not in the New Libraries.Also, not sure about "concurrency.distributed: fix serializing of remote threads". If possible, I'd like my last name spelled "Ilin". Thank you for the credit! And thank you for taking the time to release! Great work! ---=---Александр --
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] HOOK: Confusion

2018-07-28 Thread Alexander Ilin
Actually, the reasons for that may have been a little misguided. Basically, I wanted to substitute my own versions of the delete, move and copy methods with a `with-variable` scoping. So, I created a symbol that had the three (four, actually) methods defined for it, as opposed to having the infinite number of methods defined on the `windows` symbol also defined on my symbol as a redirection. You know what I mean? My special backend would record the requested file/folder operations instead of actually performing them immediately, and then it would be possible to perform those later, have the ability to see progress or cancel, etc.Or imagine you want to implement a `--dry-run` mode for your application, in which all the file operations need only to be reported to the console instead of done in the filesystem. Without separating the methods into a separate backend hook variable, if I did that with something like```my-backend io-backend [ ... ] with-variable```then `my-backend` would have to implement all kinds of crazy methods of `io-backend` like `(pipe)` or `(run-process)`, and the implementation would have to call the `windows` version of those methods, or `linux`, or whatever the previous value of `io-backend` was.I don't know of a way to subclass the `windows` symbol and only override some of its methods for the purposes of such temporary substitution. 29.07.2018, 00:06, "John Benediktsson" : Oh, so you are redefining the hook to use a different variable and it’s failing when used by another vocab? I’ll look at that later. Little busy today.  Out of curiosity why would you want it to not use the io-backend variable? On Jul 28, 2018, at 1:20 PM, Alexander Ilin <ajs...@yandex.ru> wrote: I have now pushed a branch, which adds a single commit, compared to the latest master: https://github.com/AlexIljin/factor/tree/dmc-backend(DMC stands for Delete, Move, Copy.) You can see the error I'm talking about if you:- take the branch,- start the latest build of Factor from the build farm,- press F2 in the Listener to reload the vocabs, and then- run the following command in the Listener: `USE: io.files.unique [ ] cleanup-unique-directory`. It will choke while trying to delete the temporary directory it created. I'm not sure it only chokes like that when I use my special backend. For some reason I think it sometimes fails without it, but I can't prove it (even to myself) at the moment. 28.07.2018, 01:29, "John Benediktsson" <mrj...@gmail.com>:It shouldn't fail like that, so maybe there's an issue with reloads? Do you have a simple way to reproduce it? On Fri, Jul 27, 2018 at 10:20 AM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  Sometimes I see weird errors like this:Generic word `delete-directory` does not define a method for the `word` class.Dispatching on object: `windows`  But the Browser shows that the method `delete-directory` IS defined for the `windows` symbol.  Why do the `HOOK:`s fail like this sometimes? Does it have something to do with reloading some of the involved vocabs?  ---=---Александр --
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] HOOK: Confusion

2018-07-28 Thread Alexander Ilin
I have now pushed a branch, which adds a single commit, compared to the latest master: https://github.com/AlexIljin/factor/tree/dmc-backend(DMC stands for Delete, Move, Copy.) You can see the error I'm talking about if you:- take the branch,- start the latest build of Factor from the build farm,- press F2 in the Listener to reload the vocabs, and then- run the following command in the Listener: `USE: io.files.unique [ ] cleanup-unique-directory`. It will choke while trying to delete the temporary directory it created. I'm not sure it only chokes like that when I use my special backend. For some reason I think it sometimes fails without it, but I can't prove it (even to myself) at the moment. 28.07.2018, 01:29, "John Benediktsson" :It shouldn't fail like that, so maybe there's an issue with reloads? Do you have a simple way to reproduce it? On Fri, Jul 27, 2018 at 10:20 AM Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  Sometimes I see weird errors like this:Generic word `delete-directory` does not define a method for the `word` class.Dispatching on object: `windows`  But the Browser shows that the method `delete-directory` IS defined for the `windows` symbol.  Why do the `HOOK:`s fail like this sometimes? Does it have something to do with reloading some of the involved vocabs?  ---=---Александр --
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] Recursive Definition

2018-01-26 Thread Alexander Ilin
Ah, I see it in the notes: "if is executed as a primitive when preceded by two 
literal quotations".
Sorry for the noise : )

26.01.2018, 11:56, "Alexander Ilin" <ajs...@yandex.ru>:
> Hello!
>
>   I was looking through the documentation, and something drew my attention.
>
> Definition
> IN: kernel
> : if
> ( ..a ? true: ( ..a -- ..b ) false: ( ..a -- ..b ) -- ..b )
> ? call ;
>
> Definition
> IN: kernel
> : ? ( ? true false -- true/false ) rot [ drop ] [ nip ] if ;
> inline
>
>   How is it possible that these two words are defined using each other?
>   Shouldn't the world explode when that happens?

---=--- 
 Александр


--
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] Recursive Definition

2018-01-26 Thread Alexander Ilin
Hello!

  I was looking through the documentation, and something drew my attention.

Definition
IN: kernel
: if
( ..a ? true: ( ..a -- ..b ) false: ( ..a -- ..b ) -- ..b )
? call ;

Definition
IN: kernel
: ? ( ? true false -- true/false ) rot [ drop ] [ nip ] if ;
inline

  How is it possible that these two words are defined using each other?
  Shouldn't the world explode when that happens?

---=--- 
 Александр


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

2018-01-24 Thread Alexander Ilin
Thank you, this is certainly useful! I've save this text in a file at my Factor repo.I seems like this should be somewhere in a wiki or in a text file (perhaps not in the Readme, but close to it). 24.01.2018, 22:39, "Björn Lindqvist" :Hello! I want to describe how to run Factors unit testing suite. Perhaps noteveryone on the mailing list knows about it? Anyways, running the testsuites and reporting any failures is a great way to improveFactor. Unexpected test failures can reveal bugs that are otherwisevery hard to find. Here is how you do it on Windows: 1. First you download a release of Factor and get it running.2. Go either to http://downloads.factorcode.org/dlls/64/ or   http://downloads.factorcode.org/dlls/ for 64 and 32bit builds of   Factor respectively.3. Download all the dlls and put them in the same directory as the   factor.exe file.4. Run factor.com -run=listener in a cmd.exe window.5. Then type "load-all test-all"6. Then go for a walk or something :) It takes up to two hours   for all the test suites to finish.7. If there are test failures you can inspect them by running the   :test-failures word.8. If there are so many test failures that they fill up the scrollback   buffer, you can save them to a file using: [ :test-failures ]   with-string-writer "test.log" utf8 set-file-contents If you don't have time for all the test suites, you can run the mostimportant ones using only "test-all" without "load-all".  --mvh/best regards Björn Lindqvist,--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] printf documentation

2018-01-19 Thread Alexander Ilin
Doug and John, thank you for the thorough explanation! 19.01.2018, 00:31, "John Benediktsson" <mrj...@gmail.com>:See this macro: MACRO: add ( n -- quot )    [ \ + ] [ ] replicate-as ; It's "stack effect" depends on the input.     IN: scratchpad [ 1 add ] infer .    ( x x -- x )     IN: scratchpad [ 2 add ] infer .    ( x x x -- x ) So you really can't do much more than say this macro produces some quotation. Then in calling code, we expand the macro and check the resulting body of code has the right stack effect.     : foo1 ( a b -- c ) 1 add ;    : foo2 ( a b c -- d ) 2 add ;    : foo3 ( a b c d -- e ) 3 add ;On Thu, Jan 18, 2018 at 1:04 PM, Doug Coleman <doug.cole...@gmail.com> wrote:Oops. MACRO: printf ( string -- quot: ( ..a string -- ..b ) )MACRO: sprintf ( string -- quot: ( ..a string -- ..b string ) )   On Thu, Jan 18, 2018 at 3:02 PM John Benediktsson <mrj...@gmail.com> wrote:MACRO: always produces a quot. But when it's "called" it's whatever the stack effect of that produced quot is when it's expanded into the calling site.On Thu, Jan 18, 2018 at 12:36 PM, Alexander Ilin <ajs...@yandex.ru> wrote:O-kay... Let me try to ask my question again... I've read the blog post that you linked to. In there I found the following declaration:`MACRO: printf ( format-string -- )` This means that the macro takes one argument and removes it from the stack, doesn't put anything back. But in the actual source code of the `formatting` vocab the declaration is: `MACRO: printf ( format-string -- quot )`, which looks as if the `printf` word takes one parameter off the stack and puts one item back on the stack. ... which is not true: it doesn't put a quotation on the stack, because it calls the quotation. So, I have two questions, basically: 1) why not change the declaration in `formatting` to ``MACRO: printf ( format-string -- )` - with no output onto the stack?2) are `MACRO:`s allowed to have invalid stack effect declaration? Are they somehow exempted from the compiler checks? I'm asking this because the declared stack effect shows up in the documentation, and is confusing. Reading it gives the _expression_ that it should be used with an extra `call` to the produced quotation:`11 "he%do, world" printf call` 18.01.2018, 19:00, "John Benediktsson" <mrj...@gmail.com>:Both of those are macros (basically special words that produce a quotation), so when "called" they are first macro-expanded into a quotation and then that quotation is called, with whatever stack effect it has. IN: scratchpad 1 2 3 "%s %s %s" printf1 2 3 IN: scratchpad [ "%s %s %s" printf ] infer( x x x -- ) IN: scratchpad [ "%s %s %s" printf ] expand-macros[    [ present ] 2 ndip [ " " ] 2 ndip [ present ] 1 ndip    [ " " ] 1 ndip [ present ] 0 ndip output-stream get    [ stream-write ] curry 5 napply] Maybe the article I wrote when developing it would help: https://re-factor.blogspot.com/2011/08/printf.html  On Thu, Jan 18, 2018 at 4:32 AM, Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  There are two similar words: printf and sprintf. They have similar stack effects, but different behavior.MACRO: sprintf ( format-string -- result )leaves a string on stackMACRO: printf ( format-string -- quot )leaves nothing on stack despite the stack effect specified  How come `printf` does'n obey its declared stack effect?---=--- Александр  ---=---Александр --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  ---=---Александр 

Re: [Factor-talk] printf documentation

2018-01-18 Thread Alexander Ilin
Can I simply change the stack effects for the purposes of documenting them like this?```MACRO: printf ( ... string -- )MACRO: sprintf ( ... string -- result )```  18.01.2018, 23:44, "Doug Coleman" <doug.cole...@gmail.com>:Stack effects on macros are not checked. We have the convention of lying that the stack effect is ( input -- quot ) but even that is wrong, as the macro is called immediately so you don't get a quot on the stack. The quot could have a stack effect of its own but it's variable arity, as you are seeing with printf. If you have a way to resolve this, lemme know! (One idea is "input-only stack effects" which don't have an output, so you could do ``MACRO: printf ( string ) ... ;``) On Thu, Jan 18, 2018 at 2:36 PM Alexander Ilin <ajs...@yandex.ru> wrote:O-kay... Let me try to ask my question again... I've read the blog post that you linked to. In there I found the following declaration:`MACRO: printf ( format-string -- )` This means that the macro takes one argument and removes it from the stack, doesn't put anything back. But in the actual source code of the `formatting` vocab the declaration is: `MACRO: printf ( format-string -- quot )`, which looks as if the `printf` word takes one parameter off the stack and puts one item back on the stack. ... which is not true: it doesn't put a quotation on the stack, because it calls the quotation. So, I have two questions, basically: 1) why not change the declaration in `formatting` to ``MACRO: printf ( format-string -- )` - with no output onto the stack?2) are `MACRO:`s allowed to have invalid stack effect declaration? Are they somehow exempted from the compiler checks? I'm asking this because the declared stack effect shows up in the documentation, and is confusing. Reading it gives the _expression_ that it should be used with an extra `call` to the produced quotation:`11 "he%do, world" printf call` 18.01.2018, 19:00, "John Benediktsson" <mrj...@gmail.com>:Both of those are macros (basically special words that produce a quotation), so when "called" they are first macro-expanded into a quotation and then that quotation is called, with whatever stack effect it has. IN: scratchpad 1 2 3 "%s %s %s" printf1 2 3 IN: scratchpad [ "%s %s %s" printf ] infer( x x x -- ) IN: scratchpad [ "%s %s %s" printf ] expand-macros[    [ present ] 2 ndip [ " " ] 2 ndip [ present ] 1 ndip    [ " " ] 1 ndip [ present ] 0 ndip output-stream get    [ stream-write ] curry 5 napply] Maybe the article I wrote when developing it would help: https://re-factor.blogspot.com/2011/08/printf.html  On Thu, Jan 18, 2018 at 4:32 AM, Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  There are two similar words: printf and sprintf. They have similar stack effects, but different behavior.MACRO: sprintf ( format-string -- result )leaves a string on stackMACRO: printf ( format-string -- quot )leaves nothing on stack despite the stack effect specified  How come `printf` does'n obey its declared stack effect?---=--- Александр  ---=---Александр --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] printf documentation

2018-01-18 Thread Alexander Ilin
O-kay... Let me try to ask my question again... I've read the blog post that you linked to. In there I found the following declaration:`MACRO: printf ( format-string -- )` This means that the macro takes one argument and removes it from the stack, doesn't put anything back. But in the actual source code of the `formatting` vocab the declaration is: `MACRO: printf ( format-string -- quot )`, which looks as if the `printf` word takes one parameter off the stack and puts one item back on the stack. ... which is not true: it doesn't put a quotation on the stack, because it calls the quotation. So, I have two questions, basically: 1) why not change the declaration in `formatting` to ``MACRO: printf ( format-string -- )` - with no output onto the stack?2) are `MACRO:`s allowed to have invalid stack effect declaration? Are they somehow exempted from the compiler checks? I'm asking this because the declared stack effect shows up in the documentation, and is confusing. Reading it gives the _expression_ that it should be used with an extra `call` to the produced quotation:`11 "he%do, world" printf call` 18.01.2018, 19:00, "John Benediktsson" <mrj...@gmail.com>:Both of those are macros (basically special words that produce a quotation), so when "called" they are first macro-expanded into a quotation and then that quotation is called, with whatever stack effect it has. IN: scratchpad 1 2 3 "%s %s %s" printf1 2 3 IN: scratchpad [ "%s %s %s" printf ] infer( x x x -- ) IN: scratchpad [ "%s %s %s" printf ] expand-macros[    [ present ] 2 ndip [ " " ] 2 ndip [ present ] 1 ndip    [ " " ] 1 ndip [ present ] 0 ndip output-stream get    [ stream-write ] curry 5 napply] Maybe the article I wrote when developing it would help: https://re-factor.blogspot.com/2011/08/printf.html  On Thu, Jan 18, 2018 at 4:32 AM, Alexander Ilin <ajs...@yandex.ru> wrote:Hello!  There are two similar words: printf and sprintf. They have similar stack effects, but different behavior.MACRO: sprintf ( format-string -- result )leaves a string on stackMACRO: printf ( format-string -- quot )leaves nothing on stack despite the stack effect specified  How come `printf` does'n obey its declared stack effect?---=--- Александр  ---=---Александр --
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] printf documentation

2018-01-18 Thread Alexander Ilin
Hello!

  There are two similar words: printf and sprintf. They have similar stack 
effects, but different behavior.

MACRO: sprintf ( format-string -- result )
leaves a string on stack

MACRO: printf ( format-string -- quot )
leaves nothing on stack despite the stack effect specified 

  How come `printf` does'n obey its declared stack effect?

---=--- 
 Александр


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

2018-01-17 Thread Alexander Ilin
Hello, Björn! Thanks for the explanation! I've already lost hope of seeing a reply to that, but you appeared out of nowhere and saved the day. Thank you! Are you saying there was a different (better?) optimizer in the previous Factor releases? What happened to it? 17.01.2018, 22:25, "Björn Lindqvist" : r14 contains the datastack top pointer. It is incremented by 0x10 which is 16 bytes or 2 cells. Your code was supposed to put two items on the stack, but then the optimizer did a great job and noticed that the values didn't have to be put on the stack but could be kept in registers. But it didn't optimize away the stack increment/decrement. Possibly, the optimizer in 0.96 or 0.97 did a better job at optimizing code like that.  ---=---Александр --
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] Secure Memory

2018-01-17 Thread Alexander Ilin
Doug and Björn, I'd like to point out the following use case for your consideration, and then you can tell me if the selective zeroing of sensitive memory buffers by the GC makes sense. Some sensitive data is stored in a networked application (let's say, a Web Server with its security certificates).The data in the application is surrounded with some `with-destructors` combinators that will clear it when it's no longer needed.But - the GC comes along and relocates the sensitive data in memory by copying it and not erasing it in the old place. The old location is marked as free memory. Now I assume that there is a way in Factor to allocate a `byte-array` without initializing the memory. This means that by requesting enough "free" memory from the runtime we will at some point get a hold of the block containing the released copy of the sensitive data. This is a problem, especially if our application is downloading and running scripts from the network, like, say, a Web Browser would do all the time. That combination of not clearing the memory on release and not clearing the memory on allocation (both expensive things to do if you do them all the time) creates the potential for the leakage.Adding a single bit flag that would tell GC to zero a particular object's memory on release (or reallocation) would be a great security feature, I think. Not a global command-line argument, but a per-object-instance flag.What do you think? Does it make sense? Is it difficult to implement? As to the Java finalizers argument - I'm not suggesting to rely on GC for the cleanup, as indeed it may never happen. I'd only want it not to leave old copies of some specific buffers hanging around when it's done its invisible (to the application code) magic. 17.01.2018, 22:40, "Doug Coleman" <doug.cole...@gmail.com>:We actually had a command-line argument to the vm to optionally zero the gc after collection but we removed the feature somewhere around when we dropped BSD support. It's probably better than nothing but if they could read your memory after a gc why not just read it before gc instead? Doug On Wed, Jan 17, 2018 at 1:34 PM Björn Lindqvist <bjou...@gmail.com> wrote:Factor when run in debug mode actually clears memory. See bump_allocator.hpp. Unfortunately clearing memory is slow as hell. The time complexity of copying gc is proportional to the number of surviving objects. But if you want to clear memory too it becomes proportional to the total number of allocated objects.  Plus, relying on the gc to zero out sensitive memory is a bad idea. You never know when the gc runs or if it runs at all. That's why it is considered bad practice in Java to use finalizers. I think it would be better to use the destructors vocab to implement zeroing out of sensitive memory.     2018-01-16 23:17 GMT+01:00 Alexander Ilin <ajs...@yandex.ru>:Hello!  I was reading a manual on the `8th` language, and noticed an interesting feature.  Apparently, it's possible to call a word on a memory buffer and thereby mark it as "sensitive information".  GC would zero the memory upon release.  Zeroing every bit of memory on release would add a lot of overhead (as I understand), but selectively clearing it like this could help with security applications that deal with certificates and passwords and stuff. This is especially useful, because in Factor GC can relocate (= copy) objects in memory. Does it clean up the memory it copied?  Do we have such a feature? Is it difficult to implement?  Bjourne, you've seen a lot of the runtime, can you comment?---=--- Александр--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  --mvh/best regards Björn Lindqvist--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] Secure Memory

2018-01-16 Thread Alexander Ilin
Hello!

  I was reading a manual on the `8th` language, and noticed an interesting 
feature.
  Apparently, it's possible to call a word on a memory buffer and thereby mark 
it as "sensitive information".
  GC would zero the memory upon release.

  Zeroing every bit of memory on release would add a lot of overhead (as I 
understand), but selectively clearing it like this could help with security 
applications that deal with certificates and passwords and stuff. This is 
especially useful, because in Factor GC can relocate (= copy) objects in 
memory. Does it clean up the memory it copied?

  Do we have such a feature? Is it difficult to implement?
  Bjourne, you've seen a lot of the runtime, can you comment?

---=--- 
 Александр

--
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] concurrency.distributed under Windows

2018-01-07 Thread Alexander Ilin
Hello! 08.01.2018, 02:41, "John Benediktsson" :If you look at ``M\ remote-thread send``, it uses ``send-remote-message`` which opens a TCP connection using ``with-client``, which sends a message, then closes the connection. The code is 10's of lines to implement concurrency.distributed so I'm sure you could modify it in minor ways to be specific to your application and maybe useful to contribute back.   Thank you for believing in me! I think I'll give it a shot while I still have some holiday time left. If you need to get more familiar with network programming, I recommend Beej's guide: https://beej.us/guide/bgnet/ Huh? I'd better read the ZeroMQ manual, seems roughly the same volume. ---=---Александр --
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] concurrency.distributed under Windows

2018-01-07 Thread Alexander Ilin
> So, it doesn't seem to be a runaway buffer issue, unless Factor does 
> something completely wrong, like peeking in the buffer and never removing 
> messages from it.

  Also, is it OK that I'm seeing hundreds of TCP connections being made between 
the processes?
  It seems like every individual message is sent in a separate connection, 
which brought up and then torn down instantly.

  I would expect a longer-lived TCP channel to be established, but what do I 
know about how networks (and Factor) work...

---=--- 
 Александр

--
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] concurrency.distributed under Windows

2018-01-07 Thread Alexander Ilin
Hello!

07.01.2018, 07:21, "Chris Double" <chris.dou...@double.co.nz>:
> On Sat, Jan 6, 2018 at 1:18 PM, Alexander Ilin <ajs...@yandex.ru> wrote:
>>  It seems that I overloaded the system somehow, but I don't see me doing 
>> anything illegal. Can you guys help me figure out what's going on?
>
> I suspect you are overloading the network stack on your machine since
> you are sending data as fast as possible and receiving it as fast as
> possible. Maybe the sender is getting ahead of the receiver and
> queuing more data in the network stack over time. Try adding a delay
> in the sender and see if that improves things.

Thank you for the suggestion!

OK, may be the sender was getting ahead of the receiver and overflooded the 
network stack buffers in the previous example. (I would have expected a 
different error message text in that case, but maybe that's what you get.) Here 
is a modified version of the same code, this time using send-synchronous and 
reply-synchronous. There is no way to overflood the network buffers in this 
code, because the two processes are moving in lockstep, exchanging one message 
at a time and waiting for the other to respond before sending anything.

Factor instance 1 (codename "Blackhole"):

USING: concurrency.distributed concurrency.messaging io.servers threads ;
9010 local-server start-node [
[ receive t swap reply-synchronous t ] loop
] "black-hole" [ spawn ] keep register-remote-thread

Factor instance 2 (codename "Pulsar"):

USING: concurrency.distributed concurrency.messaging io.servers ;
9011 local-server start-node ! a port to receive synchronous replies
9010 local-server "black-hole" 
[ f swap send-synchronous drop t ] curry loop

Unfortunately, the resulting behavior is the same. For about 14 seconds both 
instances run at 100% CPU, then both run at about 50% CPU, and after 60 seconds 
from the experiment start the same error string is thrown by the Pulsar:
"You were not connected because a duplicate name exists on the network. If 
joining a domain, go to System in Control Panel to change the computer name and 
try again. If joining a workgroup, choose another workgroup name."

So, it doesn't seem to be a runaway buffer issue, unless Factor does something 
completely wrong, like peeking in the buffer and never removing messages from 
it.

---=--- 
 Александр

--
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] concurrency.distributed under Windows

2018-01-05 Thread Alexander Ilin
Hello!

  I'm having further issues with the `concurrency.distributed` vocab. I was 
trying to pass some data between two Factor instances, but failed, even though 
the total data volume was about 2Mb. After spending some considerable time 
debugging my code (because I'm only learning to use this vocab) I found that 
the following code reproduces the issue.

Factor instance 1 (codename "Blackhole"):

USING: concurrency.distributed concurrency.messaging io.servers threads ;
9010 local-server start-node
[ [ receive drop t ] loop ] "black-hole" [ spawn ] keep register-remote-thread

Factor instance 2 (codename redacted):

USING: concurrency.distributed concurrency.messaging io.servers ;
9010 local-server "black-hole" 
[ f swap send t ] curry loop

For about 10 seconds from the start of the loop in instance 2 both Factor 
processes consume 100% of a CPU core each. After about 10 seconds the CPU use 
by the Blackhole drops to an idle value, while instance 2 keep going full speed.

After another 50 seconds (about one minute since the start of the experiment) 
the second instance throws the following string:
"You were not connected because a duplicate name exists on the network. If 
joining a domain, go to System in Control Panel to change the computer name and 
try again. If joining a workgroup, choose another workgroup name."

It seems that I overloaded the system somehow, but I don't see me doing 
anything illegal. Can you guys help me figure out what's going on?

  OS: Windows 10x64.

---=--- 
 Александр

--
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] db.tuples in threads

2017-12-29 Thread Alexander Ilin
Hello!

  I have figured out what the issue with `no-defined-persistent` was.
  Turns out I called `object ensure-table` instead of `object class-of 
ensure-table`.

29.12.2017, 02:45, "Alexander Ilin" <ajs...@yandex.ru>:
> Understood, thank you, Chris!
>
> In the end I used a promise, which is almost the same thing.
>
> I have another question, though.
>
> Is it possible to use the facilities offered by the db.tuples vocab from 
> within a thread?
>
> When I try to call `ensure-table`, I get the `no-defined-persistent` 
> exception, even if I call `define-persistent` on the same class earlier in 
> the same thread.
>
> Is this a principal limitation, or it should be possible and I'm doing 
> something wrong? I can post a minimal example code if it helps.
>
> 21.12.2017, 01:44, "Chris Double" <chris.dou...@double.co.nz>:
>>  The easiest way might be to use futures:
>>  http://docs.factorcode.org/content/article-concurrency.futures.html
>>
>>  eg:
>>
>>  [ 42 ] future ?future .
>>  => 42
>>
>>  On Thu, Dec 21, 2017 at 10:44 AM, Alexander Ilin <ajs...@yandex.ru> wrote:
>>>   Hello!
>>>
>>> If I spawn a thread using the threads:spawn word, is there a way to 
>>> wait for the thread to finish its work?
>>> I need something like WaitForSingleObject(ThreadHandle, INFINITE).
>
> ---=---
>  Александр
>
> --
> 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] db.tuples in threads

2017-12-28 Thread Alexander Ilin
Understood, thank you, Chris!

In the end I used a promise, which is almost the same thing.

I have another question, though.

Is it possible to use the facilities offered by the db.tuples vocab from within 
a thread?

When I try to call `ensure-table`, I get the `no-defined-persistent` exception, 
even if I call `define-persistent` on the same class earlier in the same thread.

Is this a principal limitation, or it should be possible and I'm doing 
something wrong? I can post a minimal example code if it helps.

21.12.2017, 01:44, "Chris Double" <chris.dou...@double.co.nz>:
> The easiest way might be to use futures:
> http://docs.factorcode.org/content/article-concurrency.futures.html
>
> eg:
>
> [ 42 ] future ?future .
> => 42
>
> On Thu, Dec 21, 2017 at 10:44 AM, Alexander Ilin <ajs...@yandex.ru> wrote:
>>  Hello!
>>
>>    If I spawn a thread using the threads:spawn word, is there a way to wait 
>> for the thread to finish its work?
>>    I need something like WaitForSingleObject(ThreadHandle, INFINITE).

---=--- 
 Александр

--
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] Wait for Thread

2017-12-20 Thread Alexander Ilin
Hello!

  If I spawn a thread using the threads:spawn word, is there a way to wait for 
the thread to finish its work?
  I need something like WaitForSingleObject(ThreadHandle, INFINITE).

---=--- 
 Александр

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

2017-10-12 Thread Alexander Ilin

Hello!

  I'm trying to make sense of some disassembled code. Could someone help me out 
here?

```
IN: scratchpad [ 256  [ drop ] each ] disassemble
001a8dbcdfc0: 89053a30e8fe  mov [rip-0x117cfc6], eax ! What's 
this?
001a8dbcdfc6: b80001mov eax, 0x100
001a8dbcdfcb: 31db  xor ebx, ebx
001a8dbcdfcd: 4983c610  add r14, 0x10
001a8dbcdfd1: e90900jmp 0x1a8dbcdfdf (( gensym ) + 0x1f)
001a8dbcdfd6: 48ffc3inc rbx
001a8dbcdfd9: 89052130e8fe  mov [rip-0x117cfdf], eax ! What's 
this?
001a8dbcdfdf: 4839c3cmp rbx, rax
001a8dbcdfe2: 0f8ceeff  jl dword 0x1a8dbcdfd6 (( gensym ) + 0x16)
001a8dbcdfe8: 4983ee10  sub r14, 0x10
001a8dbcdfec: 89050e30e8fe  mov [rip-0x117cff2], eax ! What's 
this?
001a8dbcdff2: c3ret 
001a8dbcdff3:   add [rax], al
001a8dbcdff5:   add [rax], al
001a8dbcdff7:   add [rax], al
001a8dbcdff9:   add [rax], al
001a8dbcdffb:   add [rax], al
001a8dbcdffd:   add [rax], al
001a8dbcdfff: 00invalid 
```

  The lines like `mov [rip-0x117cfdf], eax` I read as "copy the contents of the 
EAX register to a memory location pointed to by a memory address relative to 
the current Instruction Pointer register (rIP)". Am I right? If so, why is that 
being done inside the loop, and twice at the procedure entry and exit?

  Also, why is the register r14 incremented by 0x10 on entry, and decremented 
on exit? What is r14 used for?

---=--- 
 Александр

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

2017-10-08 Thread Alexander Ilin
Hello, John! 08.10.2017, 07:46, "John Benediktsson" :Regarding unsafe-amb.  You should use ``amb-lazy`` in compiled words.  Here's a simple version that prints all solutions. As I said, a perfect solution! Thanks for the `amb-lazy` hint. ---=---Александр 

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

2017-10-08 Thread Alexander Ilin
Hello, Alston! 08.10.2017, 06:55, "CW Alston" :The solution to the puzzle that I wrote doesn't use `amb`. I approached the problemwith `math.combinatorics` & `math.ranges` instead, so I'm not much help there.But I had to wrestle with the same conundrum, regarding compilation in the Listenerversus source file compilation. See if the example helps. I posted the (brief) sourcefile below.   I like your approach using ``, because it tests fewer combinations towards a solution.I'd be very interested in an approach using `backtracking`! I think John posted a perfect one. In fact, I first learned about the `backtrack` vocab from his very own blog posts:https://re-factor.blogspot.ru/2015/06/send-more-money.htmlhttps://re-factor.blogspot.ru/2017/02/711.html ---=---Александр --
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] Backtracking

2017-10-08 Thread Alexander Ilin
Thank you for the reply, and for the code suggestions! 08.10.2017, 07:13, "CW Alston" :-for `last3` :IN: scratchpad { 1 2 3 4 5 6 } 3 tail spill-seq ! or something like it In fact, here's a non-MACRO:-way to do the same:: last3 ( seq -- X Y Z )3 cut* nip first3 ; inline ! --for `6array` :IN: scratchpad 5 6 7 8 9 10  6 narray Thanks, I forgot all about `narray`! ! - is undefined in Factor Version 0.98; should use `iota`.I didn't find  anywhere in `sequences` or its child-vocabs.(I'm running factor-macosx-x86-64-2017-05-14-20-08.dmg): I'm on the bleeding edge, you see. They've renamed `iota` to `` and `iota-tuple` to `iota`. ---=---Александр --
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] Backtracking

2017-10-06 Thread Alexander Ilin
Hello!

  I found a perfect task to learn the `backtrack` vocab, and have successfully 
solved the problem (although the help system could use some example code). The 
only question I have left is why can't I compile the vocab below. I get the 
error that says "Cannot apply “unsafe-amb” to a run-time computed value" in the 
`solve` word. It works perfectly well in the listener, so why can't it work in 
a vocab?

  Could someone point out the reason for the error? Which part of the quotation 
is run-time computed? I have inlined everything I could, but it didn't help.

```
! Copyright (C) 2017 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
USING:
arrays backtrack combinators.short-circuit infix kernel
locals math math.functions prettyprint scratchpad
sequences sequences.private sets
;

IN: andrew-task

! The task is to find digits A, B, C, D, E, and F, such that:
! all digits are 1..9,
! all of the digits are different,
! D < E < F,
! ABC*D*EE*FFF = n^2, where n is an integer.

ALIAS: 0? zero?

: last3 ( seq -- X Y Z )
unclip-last [ unclip-last [ last ] dip ] dip ; inline

: 6array ( A B C D E F -- {ABCDEF} )
4array swap prefix swap prefix ; inline

: check-success ( {ABCDEF} -- )
{
[ [ 0? ] count 0? ]
[ duplicates empty? ]
[ last3 [| D E F | D E < E F < and ] call ]
[
[ first3 ] [ last3 ] bi
[| A B C D E F |
[infix A * 100 + B * 10 + C infix] :> ABC
11  E * :> EE
111 F * :> FFF
{ ABC D EE FFF } product :> prod
prod sqrt >integer dup * prod =
] call
]
} 1&& must-be-true ; inline

: solve ( -- )
[
10  amb 10  amb 10  amb
10  amb 10  amb 10  amb
6array dup check-success .
] amb-all ;

MAIN: solve
```

---=--- 
 Александр

--
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] unless-global-var

2017-08-23 Thread Alexander Ilin
Actually, a better name might be `do-once`, or `with-guard-var`, or similar.

23.08.2017, 13:30, "Alexander Ilin" <ajs...@yandex.ru>:
> Hello!
>
>   I think I came up with a useful word. Don't we already have something of 
> this nature?
>
> : unless-global-var ( guard-variable quot -- )
> dupd '[ t _ set-global @ ] [ get-global ] dip unless ; inline
>
> ---=---
>  Александр
>
> --
> 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


[Factor-talk] unless-global-var

2017-08-23 Thread Alexander Ilin
Hello!

  I think I came up with a useful word. Don't we already have something of this 
nature?

: unless-global-var ( guard-variable quot -- )
dupd '[ t _ set-global @ ] [ get-global ] dip unless ; inline


---=--- 
 Александр

--
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] Build Farm (was: Window Messages)

2017-08-21 Thread Alexander Ilin
Cool, I'll look into it ASAP.

What's the reason for using Travis, then? For kicks?

21.08.2017, 18:17, "John Benediktsson" :
> Yes, we have an entire continuous build system (you can look in 
> `extra/mason`).

---=--- 
 Александр

--
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] Build Farm (was: Window Messages)

2017-08-21 Thread Alexander Ilin
What was doing the builds before Travis? Was it Factor itself? Do we have a Factor implementation of a build farm (like we have a web server)? I'm currently thinking about hosting a Jenking build locally for myself. Does anyone have any experience in that area? 21.08.2017, 16:44, "John Benediktsson" : As far as I know, it's an issue with the win32 instance we are using in the build farm. And it needs to be rebuilt maybe.  I wanted to ping Doug about that after solar eclipse mania settles down and see what I can do to help also.  We started getting Travis builds working but it's not setup to upload development snapshots yet.  Best,John. ---=---Александр 

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


  1   2   3   4   >