Re: [Factor-talk] supremum

2017-06-21 Thread Alex Vondrak
Technically that case would be a matter of `supremum` handling empty
arrays, not `f` elements per se.

On Jun 21, 2017 8:48 AM, "Alexander Ilin"  wrote:

```
{ f f f f } sift supremum
-> error is thrown
```

21.06.2017, 18:44, "Alex Vondrak" :

Or you could call `sift supremum`: http://docs.factorcode.org/content/word-
sift,sequences.html

Might be instructive to give the codebase a search, see how often that
pattern is used. (Can't do it myself right now - on mobile.)

On Jun 21, 2017 8:39 AM, "Alexander Ilin"  wrote:

Hello!

  How would you like if `supremum` tolerated the `f` elements?

  Now:
```
   { f 0 1 2 } supremum
  -> error is thrown

   { f f f f } supremum
  -> error is thrown
```

  Proposition:
```
   { f 0 1 2 } supremum
  -> 2

   { f f f f } supremum
  -> f
```

  Current code:
```
: supremum ( seq -- elt )
[ ] [ max ] map-reduce ;
```

  Proposed code:
```
: supremum ( seq -- elt )
[ ] [ 2dup and [ max ] [ dupd ? ] if ] map-reduce ;
```

  If you like what you are seeing, I'll make a formal PRoposal.

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


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

,


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
,

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



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



--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] supremum

2017-06-21 Thread Alex Vondrak
Or you could call `sift supremum`:
http://docs.factorcode.org/content/word-sift,sequences.html

Might be instructive to give the codebase a search, see how often that
pattern is used. (Can't do it myself right now - on mobile.)

On Jun 21, 2017 8:39 AM, "Alexander Ilin"  wrote:

> Hello!
>
>   How would you like if `supremum` tolerated the `f` elements?
>
>   Now:
> ```
>{ f 0 1 2 } supremum
>   -> error is thrown
>
>{ f f f f } supremum
>   -> error is thrown
> ```
>
>   Proposition:
> ```
>{ f 0 1 2 } supremum
>   -> 2
>
>{ f f f f } supremum
>   -> f
> ```
>
>   Current code:
> ```
> : supremum ( seq -- elt )
> [ ] [ max ] map-reduce ;
> ```
>
>   Proposed code:
> ```
> : supremum ( seq -- elt )
> [ ] [ 2dup and [ max ] [ dupd ? ] if ] map-reduce ;
> ```
>
>   If you like what you are seeing, I'll make a formal PRoposal.
>
> ---=---
>  Александр
>
> 
> --
> 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 Code Analysis Tools

2016-05-25 Thread Alex Vondrak
In case it helps, here's an ancient gist of mine where I did some basic
vocab dependency analysis: https://gist.github.com/ajvondrak/4158963 This
was to find circular dependencies, where loading the vocab would go into an
infinite loop. Thus I couldn't use the loaded vocab objects themselves, so
instead looked at the text of the file, which isn't necessarily accurate. I
also haven't tested this since writing it, so not sure if it still works on
the latest Factor.
On May 25, 2016 6:01 AM, "Alexander Ilin"  wrote:

> Hello!
>
> That's great, John, thanks for the pointer!
>
> 25.05.2016, 00:57, "John Benediktsson" :
>
> You can easily get usage information, for example all (loaded) words that
> call ``+``:
>
> \ + usage.
>
> There are some graphviz libraries that have been built to visualize
> various parts of the compiler and either already can, or with some work,
> use the tools.crossref vocabulary to look at word and vocab dependencies.
>
>
>
> ---=---
> Александр
>
>
>
> --
> Mobile security can be enabling, not merely restricting. Employees who
> bring their own devices (BYOD) to work are irked by the imposition of MDM
> restrictions. Mobile Device Manager Plus allows you to control only the
> apps on BYO-devices by containerizing them, leaving personal data
> untouched!
> https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] how to run-pipeline

2015-09-23 Thread Alex Vondrak
>
> Your suggestion in another email of implementing >process looks
> interesting to explore.
> Any example usage in this case ?
>

Not really, I'm afraid. The only two implemented methods are here:
https://github.com/slavapestov/factor/blob/master/basis/io/launcher/launcher.factor#L118-L122
It shouldn't be too hard to define your own >process for your special class
that would serialize a string/array then call >process on that
string/array. In fact, it could probably just look like

M: cmd >process cmd>string >process ;

where you implement cmd>string accordingly.

You might still be able to go the `make` route, since strings and arrays
are already launch descriptors (
http://docs.factorcode.org/content/article-io.launcher.descriptors.html)
that will work when wrapped in processes. Since strings are sequences,
`make` can build them too. For example,
https://github.com/slavapestov/factor/blob/master/basis/csv/csv.factor#L33-L34
Notice from that example that `,` and `%` are called from separate words:

https://github.com/slavapestov/factor/blob/master/basis/csv/csv.factor#L23
https://github.com/slavapestov/factor/blob/master/basis/csv/csv.factor#L26
https://github.com/slavapestov/factor/blob/master/basis/csv/csv.factor#L31

Since `make` builds the sequence in a dynamically scoped variable, you can
split up your calls to `,` and `%` across your own factored out words, and
even have nested calls to `make`:

IN: scratchpad USE: make
IN: scratchpad : a, ( -- ) CHAR: a , ;
IN: scratchpad : b, ( -- ) CHAR: b , ;
IN: scratchpad : c, ( -- ) CHAR: c , ;
IN: scratchpad : make-string ( -- str ) [ a, b, c, ] "" make ;
IN: scratchpad : string, ( -- ) make-string , ;
IN: scratchpad [ string, a, string, b, string, c, ] { } make .
{ "abc" 97 "abc" 98 "abc" 99 }

(1) invoke custom command in shell:  cmd1 -a A -b B
>  The result is printed out to stdout.
> (2) Take the output of (1) and select (or manipulate) the lines
>   And print them to stdout
> (3) invoke another custom command: cmd2 -c C…
>

Ah, that makes more sense, thanks. I'm glad you found out that you can use
quotations in `run-pipeline` - I didn't even known that! So I learned
something. :)

My original issue was to construct the string “cmd1 -a A -b B” and “cmd2 -c
> C”
> in a flexible way so that I can choose to supply (or not supply) those
> argument A, B, C.
> And find a clean way to put everything together into { … } for
> run-pipeline.
>

Ah, yes, optional arguments are an interesting case. Given those
constraints, your  objects may indeed be the best way of constructing
the individual "cmd -flag1 value1 ..." strings, rather than `make`-ing raw
strings. Although `make` might still be useful for building the array
that's passed to `run-pipeline`.

Let us know how it goes!


On Tue, Sep 22, 2015 at 8:46 PM, HP Wei  wrote:

> Thanks, Alex, for pointing out the the ‘make’ word, which is something new
> to me.
> I will study the example usages that you listed.
>
> 
>
> I realize that I did not make my original intention clear enough.
> Here is what I want to do in factor:
>
> (1) invoke custom command in shell:  cmd1 -a A -b B
>  The result is printed out to stdout.
> (2) Take the output of (1) and select (or manipulate) the lines
>   And print them to stdout
> (3) invoke another custom command: cmd2 -c C…
>
> So, in factor, from what I leaned so far, to accomplish the above I can do
>
> { “cmd1 -a A -b B” [ quot ] “cmd2 -c C” } run-pipeline
>
> My original issue was to construct the string “cmd1 -a A -b B” and “cmd2
> -c C”
> in a flexible way so that I can choose to supply (or not supply) those
> argument A, B, C.
> And find a clean way to put everything together into { … } for
> run-pipeline.
>
> By the way,
> Your suggestion in another email of implementing >process looks
> interesting to explore.
> Any example usage in this case ?
>
> Thanks
> HP
>
>
> On Sep 22, 2015, at 12:23 PM, Alex Vondrak  wrote:
>
> Ultimately, I may also insert some factor quot in betweeen
>> str1 and str2 to do some processing before handing the
>> result to cmd2.
>
>
> Do you mean you want to take the output of running cmd1, manipulate it,
> then pass *that* to cmd2? Because that sounds rather different from what
> your example code looks like it's actually trying to do.
>
> It seems like your example is trying to construct launch descriptors
> independently, then pass those entire results to run-pipeline at once.
> Which is altogether easier: if I understand right, you're basically there
> already, but your main concern is more about how to build the array in a
> prettier way? If that's it, I suggest the `make` vocabulary:
> http:

Re: [Factor-talk] how to run-pipeline

2015-09-22 Thread Alex Vondrak
You might also consider implementing the >process method for your custom
 /  objects, which will be called automatically when invoking
run-pipeline.
http://docs.factorcode.org/content/word-__gt__process,io.launcher.html Or
just do away with  /  objects altogether and build those as
strings/arrays with `make`, too.

On Tue, Sep 22, 2015 at 9:23 AM, Alex Vondrak  wrote:

> Ultimately, I may also insert some factor quot in betweeen
>> str1 and str2 to do some processing before handing the
>> result to cmd2.
>
>
> Do you mean you want to take the output of running cmd1, manipulate it,
> then pass *that* to cmd2? Because that sounds rather different from what
> your example code looks like it's actually trying to do.
>
> It seems like your example is trying to construct launch descriptors
> independently, then pass those entire results to run-pipeline at once.
> Which is altogether easier: if I understand right, you're basically there
> already, but your main concern is more about how to build the array in a
> prettier way? If that's it, I suggest the `make` vocabulary:
> http://docs.factorcode.org/content/article-namespaces-make.html
>
> Some examples of `make` usage in the wild:
>
> https://github.com/slavapestov/factor/blob/master/basis/io/backend/unix/unix-tests.factor#L142-L147
>
> https://github.com/slavapestov/factor/blob/master/basis/bootstrap/image/upload/upload.factor#L47-L51
>
> https://github.com/slavapestov/factor/blob/master/extra/graphviz/render/render.factor#L62-L67
>
> Granted, all of those are building a single process, not a pipeline. But
> the same principles apply:
>
> : cmd1 ( -- ) ... ;
> : cmd2 ( -- ) ... ;
>
> [ cmd1 , cmd2 , ] { } make run-pipeline
>
>
> On Mon, Sep 21, 2015 at 9:21 PM, HP Wei  wrote:
>
>> I want to run binary codes (C++) under linux using run-pipeline
>>
>> In linux shell, the task is
>>
>> cmd1 -a arg1 -b arg2 | cmd2 -c arg3
>>
>> I know in general, in factor, I need to construct
>>
>> { str1  str2 } run-pipeline
>> where str1 = “cmd1 -a arg1 -b arg2”
>>str2 = “cmd2 -c arg3”
>> Ultimately, I may also insert some factor quot in betweeen
>> str1 and str2 to do some processing before handing the
>> result to cmd2.
>>
>>
>> Here is what I envision:
>>
>> TUPLE: cmd1 a b ;
>>
>> :  ( — cmd1 )
>> cmd1 new
>> “default a” >>a
>> “default b” >>b ;
>>
>> : get-cmd1 ( cmd1 — str1 )
>>[ a>> ] [ b>> ] bi
>>“cmd1 -a %s -b %s” sprintf  ;
>>
>> so now, I can write
>>
>> 
>>my_b >>b
>> get-cmd1
>>
>> — similarly for cmd2.
>>
>> But I bump into a mental block when trying to
>> put things together for run-pipeline
>>
>> If there were just one cmd1 (without cmd2),
>> I thought I could do
>>
>> ${  my_b >>b get-cmd1 } run-pipeline
>>
>> Adding cmd2, I could write
>>
>> ${  my_b >>b get-cmd1   my_c >>c get-cmd2 } run-pipeline
>>
>> But this looks ugly.
>> Is there a simpler way ?
>>
>> Thanks
>> HP Wei
>>
>>
>>
>>
>> --
>> ___
>> 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] how to run-pipeline

2015-09-22 Thread Alex Vondrak
>
> Ultimately, I may also insert some factor quot in betweeen
> str1 and str2 to do some processing before handing the
> result to cmd2.


Do you mean you want to take the output of running cmd1, manipulate it,
then pass *that* to cmd2? Because that sounds rather different from what
your example code looks like it's actually trying to do.

It seems like your example is trying to construct launch descriptors
independently, then pass those entire results to run-pipeline at once.
Which is altogether easier: if I understand right, you're basically there
already, but your main concern is more about how to build the array in a
prettier way? If that's it, I suggest the `make` vocabulary:
http://docs.factorcode.org/content/article-namespaces-make.html

Some examples of `make` usage in the wild:
https://github.com/slavapestov/factor/blob/master/basis/io/backend/unix/unix-tests.factor#L142-L147
https://github.com/slavapestov/factor/blob/master/basis/bootstrap/image/upload/upload.factor#L47-L51
https://github.com/slavapestov/factor/blob/master/extra/graphviz/render/render.factor#L62-L67

Granted, all of those are building a single process, not a pipeline. But
the same principles apply:

: cmd1 ( -- ) ... ;
: cmd2 ( -- ) ... ;

[ cmd1 , cmd2 , ] { } make run-pipeline

On Mon, Sep 21, 2015 at 9:21 PM, HP Wei  wrote:

> I want to run binary codes (C++) under linux using run-pipeline
>
> In linux shell, the task is
>
> cmd1 -a arg1 -b arg2 | cmd2 -c arg3
>
> I know in general, in factor, I need to construct
>
> { str1  str2 } run-pipeline
> where str1 = “cmd1 -a arg1 -b arg2”
>str2 = “cmd2 -c arg3”
> Ultimately, I may also insert some factor quot in betweeen
> str1 and str2 to do some processing before handing the
> result to cmd2.
>
>
> Here is what I envision:
>
> TUPLE: cmd1 a b ;
>
> :  ( — cmd1 )
> cmd1 new
> “default a” >>a
> “default b” >>b ;
>
> : get-cmd1 ( cmd1 — str1 )
>[ a>> ] [ b>> ] bi
>“cmd1 -a %s -b %s” sprintf  ;
>
> so now, I can write
>
> 
>my_b >>b
> get-cmd1
>
> — similarly for cmd2.
>
> But I bump into a mental block when trying to
> put things together for run-pipeline
>
> If there were just one cmd1 (without cmd2),
> I thought I could do
>
> ${  my_b >>b get-cmd1 } run-pipeline
>
> Adding cmd2, I could write
>
> ${  my_b >>b get-cmd1   my_c >>c get-cmd2 } run-pipeline
>
> But this looks ugly.
> Is there a simpler way ?
>
> Thanks
> HP Wei
>
>
>
>
> --
> ___
> 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] Graphviz

2015-09-17 Thread Alex Vondrak
Also worth noting again that compiler.graphviz isn't the most interesting
library. Like John said, you're probably looking for just `graphviz` (in
extra/graphviz). compiler.graphviz was some quickie utility written by
Slava to show the overall shape of the control flow graph. The reason it's
marked Unix-only was indeed because of its association with the busted
graphviz vocabulary (
https://github.com/slavapestov/factor/commit/ece7a4177ad519ed2d88d33b97116e1c80ed5040)
even though it doesn't really *use* the graphviz vocab (it does now in a
minor way, but not when that platforms.txt was added). It just manually
constructs DOT files and makes calls to system binaries. Indeed, it's
"Unix-only" in another way, since it hard-codes a call to `open`, an OSX
command---pretty sure Slava was basically just whipping up the library for
personal development on his Mac.

I wrote compiler.cfg.graphviz using the graphviz vocab to generate graphs
that actually show the intermediate representation's instructions (e.g.,
https://github.com/ajvondrak/thesis/blob/master/examples/gvn/0-build-cfg.svg).
Also not the most interesting, unless you're working with the compiler. Fun
story: tried to `USE: compiler.cfg.graphviz` just now, got some endless
loop of error windows that crashed my X11 session. But that's debugging for
another day, I'm afraid. :)


On Thu, Sep 17, 2015 at 7:25 AM, Alex Vondrak  wrote:

> Is Alex Vondrak on the list?
>
>
> Am I ever! Though you couldn't tell by looking... ;)
>
> Would he be able to comment on how important that function is, and if we
>> could work without it?
>>
>
> Looks like you're running a very old version of the graphviz library that
> used the Graphviz API through Factor's FFI. That turned out to have
> headaches, so the library was reworked to instead spit out DOT code & call
> your platform's graphviz executable:
> https://github.com/slavapestov/factor/issues/724
>
>
> On Thu, Sep 17, 2015 at 4:49 AM, Alexander Ilin  wrote:
>
>> Hello!
>>
>>   Thanks for the explanation.
>>
>> 17.09.2015, 14:22, "John Benediktsson" :
>> > Vocabularies can have a platforms.txt file that has a list of OS that
>> it supports. If the platforms.txt file is not specified, we assume it runs
>> everywhere.
>>
>> > The "graphviz" vocabulary is probably the one you want and does work on
>> Windows and does not specify a platforms.txt.
>>
>>   Ignoring the platform restriction errors (by clicking Continue) works
>> up to a point.
>>   Unfortunately, I found this comment in the source:
>> ! This function doesn't exist on the Windows mason in Graphviz 2.28
>>
>>   And, indeed, gvplugin_list is not present in gvc.dll.
>>   Not sure how to proceed from here. Is Alex Vondrak on the list? Would
>> he be able to comment on how important that function is, and if we could
>> work without it?
>>
>> ---=---
>>  Александр
>>
>>
>> --
>> Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
>> Get real-time metrics from all of your servers, apps and tools
>> in one place.
>> SourceForge users - Click here to start your Free Trial of Datadog now!
>> http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
>
--
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Graphviz

2015-09-17 Thread Alex Vondrak
>
> Is Alex Vondrak on the list?


Am I ever! Though you couldn't tell by looking... ;)

Would he be able to comment on how important that function is, and if we
> could work without it?
>

Looks like you're running a very old version of the graphviz library that
used the Graphviz API through Factor's FFI. That turned out to have
headaches, so the library was reworked to instead spit out DOT code & call
your platform's graphviz executable:
https://github.com/slavapestov/factor/issues/724


On Thu, Sep 17, 2015 at 4:49 AM, Alexander Ilin  wrote:

> Hello!
>
>   Thanks for the explanation.
>
> 17.09.2015, 14:22, "John Benediktsson" :
> > Vocabularies can have a platforms.txt file that has a list of OS that it
> supports. If the platforms.txt file is not specified, we assume it runs
> everywhere.
>
> > The "graphviz" vocabulary is probably the one you want and does work on
> Windows and does not specify a platforms.txt.
>
>   Ignoring the platform restriction errors (by clicking Continue) works up
> to a point.
>   Unfortunately, I found this comment in the source:
> ! This function doesn't exist on the Windows mason in Graphviz 2.28
>
>   And, indeed, gvplugin_list is not present in gvc.dll.
>   Not sure how to proceed from here. Is Alex Vondrak on the list? Would he
> be able to comment on how important that function is, and if we could work
> without it?
>
> ---=---
>  Александр
>
>
> --
> Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
> Get real-time metrics from all of your servers, apps and tools
> in one place.
> SourceForge users - Click here to start your Free Trial of Datadog now!
> http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Several questions about Factor compiler

2015-02-28 Thread Alex Vondrak
As far as I understand it:
1. The optimizing compiler (written in Factor) generates raw machine code
that is saved in an "image file":
http://docs.factorcode.org/content/article-images.html (more about the
voodoo of bootstrapping image files:
http://factor-language.blogspot.com/2010/01/factors-bootstrap-process-explained.html
)
2. The VM's job is to load & execute the image file contents, along with
handling primitve stuff like garbage collection. When installing Factor,
you'll compile the C++ VM into a binary on your machine (check out the
Makefile: https://github.com/slavapestov/factor/blob/master/GNUmakefile).
3. To generate a standalone executable, you use the tools.deploy
vocabulary: http://docs.factorcode.org/content/article-tools.deploy.html
This creates a binary by embedding the image file of your compiled code
into the compiled VM executable. I'm fuzzy on the details, but it seems to
just straight-up copy the contents of the binary image file into a "magic"
spot where the VM executable will know to look:
https://github.com/slavapestov/factor/blob/fe2c2d23de9e300d7cd1b04e139dfbdd2069d00a/vm/image.hpp
&
https://github.com/slavapestov/factor/blob/master/basis/tools/deploy/embed/embed.factor
The deploy tool does some other fancy stuff, like trying to minimize the
total image size using the "shaker":
http://factor-language.blogspot.com/2007/06/generating-minimal-images-deploying.html

So, short answer: Factor's standalone executables are copies of the VM
executable (itself fairly small) + your compiled code.

Hope that helps,
--Alex Vondrak

On Sat, Feb 28, 2015 at 2:15 PM,  wrote:

> Hello! I'm very interested in Factor. I don't quite understand how
> Factor's native code compiler works, so I'd like to ask some questions
> about it. Can factor code run on bare metal (without operating system)? How
> does the compiler generate standalone executables? Factor has a VM code
> written in C++, how does the compiler links C++ code with compiled Factor
> code? Or the VM is only used in Factor's interactive tools and all the code
> that gets compiled into standalone executable is written in Factor? If so
> how is low level stuff like GC can be implemented in Factor code?
>
> --
> Dive into the World of Parallel Programming The Go Parallel Website,
> sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for
> all
> things parallel software development, from weekly thought leadership blogs
> to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] ! Comments

2015-01-29 Thread Alex Vondrak
See also: https://github.com/slavapestov/factor/issues/737

On Thu, Jan 29, 2015 at 6:35 AM, John Benediktsson  wrote:

> Right now the comment character is not hard-coded in the lexer which
> causes us to discover poor errors like this one in some syntax words that
> aren't "comment-aware". There are a couple others we are planning on fixing
> also. Maybe you can add your test case to this issue:
>
> https://github.com/slavapestov/factor/issues/1243
>
> And pull requests are always welcome!
>
> Best,
> John.
>
>
> > On Jan 29, 2015, at 6:18 AM, Alexander Iljin  wrote:
> >
> > Hello, Jon!
> >
> > 29.01.2015, 16:07, "Jon Harper" :
> >> You're missing a whitespace between x and your closing parenthesis in
> >> ": dice5 ( -- x)"
> >
> >  Thank you! I can see that now.
> >
> >  If I were to sumbit a patch for this problem I need to understand a bit
> more.
> >  Am I right in thinking that the effects.parser.parse-effect-token (or
> something rearby) needs to respect the rule stating that "everything from a
> ! to the end of line is a comment"? Or is there no such universally
> applicable rule in Factor?
> >
> > ---=---
> > Александр
> >
> >
> --
> > Dive into the World of Parallel Programming. The Go Parallel Website,
> > sponsored by Intel and developed in partnership with Slashdot Media, is
> your
> > hub for all things parallel software development, from weekly thought
> > leadership blogs to news, videos, case studies, tutorials and more. Take
> a
> > look and join the conversation now. http://goparallel.sourceforge.net/
> > ___
> > Factor-talk mailing list
> > Factor-talk@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
> --
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is
> your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Gödel Numbering

2015-01-19 Thread Alex Vondrak
>
> Factor seems to encapsulate a lot of knowledge that a student of computer
> science might encounter.
>

Not sure quite what that means, but in a trivial sense, this would be true
of any (Turing complete) programming language. ;)

Does anyone else think that a university math course sequence is then more
> valuable than a typical Java/C++ CS/IT sequence?
>

That was my philosophy late into my college degree(s). My CS courses fell
into a rut of feeling a bit too easy, but taking abstract algebra,
combinatorics, graph theory, and number theory classes broadened my
horizons (and taught me to use LaTeX!). Not that CS classes aren't
worthwhile; a proper *Computer Science* education is more than just
programming. My favorite CS classes were basically just math classes:
computability, cryptography, formal languages, compiler optimization, etc.

On the one hand, math classes are directly practical in the tools they give
programmers. E.g., graph theory is rich with useful insights and algorithms
about structures that programmers deal with every day. But I think the
biggest benefit I got from my math classes was working directly with
abstractions. In a CS class, you might be given an assignment to code up,
and you just kind of "wing it" in the language you know with some new
techniques from class (e.g., write a game-playing AI with the alpha-beta
pruning algorithm you learned). Your abstractions are limited, because
you're mostly imitating something you've seen. In a math class, you derive
new results (new to you, anyway) from the abstractions studied. You're
directly dealing in building up a framework: given theorem A taught in
class, prove that theorem B in the homework must be true; use theorem B to
prove theorem C (code reuse!). I think it can easily make you a better
programmer. Even in a literal sense, since mathematical proofs are the same
things as programs:
https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence.

Anyway, I could go on. :) Take-home message to The Kids: eat your
vegetables, brush your teeth, do your abstract algebra.


On Mon, Jan 19, 2015 at 8:55 AM, mr wzrd  wrote:

>  http://re-factor.blogspot.com/2015/01/godel-numbering.html
>
> Factor seems to encapsulate a lot of knowledge that a student of computer
> science might encounter.
>
> Does anyone else think that a university math course sequence is then more
> valuable than a typical Java/C++ CS/IT sequence?
>
>
> http://www.scientificamerican.com/article/is-the-universe-made-of-math-excerpt/
>
>   - mrw
>
>
>
> --
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Google+ Factor community and first question

2015-01-16 Thread Alex Vondrak
To explain the error you got, though, the problem with

home
[ 0 [ file-info size>> + ] each ]
with-directory-files

1. `home` is pushed to the stack
2. `[ 0 [ file-info size>> + ] each ]` is pushed to the stack
3. `with-directory-files` executes `[ 0 [ file-info size>> + ] each ]` on
the sequence of directory files for `home`
4. So effectively this is like doing `seq 0 [ file-info size>> + ] each`
where `seq` is your sequence of files
5. `each` tries to call `[ file-info size>> + ]` on each item in the
"sequence" `0`!
6. `0` does not respond to the word `length` (which `each` uses to iterate
over sequences)

I don't have Factor installed on this machine so I can't check, but I think
the following would work (though not recursively on your directory):

home
[ 0 swap [ file-info size>> + ] each ]
with-directory-files

Interestingly, because arguments are passed around on the stack, `0 swap [
... ] each` is equivalent to `0 [ ... ] reduce`. Not just intuitively,
that's the actual definition of `reduce`:
http://docs.factorcode.org/content/word-reduce,sequences.html

Welcome to Factor!

On Fri, Jan 16, 2015 at 7:27 AM, Marc Hanisch 
wrote:

> Thanks,
>
> USING: io.directories.search io.files.info
> home f recursive-directory-files [ link-info size>> ] map sum
>
> did it! Better idea is to test with a small directory ;-)
>
> Best regards,
> Marc
>
> 2015-01-16 15:19 GMT+01:00 mr wzrd :
>
>> On 01/16/2015 04:46 AM, Marc Hanisch wrote:
>> > I'm trying to create a word which recursive loops over all files in a
>> > directory and sums the filesizes. I entered the following steps into
>> > the listener:
>> Try this ...
>>
>> home f recursive-directory-files [ link-info size>> ] map sum
>>
>>   - mrw
>>
>>
>>
>>
>> --
>> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
>> GigeNET is offering a free month of service with a new server in Ashburn.
>> Choose from 2 high performing configs, both with 100TB of bandwidth.
>> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
>> http://p.sf.net/sfu/gigenet
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
>
>
> --
> ★ Esperanto - Lingvo internacia ▪ http://www.esperanto.de ▪
> http://www.esperanto.berlin ★
>
>
> --
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] A stub of a package manager

2014-12-17 Thread Alex Vondrak
Excited to see where this goes! I like the DSL - reminds me of how it feels
to use [Bundler](http://bundler.io/), where the language for dependency
management is the same as the language you're coding in. (Can you tell my
day job is in Ruby?)

I don't really have anything to add - I can't seem to find the time to
touch Factor these days, and I shy away from the Big Decisions when it
comes to package management (I understand it's a deceptively subtle
problem). But I enjoyed reading about your work, and wanted you to know. :)

On Wed, Dec 17, 2014 at 8:28 AM, John Benediktsson  wrote:
>
> Hi Andrea,
>
> I want to look through this and give you a more full response, looks like
> a pretty good start. Thank you!
>
> One of the benefits to the "one big tree" that we have right now is that
> we guarantee to update your code as the standard library changes or
> improves. This prevents bitrot and allows for some flexibility in changing
> common words.  That matters less over time as the standard library becomes
> more mature, but has been useful at times.  We've wanted ``extra/`` to be
> very very easy to contribute to as a way of supporting new contributors and
> then involving them as we keep an eye on their code.  Obviously there are
> drawbacks to this approach too...
>
> Of course people can have their own repositories, and we should support
> them as best we can (like support for adding vocab roots or through a
> package manager), but I always want to encourage contributions when it
> makes sense for everyone.
>
> Having something simple that encourages re-use of code is pretty great, we
> could probably share our testing infrastructure to support easy continuous
> integration for a project developed this way.
>
> More to come later when I have time.
>
> Best,
> John.
>
>
>
> On Wed, Dec 17, 2014 at 6:20 AM, Andrea Ferretti  > wrote:
>>
>> Hi, following this [small
>> discussion](https://news.ycombinator.com/item?id=8750720) I thought I
>> might give a try at designing a simple package manager.
>>
>> It is inspired by [Metacello](https://code.google.com/p/metacello/)
>> but delegates to existing source control management software such as
>> git the actual handling of repositories, similar to
>> [Bower](http://bower.io/).
>>
>> You can find the stub of a package manager
>> [here](https://github.com/andreaferretti/factor-packages) (keep in
>> mind: this is just the work of a day, and I am still a beginner).
>>
>> Outline
>> ---
>>
>> The central concept is that of a *project*. A project has a name and a
>> version, and contains some vocabularies. It can also depend on other
>> projects. There are syntax words to define the structure of a project,
>> which currently look like this (for a hypothetical project):
>>
>>
>> USING: packages.syntax
>> IN: example-project
>>
>> PROJECT: example
>>
>> VERSION: 0.2.0-alpha
>>
>> VOCAB: example.thrift
>>
>> VOCAB: example.main
>>
>> DEPENDENCY: thrift
>>   GITHUB{ "factor" "thrift" "0.2.5" }
>>
>> One can then do the following in the listener
>>
>> IN: scratchpad
>> USE: packages.projects
>> "example-project" activate
>>
>> This clones the repository for each of the dependencies in a subfolder
>> of "resource:cache" and switches to the given version. It is expected
>> that each dependency contains a toplevel file `project.factor` as
>> above. Then, transitive dependencies are recursively fetched.
>>
>> After fetching all dependencies, the vocabulary roots are adjusted,
>> and finally all vocabularies mentioned in the project or in a
>> dependency are `require`d.
>>
>> If you import the package manager in your work folder, you can see a
>> [simple example](
>> https://github.com/andreaferretti/factor-packages/blob/master/packages/example/example.factor
>> )
>> in action. Just do
>>
>> IN: scratchpad
>> USE: packages.projects
>> "packages.example" activate
>>
>> You will then be able to use, say, the `monoid` dependency, like this
>>
>> IN: scratchpad
>> 3 5 |+|
>>
>> I would like to get feedback on the above design, so as to understand
>> if it is worth the effort to develop this into something actually
>> usable. While very simplistic, I think this approach has a couple of
>> advantages:
>>
>> * it does not require any change to the Factor vocabulary system
>> * by exploiting existing SCM (git and hg are currently supported, but
>> it would be easy to add more) one can avoid the need to setup a
>> repository and to develop a custom protocol.
>>
>> Issues
>> --
>>
>> If the above looks any good, there are a number of things one can
>> improve. All of those seem easy enough, they just requires some time.
>>
>> * support other SCM (svn, darcs, bazaar, ...)
>> * improve the DSL (for instance, should we have VOCABS: ?)
>> * add support for publishing, as well as consuming packages. This
>> would allow to do something like `"mypackage" publish` and
>>   - copy the vocabularies in the cache under the appropri

Re: [Factor-talk] Sorry, another request for advice..

2014-12-14 Thread Alex Vondrak
1. What else are mailing lists for? :)

2. John's suggestion is good (to just rework the program), but in the
future / other situations, it may also make sense to look into the right
dataflow combinator (
http://docs.factorcode.org/content/article-dataflow-combinators.html). For
instance, instead of `25 swap 7 swap`, you can say `[ 25 7 ] dip`.  There's
a combinator for reaching 3 deep, too:
http://docs.factorcode.org/content/word-3dip%2Ckernel.html

3. To your particular problem of applying `bsread-string` to multiple pairs
of values, there are apply combinators that might help:
http://docs.factorcode.org/content/word-2bi__at__%2Ckernel.html
http://docs.factorcode.org/content/word-2tri__at__%2Ckernel.html
http://docs.factorcode.org/content/word-mnapply%2Cgeneralizations.html

For example, `4 7 8 7 [ bitreader bsread-string ] 2bi@` could be
accomplished with `bitreader` atop the stack by saying `[ 4 7 8 7 ] dip [
bsread-string ] curry 2bi@`.

On Sun, Dec 14, 2014 at 8:54 AM, Mark Green 
wrote:
>
> That's very helpful, but the thing is that what I really want to do is to
> pull a series of fields from the bitreader and store them in a tuple via
> boa. Something like bitreader [ 4 7 bsread-string ] [ 8 7 bsread-string ]
> tri boa . The problem is that to do that I need a version of bsread-string
> that takes the bitreader argument as the deepest rather than the
> shallowest, and I don't see any way of doing that (other than using locals)
> because it's hard to reach down 3 steps on the stack. Is there any way of
> doing this?
>
> Mark
>
>
>
> --
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
>
> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] how to calculate count of days

2014-09-05 Thread Alex Vondrak
I also realize now that this "date" vs "datetime" distinction was what Jon
was suggesting, whereas I thought he was talking about "have one version
normalize to local time, have the other normalize to GMT" (like
Date.current & Date.today in Rails).  I'm all for a "date" vs "datetime"
distinction---probably best as separate tuples.


On Fri, Sep 5, 2014 at 9:06 AM, Alex Vondrak  wrote:

> On Fri, Sep 5, 2014 at 3:34 AM, Jon Harper  wrote:
>
>> On Fri, Sep 5, 2014 at 9:52 AM, Alex Vondrak  wrote:
>>
>>> On Thu, Sep 4, 2014 at 4:06 PM, Jon Harper 
>>> wrote:
>>>
>>>> How about:
>>>> : today ( -- timestamp ) now midnight instant >>gmt-offset ; inline
>>>>
>>>
>>> Or really just
>>>
>>> : today ( -- timestamp ) gmt midnight ; inline
>>>
>>> No, this is not the correct date.  "2014-09-05 01:00:00+02:00" is the
>> same instant as "2014-09-04 23:00:00Z" (ie "now" and "gmt" would return
>> those timestamps if invoked at the same time), but the date is not the
>> same: 09-05 and 09-04 (and the correct one is really 09-05 when you are in
>> the +2 timezone)
>>
>
> Ah, that makes the rest of your email suddenly make sense to me, where you
> said:
>
> However, the big negative impact of this representation is that comparing
>> a timestamp representing a date and a timestamp representing an instant
>> becomes meaningless (ie not all timestamps in a day are before or after a
>> timestamp representing a date), wherease before, it was only meaningless if
>> the timezone had changed (rare, but it still happens...). Since it was
>> already dangerous, it doesn't seem like a big deal.
>>
>
> I thought your idea was to normalize to GMT.  I mean, why would I want to
> separate the timezone from the date?  Then asking for "the date of today"
> would give back "it's totally 2014-09-05 locally, but I'm just going to say
> that it's 2014-09-05 GMT too---even though it's actually 2014-09-04 GMT,
> I'll just say that `today` is in the future". Seems more confusing to me,
> since dates are intrinsically linked to timezones.  I don't care if it's
> normalized to GMT or to local time, so long as it's actually normalized
> correctly.
>
> But then, I guess I'm thinking of "dates" as "datetimes" - which is how
> the `calendar` vocab treats them currently (even `` just constructs a
> `timestamp` tuple).  I think it would be clearer if we had a separate API
> for dates devoid of timestamps.  In one vocab, you could call `today` and
> get back "local/GMT-normalized date of today, set to the timestamp of
> midnight" and in the other you would get back "local/GMT-normalized date of
> today, no timestamp at all".  Then dates and datetimes would be
> incomparable, and adding/subtracting durations from dates would only
> consider the day/month/year components (I'm thinking along the lines of how
> Python works -
> https://docs.python.org/2/library/datetime.html#datetime.date.day).
>
>
>> But then things go wrong in the rare cases when you change your timezone.
>>
>
> Fair enough. I think changing timezones is less of a deal-breaker than
> `ymd>timestamp` & `timestamp>ymd` not being inverses of each other (without
> intervening GMT conversion), though.
>
> I guess a solution to both problems could be just having more robust
> parsing that could translate strings with GMT offsets. Many RFCs abound
> with date formats.
>
--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] how to calculate count of days

2014-09-05 Thread Alex Vondrak
On Fri, Sep 5, 2014 at 3:34 AM, Jon Harper  wrote:

> On Fri, Sep 5, 2014 at 9:52 AM, Alex Vondrak  wrote:
>
>> On Thu, Sep 4, 2014 at 4:06 PM, Jon Harper 
>> wrote:
>>
>>> How about:
>>> : today ( -- timestamp ) now midnight instant >>gmt-offset ; inline
>>>
>>
>> Or really just
>>
>> : today ( -- timestamp ) gmt midnight ; inline
>>
>> No, this is not the correct date.  "2014-09-05 01:00:00+02:00" is the
> same instant as "2014-09-04 23:00:00Z" (ie "now" and "gmt" would return
> those timestamps if invoked at the same time), but the date is not the
> same: 09-05 and 09-04 (and the correct one is really 09-05 when you are in
> the +2 timezone)
>

Ah, that makes the rest of your email suddenly make sense to me, where you
said:

However, the big negative impact of this representation is that comparing a
> timestamp representing a date and a timestamp representing an instant
> becomes meaningless (ie not all timestamps in a day are before or after a
> timestamp representing a date), wherease before, it was only meaningless if
> the timezone had changed (rare, but it still happens...). Since it was
> already dangerous, it doesn't seem like a big deal.
>

I thought your idea was to normalize to GMT.  I mean, why would I want to
separate the timezone from the date?  Then asking for "the date of today"
would give back "it's totally 2014-09-05 locally, but I'm just going to say
that it's 2014-09-05 GMT too---even though it's actually 2014-09-04 GMT,
I'll just say that `today` is in the future". Seems more confusing to me,
since dates are intrinsically linked to timezones.  I don't care if it's
normalized to GMT or to local time, so long as it's actually normalized
correctly.

But then, I guess I'm thinking of "dates" as "datetimes" - which is how the
`calendar` vocab treats them currently (even `` just constructs a
`timestamp` tuple).  I think it would be clearer if we had a separate API
for dates devoid of timestamps.  In one vocab, you could call `today` and
get back "local/GMT-normalized date of today, set to the timestamp of
midnight" and in the other you would get back "local/GMT-normalized date of
today, no timestamp at all".  Then dates and datetimes would be
incomparable, and adding/subtracting durations from dates would only
consider the day/month/year components (I'm thinking along the lines of how
Python works -
https://docs.python.org/2/library/datetime.html#datetime.date.day).


> But then things go wrong in the rare cases when you change your timezone.
>

Fair enough. I think changing timezones is less of a deal-breaker than
`ymd>timestamp` & `timestamp>ymd` not being inverses of each other (without
intervening GMT conversion), though.

I guess a solution to both problems could be just having more robust
parsing that could translate strings with GMT offsets. Many RFCs abound
with date formats.
--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] how to calculate count of days

2014-09-05 Thread Alex Vondrak
On Thu, Sep 4, 2014 at 4:06 PM, Jon Harper  wrote:

> How about:
> : today ( -- timestamp ) now midnight instant >>gmt-offset ; inline
>

Or really just

: today ( -- timestamp ) gmt midnight ; inline

if I'm not mistaken.  It's a short trip from `today`'s current definition:
http://docs.factorcode.org/content/word-today,calendar.html

As far as I know, that goes for the other words: their reliance is on `now`
rather than `gmt` (e.g.,
http://docs.factorcode.org/content/word-ago%2Ccalendar.html and
http://docs.factorcode.org/content/word-hence%2Ccalendar.html).

I guess less drastic would be for `ymd>timestamp` to just use local time;
right now it's defined with ``:
http://docs.factorcode.org/content/word-%28ymd__gt__timestamp%29%2Ccalendar.format.html
I know John mentioned it, but I'm not sure why that shouldn't just be
``, since most other things appear to use local time as well (per the
above).


> If backwards compatibility is an issue, we can always create new words
> instead of changing the existing ones (ie leave "today" as it is, and
> create "today-date").
>

Ah, man, we could be just like Ruby on Rails with the `Date.current` &
`Date.today` distinction! :)

Sorry, it's too far past my bed time to make useful contributions to the
discussion, haha. That, and date & time libraries are a headache.
--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] how to calculate count of days

2014-09-05 Thread Alex Vondrak
>
> English is not my native language but could days-since be better?


Just wanted to chime in here that `days-since` would be the perfect name
(as in `"2014-08-21" days-since`).  English is my native language and I
hadn't even thought of this name! :)



On Wed, Sep 3, 2014 at 1:22 AM, Georg Simon  wrote:

> Am Tue, 2 Sep 2014 19:09:45 -0700
> schrieb Alex Vondrak :
>
> Thank you.
>
> > ...
> >
> > That is, if it weren't for the GMT bit, you could just say
> > `"2014-08-31"
> > ymd>timestamp ago duration>days`.  In fact, that would make a nice
> > ymd>word: `:
> > days-ago ( timestamp -- days ) ago duration>days ;`
> >
> But ago includes the time since midnight. So this didn't work.
>
> > (Not sure I would name it `days-ago`, since that's similar to `days
> > ago`, which has a different meaning...but I can't think of a better
> > name.)
> >
> English is not my native language but could days-since be better?
>
> > However, there's the GMT hangup.  I'm not smart enough right now to
> > reason about whether you could just use `ago >gmt` and get the right
> > results, but I'd try it -
> > http://docs.factorcode.org/content/word-__gt__gmt,calendar.html
> >
> Did not work: not a method for the duration class
>
> > Hope any of that helps or gives you some ideas. Let us know what you
> > come up with!
> >
> Yes, important help. Now I see the cause in the information loss when
> generating ymd-strings. So my code explicitly assumes that ymd-strings
> give the local time:
>
> : local-ymd>timestamp ( str -- timestamp )
> ymd>timestamp gmt-offset-duration >>gmt-offset
> ;
>  : days-since ( str -- n )
> today swap local-ymd>timestamp time- duration>days
> ;
>
>
> --
> Slashdot TV.
> Video for Nerds.  Stuff that matters.
> http://tv.slashdot.org/
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] how to calculate count of days

2014-09-02 Thread Alex Vondrak
I don't have Factor installed on this machine, so I can't test my
suggestions. But I'll do my best.

`today` is defined as `now midnight` -
http://docs.factorcode.org/content/word-today,calendar.html

Notice that `now` uses `gmt`, then sets the offset -
http://docs.factorcode.org/content/word-now,calendar.html

Thus, instead of `today 0 hours >>gmt-offset` I think you can just say `gmt
midnight`.

`ymd>timestamp` seems to be exactly what you need for converting a YMD
string to a timestamp, so let's leave that part alone. :)

Now, we can pay attention to the general pattern of this code. If it
weren't for the GMT offset, most of your snippet would look like `now
"2014-08-31" ymd>timestamp time-`.  This pattern of subtracting a timestamp
or duration from the current time is exactly encapsulated by the `ago` word
- http://docs.factorcode.org/content/word-ago%2Ccalendar.html (due to the
fact that `time-` can apply to a timestamp as well -
http://docs.factorcode.org/content/word-time-%2Ccalendar.html)

That is, if it weren't for the GMT bit, you could just say `"2014-08-31"
ymd>timestamp ago duration>days`.  In fact, that would make a nice word: `:
days-ago ( timestamp -- days ) ago duration>days ;`

(Not sure I would name it `days-ago`, since that's similar to `days ago`,
which has a different meaning...but I can't think of a better name.)

However, there's the GMT hangup.  I'm not smart enough right now to reason
about whether you could just use `ago >gmt` and get the right results, but
I'd try it - http://docs.factorcode.org/content/word-__gt__gmt,calendar.html

Hope any of that helps or gives you some ideas. Let us know what you come
up with!



On Tue, Sep 2, 2014 at 9:02 AM, Georg Simon  wrote:

> today "2014-08-31" ymd>timestamp time- duration>days .
>
> prints 1+11/12
> as we are 2 hours earlier than gmt I guess.
>
> today 0 hours >>gmt-offset "2014-08-31" ymd>timestamp time-
> duration>days .
>
> prints 2
> which is what I want.
>
> Is there a better way to calculate how many days ago a -MM-DD
> string means ?
>
> Georg
>
>
> --
> Slashdot TV.
> Video for Nerds.  Stuff that matters.
> http://tv.slashdot.org/
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] OCR via docsplit in Factor

2014-02-09 Thread Alex Vondrak
Thing is, `cd` isn't a binary that Factor can execute in a process.  It's
just a shell command implemented by bash or zsh or whatever you use.  Same
with the semicolon syntax, for that matter.  You might try to finagle
something like

IN: scratchpad { "sh" "-c" "cd /tmp ; pwd" } utf8 [ contents . ]
with-process-reader
"/tmp\n"

Not sure how the PATH stuff will work out with that, though.

You could also try just using the `-o` flag to docsplit.  Again,
deliberately messing up my PATH so Factor can't run docsplit directly:

IN: scratchpad "docsplit" which .
f
IN: scratchpad "/tmp/thesis.pdf" exists? .
t
IN: scratchpad "/tmp/thesis.txt" exists? .
f
IN: scratchpad "/usr/local/bin/docsplit text --no-clean -l eng
/tmp/thesis.pdf -o /tmp" try-process
IN: scratchpad "/tmp/thesis.txt" exists? .
t



On Sun, Feb 9, 2014 at 5:02 PM, CW Alston  wrote:

> Yeah, Alex-
> I would have thought the cd in my compound command string would take care
> of he current directory issue.
> There's another thread about this 
> problem<http://www.programmingrelief.com/3213645/Docsplit-Works-Fine-In-Command-Line-But-Ignores-Code-In-Ruby-Script%3F>that
>  finds docsplit returning files in the root directory - on my system
> no files are winding up there.
> Let me see what I can do w/ your path/environment suggestions.
>
> Gonna be another long night...
> Thanks much,
> ~cw
>
>
> On Sun, Feb 9, 2014 at 4:08 PM, Alex Vondrak  wrote:
>
>> Strange.  Well, not actually "strange", since many programs aren't great
>> about return codes...but still!  I decided to re-enact the issue by
>> removing /usr/local/bin (where my docsplit was installed) from my PATH,
>> starting Factor, and trying it out.  Looks like docsplit is dumping the txt
>> file in the current working directory:
>>
>>
>> IN: scratchpad "docsplit" which .
>> f
>> IN: scratchpad "docsplit text --no-clean -l eng /tmp/thesis.pdf"
>> run-process status>> .
>> 255
>> IN: scratchpad "/usr/local/bin/docsplit text --no-clean -l eng
>> /tmp/thesis.pdf" run-process status>> .
>> 0
>> IN: scratchpad "/tmp/thesis.txt" exists? .
>> f
>> IN: scratchpad "thesis.txt" exists? .
>> t
>>
>> Seems as though you need to tell Factor to run in another working
>> directory:
>>
>> IN: scratchpad "/tmp" [
>> "/usr/local/bin/docsplit text --no-clean -l eng /tmp/thesis.pdf"
>> run-process status>> .
>>  ] with-directory
>> 0
>> IN: scratchpad "/tmp/thesis.txt" exists? .
>> t
>>
>> By the way, turns out you can set the `environment` slot of an
>> io.launcher process, so I was thinking maybe that would help, but...
>>
>> IN: scratchpad 
>> "docsplit text --no-clean -l eng /tmp/thesis.pdf" >>command
>> "/tmp/stdout.txt" >>stdout
>> +stdout+ >>stderr
>> { { "PATH" "/usr/local/bin" } } >>environment
>> run-process status>> .
>> 1
>> IN: scratchpad "/tmp/stdout.txt" utf8 file-contents print
>> sh: 1: pdftotext: not found
>>
>> Damn. No dice. Looks like you'll have to fix the PATH issue on the system
>> itself.
>>
>> Anyway, hope that helps.
>>
>> (P.S.: Charles, if you're getting this message again, it's because I
>> think GMail might've screwed up the reply behavior and didn't send this to
>> the list, so I'm re-sending it.)
>>
>>
>>
>> On Sun, Feb 9, 2014 at 3:13 PM, CW Alston  wrote:
>>
>>> Hi Alex-
>>>
>>> Thanks, I did try
>>>
>>> "/full/path/to/docsplit text --no-clean -l chi_sim
>>> /path/to/1_long_gu/long_gu001.pdf" try-process
>>>
>>> using both the symlink and the resolved executable:
>>>
>>> /usr/local/opt/ruby/bin/docsplit
>>> /usr/local/Cellar/ruby/2.1.0/bin/docsplit
>>>
>>> but still no response, still status 0. A lightbulb went on, and I set a
>>> duplicate symlink
>>> in /usr/bin/docsplit (where Factor's which can find it) straight to
>>> /usr/local/Cellar/ruby/2.1.0/bin/docsplit:
>>>
>>> IN: scratchpad "docsplit" which .
>>> "/usr/bin/docsplit"
>>>
>>> -ok, but still no success with anything in io.launcher. Oy!
>>>
>>> I see on the web that this problem calling docsplit isn't confined to
>>> Factor. Help calls

Re: [Factor-talk] OCR via docsplit in Factor

2014-02-09 Thread Alex Vondrak
Strange.  Well, not actually "strange", since many programs aren't great
about return codes...but still!  I decided to re-enact the issue by
removing /usr/local/bin (where my docsplit was installed) from my PATH,
starting Factor, and trying it out.  Looks like docsplit is dumping the txt
file in the current working directory:


IN: scratchpad "docsplit" which .
f
IN: scratchpad "docsplit text --no-clean -l eng /tmp/thesis.pdf"
run-process status>> .
255
IN: scratchpad "/usr/local/bin/docsplit text --no-clean -l eng
/tmp/thesis.pdf" run-process status>> .
0
IN: scratchpad "/tmp/thesis.txt" exists? .
f
IN: scratchpad "thesis.txt" exists? .
t

Seems as though you need to tell Factor to run in another working directory:

IN: scratchpad "/tmp" [
"/usr/local/bin/docsplit text --no-clean -l eng /tmp/thesis.pdf"
run-process status>> .
 ] with-directory
0
IN: scratchpad "/tmp/thesis.txt" exists? .
t

By the way, turns out you can set the `environment` slot of an io.launcher
process, so I was thinking maybe that would help, but...

IN: scratchpad 
"docsplit text --no-clean -l eng /tmp/thesis.pdf" >>command
"/tmp/stdout.txt" >>stdout
+stdout+ >>stderr
{ { "PATH" "/usr/local/bin" } } >>environment
run-process status>> .
1
IN: scratchpad "/tmp/stdout.txt" utf8 file-contents print
sh: 1: pdftotext: not found

Damn. No dice. Looks like you'll have to fix the PATH issue on the system
itself.

Anyway, hope that helps.

(P.S.: Charles, if you're getting this message again, it's because I think
GMail might've screwed up the reply behavior and didn't send this to the
list, so I'm re-sending it.)



On Sun, Feb 9, 2014 at 3:13 PM, CW Alston  wrote:

> Hi Alex-
>
> Thanks, I did try
>
> "/full/path/to/docsplit text --no-clean -l chi_sim
> /path/to/1_long_gu/long_gu001.pdf" try-process
>
> using both the symlink and the resolved executable:
>
> /usr/local/opt/ruby/bin/docsplit
> /usr/local/Cellar/ruby/2.1.0/bin/docsplit
>
> but still no response, still status 0. A lightbulb went on, and I set a
> duplicate symlink
> in /usr/bin/docsplit (where Factor's which can find it) straight to
> /usr/local/Cellar/ruby/2.1.0/bin/docsplit:
>
> IN: scratchpad "docsplit" which .
> "/usr/bin/docsplit"
>
> -ok, but still no success with anything in io.launcher. Oy!
>
> I see on the web that this problem calling docsplit isn't confined to
> Factor. Help calls appear
> in 
> Plone-Users<http://sourceforge.net/mailarchive/message.php?msg_id=29982797> 
> and
> stackoverflow re 
> python<http://stackoverflow.com/questions/18237442/execute-shell-commands-in-python-to-use-docsplit>.
> Let me dig around some more; this sticky wicket
> must have a workaround...
>
> I'll dig around some more.
> ~cw
>
>
>
>
> On Sun, Feb 9, 2014 at 2:16 PM, Alex Vondrak  wrote:
>
>> As a follow-up, from Factor you can use `with-directory-files`
>> (
>> http://docs.factorcode.org/content/word-with-directory-files,io.directories.html
>> )
>> and `absolute-path`
>> (http://docs.factorcode.org/content/word-absolute-path,io.pathnames.html)
>> to get full paths to the files in some directory:
>>
>> ```
>> IN: scratchpad "/home/alex/factor/core" [ [ absolute-path . ] each ]
>> with-directory-files
>> "/home/alex/factor/core/generic"
>> "/home/alex/factor/core/parser"
>> "/home/alex/factor/core/sorting"
>> [etc]
>> ```
>>
>>
>> On Sun, Feb 9, 2014 at 1:53 PM, Alex Vondrak  wrote:
>> > It's probably easiest to specify the full path to the file, like I did
>> > in my previous message.  Combined with the full path to the docsplit
>> > binary/link (for your particular problem), it should theoretically
>> > work fine:
>> >
>> > "/full/path/to/docsplit text --no-clean -l chi_sim
>> > /path/to/1_long_gu/long_gu001.pdf" try-process
>> >
>> > On Sun, Feb 9, 2014 at 1:00 PM, CW Alston  wrote:
>> >> Hi John-
>> >> Beg pardon, I should have mentioned earlier that since docsplit plants
>> a
>> >> .txt file in the target pdf's
>> >> directory on its own, with no other output, I had gone the route you
>> >> suggested, but to no avail, i.e.,
>> >>
>> >> "docsplit text --no-clean -l path" run-process drop
>> >>
>> >> In  the terminal,  cd /path/to/1_long_gu ; docsplit text --no-clean -l
>> >> c

Re: [Factor-talk] OCR via docsplit in Factor

2014-02-09 Thread Alex Vondrak
As a follow-up, from Factor you can use `with-directory-files`
(http://docs.factorcode.org/content/word-with-directory-files,io.directories.html)
and `absolute-path`
(http://docs.factorcode.org/content/word-absolute-path,io.pathnames.html)
to get full paths to the files in some directory:

```
IN: scratchpad "/home/alex/factor/core" [ [ absolute-path . ] each ]
with-directory-files
"/home/alex/factor/core/generic"
"/home/alex/factor/core/parser"
"/home/alex/factor/core/sorting"
[etc]
```


On Sun, Feb 9, 2014 at 1:53 PM, Alex Vondrak  wrote:
> It's probably easiest to specify the full path to the file, like I did
> in my previous message.  Combined with the full path to the docsplit
> binary/link (for your particular problem), it should theoretically
> work fine:
>
> "/full/path/to/docsplit text --no-clean -l chi_sim
> /path/to/1_long_gu/long_gu001.pdf" try-process
>
> On Sun, Feb 9, 2014 at 1:00 PM, CW Alston  wrote:
>> Hi John-
>> Beg pardon, I should have mentioned earlier that since docsplit plants a
>> .txt file in the target pdf's
>> directory on its own, with no other output, I had gone the route you
>> suggested, but to no avail, i.e.,
>>
>> "docsplit text --no-clean -l path" run-process drop
>>
>> In  the terminal,  cd /path/to/1_long_gu ; docsplit text --no-clean -l
>> chi_sim long_gu001.pdf
>> works fine. The surprise is that, in the listener, the phrase:
>>
>> "cd /path/to/1_long_gu ; docsplit text --no-clean -l chi_sim long_gu001.pdf"
>> run-process .
>>
>> - returns with status 0, but leaves no file. Ditto using
>> /full/path/to/docsplit in the command.
>>
>> The docsplit bin alias (/usr/local/opt/ruby/bin/docsplit) resolves to
>> /usr/local/Cellar/ruby/2.1.0/bin/docsplit
>> (installed w/ homebrew). There I find this ruby script:
>>
>> require 'rubygems'
>>
>> version = ">= 0"
>>
>> if ARGV.first
>>   str = ARGV.first
>>   str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
>>   if str =~ /\A_(.*)_\z/
>> version = $1
>> ARGV.shift
>>   end
>> end
>>
>> gem 'docsplit', version
>> load Gem.bin_path('docsplit', 'docsplit', version)
>>
>> If I manage to decipher this, I'll try to translate it in Factor, and invoke
>> docsplit that way.
>> That should keep me busy for a while. Worth a try, though I know zip about
>> ruby. Once past
>> this boondoggle, I already have Factor code that walks the tree & collates
>> the files.
>>
>> Thanks!
>> ~cw
>>
>>
>>
>>
>> On Sun, Feb 9, 2014 at 4:31 AM, John Benediktsson  wrote:
>>>
>>> If you get lost in path land you can always take a break and use the
>>> /full/path/to/docsplit.
>>>
>>> On Feb 9, 2014, at 2:03 AM, CW Alston  wrote:
>>>
>>> Ah! Thanks, Joe-
>>> Great tip; should clear up the issue with "which". I am indeed starting
>>> Factor in the Finder. I'll try adjusting the plist.
>>> Maybe that even has something to do with my docsplit puzzle. Since I can
>>> address commands like couchdb
>>> via a , I should be able to invoke docsplit that way as well,
>>> even though htop shows me that docsplit
>>> itself spawns sub-processes, like poppler & tesseract, to do its
>>> extraction work. Interesting.
>>>
>>> I'll go study the Mac dev doc you point to, & see what I can glean from
>>> there.
>>>
>>> Back to the books,
>>> ~cw
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Feb 8, 2014 at 10:27 PM, Joe Groff  wrote:
>>>>
>>>> On Sat, Feb 8, 2014 at 7:30 PM, CW Alston  wrote:
>>>>>
>>>>> Hi -
>>>>> Ok, I've upgraded using factor-macosx-x86-32-2013-07-25-14-21.dmg,
>>>>> still Version 0.97. Same issue with Factor's "which":
>>>>>
>>>>> IN: scratchpad USE: tools.which
>>>>> IN: scratchpad "couchdb" which .
>>>>> f
>>>>>
>>>>> IN: scratchpad "python" which .
>>>>> "/usr/bin/python"
>>>>>
>>>>> - The trouble appears to be with reporting my PATH properly, via getenv:
>>>>>
>>>>> IN: scratchpad USE: environment
>>>>> IN: scratchpad "PATH" os-env .
>>>>> "/us

Re: [Factor-talk] OCR via docsplit in Factor

2014-02-09 Thread Alex Vondrak
It's probably easiest to specify the full path to the file, like I did
in my previous message.  Combined with the full path to the docsplit
binary/link (for your particular problem), it should theoretically
work fine:

"/full/path/to/docsplit text --no-clean -l chi_sim
/path/to/1_long_gu/long_gu001.pdf" try-process

On Sun, Feb 9, 2014 at 1:00 PM, CW Alston  wrote:
> Hi John-
> Beg pardon, I should have mentioned earlier that since docsplit plants a
> .txt file in the target pdf's
> directory on its own, with no other output, I had gone the route you
> suggested, but to no avail, i.e.,
>
> "docsplit text --no-clean -l path" run-process drop
>
> In  the terminal,  cd /path/to/1_long_gu ; docsplit text --no-clean -l
> chi_sim long_gu001.pdf
> works fine. The surprise is that, in the listener, the phrase:
>
> "cd /path/to/1_long_gu ; docsplit text --no-clean -l chi_sim long_gu001.pdf"
> run-process .
>
> - returns with status 0, but leaves no file. Ditto using
> /full/path/to/docsplit in the command.
>
> The docsplit bin alias (/usr/local/opt/ruby/bin/docsplit) resolves to
> /usr/local/Cellar/ruby/2.1.0/bin/docsplit
> (installed w/ homebrew). There I find this ruby script:
>
> require 'rubygems'
>
> version = ">= 0"
>
> if ARGV.first
>   str = ARGV.first
>   str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
>   if str =~ /\A_(.*)_\z/
> version = $1
> ARGV.shift
>   end
> end
>
> gem 'docsplit', version
> load Gem.bin_path('docsplit', 'docsplit', version)
>
> If I manage to decipher this, I'll try to translate it in Factor, and invoke
> docsplit that way.
> That should keep me busy for a while. Worth a try, though I know zip about
> ruby. Once past
> this boondoggle, I already have Factor code that walks the tree & collates
> the files.
>
> Thanks!
> ~cw
>
>
>
>
> On Sun, Feb 9, 2014 at 4:31 AM, John Benediktsson  wrote:
>>
>> If you get lost in path land you can always take a break and use the
>> /full/path/to/docsplit.
>>
>> On Feb 9, 2014, at 2:03 AM, CW Alston  wrote:
>>
>> Ah! Thanks, Joe-
>> Great tip; should clear up the issue with "which". I am indeed starting
>> Factor in the Finder. I'll try adjusting the plist.
>> Maybe that even has something to do with my docsplit puzzle. Since I can
>> address commands like couchdb
>> via a , I should be able to invoke docsplit that way as well,
>> even though htop shows me that docsplit
>> itself spawns sub-processes, like poppler & tesseract, to do its
>> extraction work. Interesting.
>>
>> I'll go study the Mac dev doc you point to, & see what I can glean from
>> there.
>>
>> Back to the books,
>> ~cw
>>
>>
>>
>>
>>
>> On Sat, Feb 8, 2014 at 10:27 PM, Joe Groff  wrote:
>>>
>>> On Sat, Feb 8, 2014 at 7:30 PM, CW Alston  wrote:

 Hi -
 Ok, I've upgraded using factor-macosx-x86-32-2013-07-25-14-21.dmg,
 still Version 0.97. Same issue with Factor's "which":

 IN: scratchpad USE: tools.which
 IN: scratchpad "couchdb" which .
 f

 IN: scratchpad "python" which .
 "/usr/bin/python"

 - The trouble appears to be with reporting my PATH properly, via getenv:

 IN: scratchpad USE: environment
 IN: scratchpad "PATH" os-env .
 "/usr/bin:/bin:/usr/sbin:/sbin"

 IN: scratchpad USE: unix.ffi
 IN: scratchpad "PATH" getenv .
 "/usr/bin:/bin:/usr/sbin:/sbin"

 IN: scratchpad \ getenv see
 USING: alien.c-types alien.syntax ;
 IN: unix.ffi
 LIBRARY: libc FUNCTION: c-string getenv ( c-string name ) ;
 inline

 - Here's my actual PATH, as seen in the terminal:

 ➜  ~ git:(master) ✗ echo $PATH

 /usr/local/bin:/usr/local/opt/ruby/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/cwalston/factor:/Users/cwalston/bin:/usr/local/go/bin:/usr/local/lib/node_modules:/usr/local/narwhal/bin:/usr/texbin:/usr/X11/bin:/usr/local/sbin:/Users/cwalston/.gem/ruby/1.8/bin:/Applications/Mozart.app/Contents/Resources/bin

 - whereby which correctly finds couchdb:

 ➜  ~ git:(master) ✗ which couchdb
 /usr/local/bin/couchdb

 So, Factor's "which" (et al.) doesn't search beyond
 /usr/bin:/bin:/usr/sbin:/sbin.

 Reading through man getenv (GETENV(3), on OSX 10.6.8 ), doesn't give me
 a clue as to how to rectify this short-sightedness via the libc getenv.

 This is probably a side issue to my docsplit quandary (but maybe not).
 Anyone see a way to report my actual PATH to "which" in Factor? My PATH
 is
 augmented in my .zshrc. I don't understand why the libc function doesn't
 read it. Odd, indeed!

>>> If you're starting Factor from the Finder, you're not going to get a PATH
>>> set from your .profile or other shell dotfiles, since UI apps are launched
>>> under the loginwindow session and not under any shell. To set environment
>>> variables for UI apps, try setting them in ~/.MacOSX/environment.plist:
>>>
>>>
>>> https://developer.apple.com/library/mac/documentation/MacOSX/Conce

Re: [Factor-talk] OCR via docsplit in Factor

2014-02-08 Thread Alex Vondrak
I can't tell you what's wrong with code you haven't provided, but...

```
IN: scratchpad USING: io.files io.launcher io.encodings.ascii tools.which ;
IN: scratchpad "docsplit" which .
"/usr/local/bin/docsplit"
IN: scratchpad "/tmp/cv.pdf" exists? .
t
IN: scratchpad "/tmp/cv.txt" exists? .
f
IN: scratchpad "docsplit text --no-clean -l eng /tmp/cv.pdf" try-process
IN: scratchpad "/tmp/cv.txt" exists? .
t
IN: scratchpad "/tmp/cv.txt" ascii file-lines first .
"Alex Vondrak"
```


On Sat, Feb 8, 2014 at 2:32 AM, CW Alston  wrote:
> Hi folks -
>
> I am thrilled to find a versatile open-source optical character recognition
> engine called docsplit. I've got it installed easily as a ruby gem, & it
> works
> just great on my Mac as a shell command (it also provides a ruby module):
>
> ➜  ~ git:(master) ✗ which docsplit
> /usr/local/opt/ruby/bin/docsplit
> ➜  ~ git:(master) ✗
>
> I need such a tool to extract text from a deep directory tree, with a couple
> thousand
> folders. Each leaf folder contains 3-6 scanned pdfs (in Chinese & English),
> from which
> docsplit makes a plaintext (.txt) file with the same basename, deposited in
> the same
> leaf directory. My Factor vocab can easily visit each leaf dir & prepare to
> pass each pdf
> there to docsplit in the format it happily handles in the terminal (I use
> oh-my-zsh & iTerm2).
> My Factor code chokes on this intermediate step, trying to call docsplit.
>
> Going to the terminal, I have to first cd to the directory containing the
> pdfs, e.g.,
>
> ➜  ~ git:(master) ✗ cd /path/to/1_long_gu
>
> then call docsplit with the appropriate flags on each pdf:
>
> ➜  1_long_gu git:(master) ✗ docsplit text --no-clean -l chi_sim
> long_gu001.pdf
> ➜  1_long_gu git:(master) ✗ docsplit text --no-clean -l eng long_gu002.pdf
>
> etc., for each pdf, & docsplit gives back a bunch of text files in the dir
> like
>
> /path/to/1_long_gu/long_gu001.txt
>
> In the terminal, even a compound phrase like the following works without a
> hitch:
>
> ➜  ~ git:(master) ✗ cd /path/to/1_long_gu ; docsplit text --no-clean -l
> chi_sim long_gu001.pdf ; docsplit text --no-clean -l eng long_gu002.pdf ;
> docsplit text --no-clean -l eng long_gu003.pdf ;...
> ➜  1_long_gu git:(master) ✗
>
> So, working from the terminal, I wind up with a series of text files in
> /path/to/1_long_gu
> that my Factor vocab amalgamates into a single text file (with whitespace in
> filename), e.g.,
> /path/to/1_long_gu/long gu.txt, which I can edit for mistakes, and upload to
> a couchdb database.
> Joy!
>
> But I haven't been able to work out how to accomplish this docsplit call
> from Factor code.
> I have no problem traversing the directory tree (Factor's word each-file &
> the like come in
> very handy). I've experimented with io.launcher, io.pipes, shell scripts
> (bash, zsh, factor),
> & autoload shell functions, but flunked out. No errors with io.launcher
> tries; just no result.
> Need to learn something here. I routinely launch couchdb as a detached
> .
>
> It would be such a boon to use docsplit in Factor. After a couple weeks lost
> at sea with this,
> I'm broadcasting a Mayday. Any suggestions?
>
> Thanks in advance,
> ~cw
>
> --
> ~ Memento Amori
>
> --
> Managing the Performance of Cloud-Based Applications
> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
> Read the Whitepaper.
> http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

--
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] docs.factorcode.org not doing a `load-all`?

2013-11-17 Thread Alex Vondrak
Just noticed that something I linked to a short time ago is now 404ing
because the doc index seems to have been built with an incomplete
image.  As of this writing,
http://docs.factorcode.org/content/vocab-formatting.html says "You
must first load this vocabulary to browse its documentation and words.
 USE: formatting"

Is it just this one vocab, or did something else change, like
docs.factorcode.org not doing a `load-all`?  Or maybe the server
started running with a different image recently?

I can open an issue, if need be.  Thought it might be a quick enough
fix to get an answer here.  If nothing else, consider this a PSA.

--
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Factor interface to Spotlight

2013-11-11 Thread Alex Vondrak
I have too much formatting (and email always has a way of wrecking
that), so I put a comment on the gist:
https://gist.github.com/cwalston/7368493#comment-948159

Have a good one,
--Alex Vondrak


On Mon, Nov 11, 2013 at 1:28 AM, CW Alston  wrote:
> Hi all-
>
>  Re-factoring 'spotlight.factor' worked better than SlimFast. "Look Ma, no
> files"!
> Much obliged for the pointers on how to set up commands for
> "with-process-reader".
>
>  I've replaced the code in the Gist previously posted with a revised,
> self-contained
> version. Please do take a look & beat on the code. It should compile fine
> simply
> pasted whole in the listener. I'm sure many query formatting cases aren't
> covered yet.
>
>  There are a passel of terminal examples to try to emulate at the end of the
> file.
> As there are myriad variations in formatting terminal commands, it would be
> good to
> have as general an interface from Factor as possible. I'd like to develop
> 'spotlight'
> into a practical utility. Suggestions? Feedback appreciated.
>
> Thanks kindly,
> ~ CW Alston
>
>
>
> On Sat, Nov 9, 2013 at 7:43 PM, CW Alston  wrote:
>>
>> Great help, folks!
>>
>> I think I can figure this out now. With a l'il more elbow-grease & your
>> pointers,
>> I'd like to make the 2 crutch files disappear, & access the MetaData index
>> in all its glory directly. That certainly would make this a much more
>> independent,
>> self-contained utility. Useful breakdown, Alex. Back to the drawing board.
>>
>> Thanks, all -
>> ~cw
>>
>>
>>
>> On Sat, Nov 9, 2013 at 8:36 AM, John Benediktsson 
>> wrote:
>>>
>>> This works for me, it has to be a string or sequence of strings:
>>>
>>> IN: scratchpad { "mdfind" "kMDItemComposer == 'Andrea Bocelli'" } utf8 [
>>> lines ] with-process-reader
>>>
>>> Anyway, I love this vocab and getting it to work is like 95% of the
>>> challenge, I think it would be fun to modify it to not require the
>>> indirection and contribute it to the main repository if you're interested!
>>>
>>> Best,
>>> John.
>>>
>>>
>>>
>>> On Fri, Nov 8, 2013 at 10:11 PM, CW Alston  wrote:
>>>>
>>>> Hi John,
>>>>
>>>> I can't get your suggestion to work with mdfind:
>>>>
>>>> > Why go through the indirection of a shell script and a query results
>>>> > rather than just preparing
>>>> > a sequence of args and then grabbing all the results, e.g.
>>>> > { mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'" } utf8 [ lines ]
>>>> > with-process-reader
>>>>
>>>> - Trying this command format (with a different MD Attribute) works fine
>>>> in the terminal:
>>>>
>>>> ➜  ~ git:(master) ✗ mdfind "kMDItemComposer == 'Dylan'"
>>>> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/11
>>>> Wedding Song.m4a
>>>> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/10 Never
>>>> Say Goodbye.m4a
>>>> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/09 You
>>>> Angel You.m4a
>>>> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/08
>>>> Dirge.m4a
>>>> ...
>>>> ➜  ~ git:(master) ✗
>>>>
>>>> - But trying the same command in the with-process-reader format fails in
>>>> the listener:
>>>>
>>>> IN: scratchpad { mdfind "kMDItemComposer == 'Dylan'" } utf8 [ lines ]
>>>> with-process-reader
>>>>
>>>> Process exited with error code 254
>>>>
>>>> Launch descriptor:
>>>>
>>>> T{ process
>>>> { command { mdfind "kMDItemComposer == 'Dylan'" } }
>>>> { environment H{ } }
>>>> { environment-mode +append-environment+ }
>>>> { stdout T{ fd { disposed t } { fd 23 } } }
>>>> { group +same-group+ }
>>>> { status 254 }
>>>> { pipe
>>>> T{ pipe
>>>> { in T{ fd { disposed t } { fd 19 } } }
>>>> { out T{ fd { disposed t } { fd 23 } } }
>>>> }
>>>> }
>>>> }
>>>> ---
>>>> -Switching single & double quotes

Re: [Factor-talk] Factor interface to Spotlight

2013-11-08 Thread Alex Vondrak
I guess io.launcher needs better examples...  They show how launch
descriptors are either strings or arrays, but they don't explain what
each means.  The details change by OS backend, but for Unix it works
like this:

- Given a sequence launch descriptor, { "a" "b" "c" }, io.launcher
uses exec-with-path
(http://docs.factorcode.org/content/word-exec-with-path,unix.process.html)
supplying "a" as the filename (the command to execute) and { "a" "b"
"c" } as ARGV: http://notabug.com/2002/coherent/man/argv.html  Thus,
each element of the array (past the first) should be a *single* token,
as provided to ARGV.

So instead of

  { "find -maxdepth 1 -type d" } utf8 [ lines ] with-process-reader .

or

  { "find" "-maxdepth 1 -type d" } utf8 [ lines ] with-process-reader .

or

  { "find" "-maxdepth 1" "-type d" } utf8 [ lines ] with-process-reader .

all of which break, you'd have to run

  { "find" "-maxdepth" "1" "-type" "d" } utf8 [ lines ] with-process-reader .

- Given a string launch descriptor, "a b c", the string gets
*tokenized* into such an array:
http://docs.factorcode.org/content/word-tokenize%2Csimple-tokenizer.html

Thus

  "find -maxdepth 1 -type d" utf8 [ lines ] with-process-reader .

works, because

  "find -maxdepth 1 -type d" tokenize

gives

  V{ "find" "-maxdepth" "1" "-type" "d" }

which is used as the launch descriptor.

Therefore, much like the examples I sent a few weeks back, I suspect
the following will work:

  "mdfind \"kMDItemComposer == 'Dylan'\"" utf8 [ lines ] with-process-reader .

My point in the examples I gave you a few weeks ago was that the
*real* thing to watch out for here is unexpected input or results that
may give non-zero exit statuses.  E.g., on my Linux box,

  "find /proc -name blah" utf8 [ lines ] with-process-reader

throws an error Factor-side because find's exit status is 1, since
find didn't have permission to read /proc.

Hope that helps,
--Alex Vondrak

On Fri, Nov 8, 2013 at 10:11 PM, CW Alston  wrote:
> Hi John,
>
> I can't get your suggestion to work with mdfind:
>
>> Why go through the indirection of a shell script and a query results
>> rather than just preparing
>> a sequence of args and then grabbing all the results, e.g.
>> { mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'" } utf8 [ lines ]
>> with-process-reader
>
> - Trying this command format (with a different MD Attribute) works fine in
> the terminal:
>
> ➜  ~ git:(master) ✗ mdfind "kMDItemComposer == 'Dylan'"
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/11 Wedding
> Song.m4a
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/10 Never Say
> Goodbye.m4a
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/09 You Angel
> You.m4a
> /Applications/Music/iTunes/iTunes Music/Bob Dylan/Planet Waves/08 Dirge.m4a
> ...
> ➜  ~ git:(master) ✗
>
> - But trying the same command in the with-process-reader format fails in the
> listener:
>
> IN: scratchpad { mdfind "kMDItemComposer == 'Dylan'" } utf8 [ lines ]
> with-process-reader
>
> Process exited with error code 254
>
> Launch descriptor:
>
> T{ process
> { command { mdfind "kMDItemComposer == 'Dylan'" } }
> { environment H{ } }
> { environment-mode +append-environment+ }
> { stdout T{ fd { disposed t } { fd 23 } } }
> { group +same-group+ }
> { status 254 }
> { pipe
> T{ pipe
> { in T{ fd { disposed t } { fd 19 } } }
> { out T{ fd { disposed t } { fd 23 } } }
> }
> }
> }
> ---
> -Switching single & double quotes around doesn't help:
> IN: scratchpad { mdfind 'kMDItemComposer == "Dylan"' } utf8 [ lines ]
> with-process-reader
>
> Error
> No word named “'kMDItemComposer” found in current vocabulary search path
> (however, mdfind 'kMDItemComposer == "Dylan"' works in terminal)
>
> ---
> -Ok, so trying various permutations of single, double, triple quotes in the
> command:
> IN: scratchpad { """mdfind "kMDItemComposer == 'Dylan'"""" } utf8 [ lines ]
> with-process-reader
>
> Process exited with error code 255
> (however, mdfind "kMDItemComposer == 'Dylan'" works in terminal)
>
> ---
> IN: scratchpad { """mdfind 'kMDItemComposer == "Dylan"'

Re: [Factor-talk] Why execute( will check stack effect in some cases but won't in others?

2013-10-30 Thread Alex Vondrak
Sure thing, all in a day's work, etc. :)

Maybe it could be fixed by some additional logic around whether the
`in` and `out` heights in primitive_check_datastack are 0?  Like, if
they're both 0 and the saved_height > 0, just push false_object?  I'm
not sure...plus, I'm pretty wary of introducing regressions by
changing the logic without thinking it through a lot.


On Wed, Oct 30, 2013 at 7:58 PM, John Benediktsson  wrote:
> Wow, Alex nice investigation!
>
> Thanks for looking into that.
>
>
>
>
> On Wed, Oct 30, 2013 at 7:46 PM, Alex Vondrak  wrote:
>>
>> Let me preface by saying you generally want to avoid `execute` and
>> `call`, except when implementing combinators
>> (http://docs.factorcode.org/content/article-combinators.html).  As
>> you've already seen, they might have some finicky behavior.  It's not
>> quite the same level of antipattern as "eval is evil", but it's always
>> felt similar to me.  Perhaps the following is a bit better:
>>
>> ```
>> USING: arrays combinators formatting fry kernel sequences
>> unicode.normalize ;
>>
>> : normalizations ( str -- norms )
>> {
>> [ nfc ]
>> [ nfd ]
>> [ nfkc ]
>> [ nfkd ]
>> } cleave 4array
>> [ [ "U+%04X" sprintf ] { } map-as ] map ;
>> ```
>>
>> That said...
>>
>> The reason this issue was tripped was because of `nfc`---and probably
>> the others, too, but `nfc` is the first one done in the `map`.
>>
>> `nfc` is defined like this:
>>
>> ```
>> USING: unicode.normalize.private ;
>> IN: unicode.normalize
>> : nfc ( string -- nfc ) [ (nfd) combine ] with-string ;
>> ```
>>
>> The `with-string` combinator that it uses is defined like this:
>>
>> ```
>> USING: accessors kernel ;
>> IN: unicode.normalize.private
>> : with-string ( str quot -- str )
>> over aux>> [ call ] [ drop ] if ; inline
>> ```
>>
>> Because the above word is inlined, `nfc` is "really" behaving like this:
>>
>> ```
>> : nfc ( string -- nfc )
>> [ (nfd) combine ] over aux>> [ call ] [ drop ] if ;
>> ```
>>
>> Thus, if the input string doesn't have an `aux` slot set, we don't do
>> any computation because the `[ (nfd) combine ]` quotation just gets
>> `drop`ped.  It's as though we defined it as just a no-op, like this:
>>
>> ```
>> : nfc ( string -- nfc ) ;
>> ```
>>
>> So, just take a look:
>>
>> ```
>> IN: scratchpad "Factor" aux>> .
>> f
>> IN: scratchpad "\xF1" aux>> .
>> B{ 0 0 }
>> ```
>>
>> Because of the above, the call to `"Factor" nfc` becomes a no-op, and
>> it *looks* to the Factor VM like `nfc` had the stack-effect `( -- )`.
>> So, the `execute( -- )` doesn't raise an error in this example.
>>
>> To get really technical, I think the reason the VM thinks the
>> stack-effect looks OK is because of how this primitive is implemented:
>> https://github.com/slavapestov/factor/blob/master/vm/contexts.cpp#L274
>>  Basically, the datastack before & after the call to `nfc` is exactly
>> the same, so it thinks the stack effect was `( -- )`.  But with
>> "\xF1", this isn't the case, and the error is thus caught.
>>
>> Hope that helps,
>> --Alex Vondrak
>>
>> On Wed, Oct 30, 2013 at 3:24 PM, OwnWaterloo 
>> wrote:
>> > I'm new to Factor and don't know how to minimize the code while get
>> > the similar behaviour. Sorry for that.
>> > But thanks to the expressiveness and good libraries of Factor the code
>> > won't be too long, I hope...
>> >
>> > Firstly, the primary goal is to normalize some unicode string.
>> > Formating the result will make it more clear. And I also want to learn
>> > the "Fried quotations".
>> > So I use the three vocabularies:
>> >
>> >   IN: scratchpad USING: unicode.normalize formatting fry ;
>> >   Loading resource:basis/formatting/formatting.factor
>> >   Loading resource:basis/formatting/formatting-docs.factor
>> >
>> > Then the implement it with correct stack effect declaration in
>> > "execute(" :
>> >
>> >   IN: scratchpad : normalizations ( str -- norm )
>> >'[ _ swap execute( x -- x ) ] ! correct stack effect declaration
>> >{ nfc nfd nfkc nfkd } swap map ! normalize str with four methods
>>

Re: [Factor-talk] The experience of the first day in Factor, or the naming problem.

2013-10-30 Thread Alex Vondrak
It's a common complaint, but the cynic in me thinks it's kind of how
the world works.  I mean, (silly example, but) I probably wouldn't
like being a biologist having to search for info about pythons
(http://www.google.com/search?q=python); yet no one's going to change
the name of a genus.  Not that programming projects haven't been
re-branded before, but...

Also, Factor's not exactly popular.  I'm not sure how much you'll find
outside of known resources anyway---including the docs, which are
actually searchable: try `"numbers" apropos` in the UI listener, or
hit up http://docs.factorcode.org/

--
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Why execute( will check stack effect in some cases but won't in others?

2013-10-30 Thread Alex Vondrak
Let me preface by saying you generally want to avoid `execute` and
`call`, except when implementing combinators
(http://docs.factorcode.org/content/article-combinators.html).  As
you've already seen, they might have some finicky behavior.  It's not
quite the same level of antipattern as "eval is evil", but it's always
felt similar to me.  Perhaps the following is a bit better:

```
USING: arrays combinators formatting fry kernel sequences
unicode.normalize ;

: normalizations ( str -- norms )
{
[ nfc ]
[ nfd ]
[ nfkc ]
[ nfkd ]
} cleave 4array
[ [ "U+%04X" sprintf ] { } map-as ] map ;
```

That said...

The reason this issue was tripped was because of `nfc`---and probably
the others, too, but `nfc` is the first one done in the `map`.

`nfc` is defined like this:

```
USING: unicode.normalize.private ;
IN: unicode.normalize
: nfc ( string -- nfc ) [ (nfd) combine ] with-string ;
```

The `with-string` combinator that it uses is defined like this:

```
USING: accessors kernel ;
IN: unicode.normalize.private
: with-string ( str quot -- str )
over aux>> [ call ] [ drop ] if ; inline
```

Because the above word is inlined, `nfc` is "really" behaving like this:

```
: nfc ( string -- nfc )
[ (nfd) combine ] over aux>> [ call ] [ drop ] if ;
```

Thus, if the input string doesn't have an `aux` slot set, we don't do
any computation because the `[ (nfd) combine ]` quotation just gets
`drop`ped.  It's as though we defined it as just a no-op, like this:

```
: nfc ( string -- nfc ) ;
```

So, just take a look:

```
IN: scratchpad "Factor" aux>> .
f
IN: scratchpad "\xF1" aux>> .
B{ 0 0 }
```

Because of the above, the call to `"Factor" nfc` becomes a no-op, and
it *looks* to the Factor VM like `nfc` had the stack-effect `( -- )`.
So, the `execute( -- )` doesn't raise an error in this example.

To get really technical, I think the reason the VM thinks the
stack-effect looks OK is because of how this primitive is implemented:
https://github.com/slavapestov/factor/blob/master/vm/contexts.cpp#L274
 Basically, the datastack before & after the call to `nfc` is exactly
the same, so it thinks the stack effect was `( -- )`.  But with
"\xF1", this isn't the case, and the error is thus caught.

Hope that helps,
--Alex Vondrak

On Wed, Oct 30, 2013 at 3:24 PM, OwnWaterloo  wrote:
> I'm new to Factor and don't know how to minimize the code while get
> the similar behaviour. Sorry for that.
> But thanks to the expressiveness and good libraries of Factor the code
> won't be too long, I hope...
>
> Firstly, the primary goal is to normalize some unicode string.
> Formating the result will make it more clear. And I also want to learn
> the "Fried quotations".
> So I use the three vocabularies:
>
>   IN: scratchpad USING: unicode.normalize formatting fry ;
>   Loading resource:basis/formatting/formatting.factor
>   Loading resource:basis/formatting/formatting-docs.factor
>
> Then the implement it with correct stack effect declaration in "execute(" :
>
>   IN: scratchpad : normalizations ( str -- norm )
>'[ _ swap execute( x -- x ) ] ! correct stack effect declaration
>{ nfc nfd nfkc nfkd } swap map ! normalize str with four methods
>[ >array [ "U+%04X" sprintf ] map ] map ; ! make it more clear
>
> It gives me the expected results except the last two(but it maybe not
> important to this question):
>
>   IN: scratchpad "Factor" normalizations .
>   {
>   { "U+0046" "U+0061" "U+0063" "U+0074" "U+006F" "U+0072" }
>   { "U+0046" "U+0061" "U+0063" "U+0074" "U+006F" "U+0072" }
>   { "U+0046" "U+0061" "U+0063" "U+0074" "U+006F" "U+0072" }
>   { "U+0046" "U+0061" "U+0063" "U+0074" "U+006F" "U+0072" }
>   }
>   IN: scratchpad "\xF1" normalizations .
>   {
>   { "U+00F1" }
>   { "U+006E" "U+0303" }
>   { "U+00F1" }
>   { "U+006E" "U+0303" }
>   }
>   IN: scratchpad "\x6E\u000303" normalizations .
>   {
>   { "U+00F1" }
>   { "U+006E" "U+0303" }
>   { "U+00F1" }
>   { "U+006E" "U+0303" }
>   }
>   IN: scratchpad "\u01D160" normalizations .
>   {
>   { "U+1D158" "U+1D165" "U+1D16E" }
>   { "U+1D158" "U+1D165" "U+1D16E" }
>   { "U

Re: [Factor-talk] command conundrum

2013-10-21 Thread Alex Vondrak
Maybe this whole thing is solved by going directly to the stream solution?

$ rlwrap ./factor -run=listener 2> /dev/null
IN: scratchpad USING: io.encodings.utf8 io.launcher ;
IN: scratchpad "find /home/alex/talks/factor -name *.pdf" utf8 [ lines
] with-process-reader .
{
"/home/alex/talks/factor/factor.pdf"
"/home/alex/talks/factor/factor-test.pdf"
}
IN: scratchpad "find /home/alex/talks/factor -name DOESNOTEXIST" utf8
[ lines ] with-process-reader .
{ }
IN: scratchpad "find /proc -name PERMISSION_DENIED_ERROR" utf8 [ lines
] with-process-reader .
Process exited with error code 1

Launch descriptor:

T{ process
{ command
"find /proc -name PERMISSION_DENIED_ERROR"
}
{ environment H{ } }
{ environment-mode +append-environment+ }
{ stdout T{ fd { disposed t } { fd 19 } } }
{ group +same-group+ }
{ status 1 }
{ pipe
T{ pipe
{ in T{ fd { disposed t } { fd 18 } } }
{ out T{ fd { disposed t } { fd 19 } } }
}
}
}

Type :help for debugging help.

See
- http://docs.factorcode.org/content/word-with-process-reader%2Cio.launcher.html
- http://docs.factorcode.org/content/word-lines,io.html
- General perusal of
http://docs.factorcode.org/content/article-io.launcher.html and
http://docs.factorcode.org/content/vocab-io.launcher.html

As for the original problem of I/O redirection, there seem to be some
docs on that at
http://docs.factorcode.org/content/article-io.launcher.redirection.html
and some examples in
http://docs.factorcode.org/content/article-io.launcher.examples.html

Hope that helps,
--Alex Vondrak

On Mon, Oct 21, 2013 at 2:26 AM, Björn Lindqvist  wrote:
> 2013/10/21 CW Alston :
>> ::  ( filename -- seq )
>>  "'kMDItemFSName == " filename tri-quotes-surround append  "'"
>> append ;
>>
>> :  ( filename -- process )
>>  ! ( -- seq )
>>  '[ "mdfind" , "-onlyin" , "/" , _ , ">" ,
>> "/Users/cwalston/factor/mdfind.txt" , ]
>>  { } make  ! ( -- seq )
>>swap >>command
>>   t >>detached clone  ! ( -- process )
>> ;
>>
>> And then, "Finding Joy in Combinators.pdf"  contains a
>> command
>> sequence that looks like this:
>> {
>> "mdfind"
>> "-onlyin"
>> "/"
>> "'kMDItemFSName == \"Finding Joy in Combinators.pdf\"'"
>> ">"
>> "/Users/cwalston/factor/mdfind.txt"
>> }
>
> The command>> attribute in  should be a string not a sequence
> of strings. I think that is the core of your problem, not sure. Also,
> input and output redirection is a feature of the shell, not the os, so
> you need to wrap those commands in a subshell. But that is platform
> dependent since not all shells are available everywhere and they dont
> all have the same features. Here is how you could write a find utility
> for Windows (using gnu find), maybe you can use it as a template:
>
> USING: formatting io.launcher kernel ;
> IN: cmdpipe
>
> CONSTANT: find-bin "C:\\Program Files (x86)\\Git\\bin\\find.exe"
>
> : shell-command ( str -- str' )
> "cmd /C \"%s\"" sprintf ;
>
> : find-command ( dir pattern out-path -- str )
> [ find-bin ] 3dip "\"%s\" \"%s\" -name \"%s\" > \"%s\"" sprintf ;
>
> : run-find ( dir pattern out-path -- proc )
> find-command shell-command run-process ;
>
> IN: scratchpad "C:\\Users\\bjourne\\Downloads" "*.pdf"
> "C:\\Users\\bjourne\\result.txt" run-find
>
>
> --
> mvh/best regards Björn Lindqvist
>
> --
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Drawing, and saving images

2013-10-14 Thread Alex Vondrak
It doesn't seem to be documented (nor is it particularly advanced),
but I had some luck with simple image drawing by looking into the
images.processing vocab:
https://github.com/slavapestov/factor/blob/master/basis/images/processing/processing.factor

For example, try the following in the UI listener:

USING: images.processing images.viewer ;
{
{ 1 1 1 1 1 }
{ 1 0 1 0 1 }
{ 1 1 1 1 1 }
{ 0 1 1 1 0 }
{ 0 0 0 0 0 }
{ 1 1 1 1 1 }
} flip 10 matrix-zoom matrix>image image.

For loading/saving images, see the images.loader vocab:
http://docs.factorcode.org/content/vocab-images.loader.html

There could very well be better libraries that I'm simply unaware of.
It might help to peruse
http://docs.factorcode.org/content/vocab-images.html

The UI vocabs also come to mind:
http://docs.factorcode.org/content/vocab-ui.html  Not sure if they'll
be of much help here, though.  But an example of a polygon in the UI
anyway:

USING: colors.constants ui.pens.polygon ui.gadgets.panes ;
"black" named-color { { 0 0 } { 100 100 } { 200 0 } }
 gadget.

Hope that's enough to get you started (or at least until someone with
a better answer comes along),
--Alex Vondrak

On Sun, Oct 13, 2013 at 10:43 PM, Alf Mikula  wrote:
> Hey everybody,
>
> I'm having a little bit of trouble getting started, and I'd appreciate any
> help that anyone can offer.
>
> I'm looking for a simple example on how to draw lines and polygons, and how
> to save the results in an image, such as a jpg or png file.
>
> Can anybody provide an example, or point me in the right direction?
>
> Thanks,
>
> -Alf
>
> --
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Mind reviewing my code?

2013-10-10 Thread Alex Vondrak
Overall, the code is readable.  Nice work!

It's a bit odd to have a separate private.factor file on its own.  The
only Factor project to do this (in my git pull from July) is
unmaintained:

$ find . -name private.factor
./unmaintained/alien/marshall/private/private.factor

More common is to use `` syntax in the same file:

$ grep -l "http://docs.factorcode.org/content/word-__lt__PRIVATE,syntax.html

A few things I noticed (mind you, it's late at night for me right now):

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/market-movers.factor

All around, you use a lot of `{ } nsequence`.  For one, you can use
http://docs.factorcode.org/content/word-1array,arrays.html  For
another, you're defining words to calculate constants.  Consider
instead using the literals vocab:
http://docs.factorcode.org/content/article-literals.html

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/market-movers.factor?at=default#cl-38

Consider using http://docs.factorcode.org/content/word-C__colon__,syntax.html

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor

All around, you seem to have some long lines.  The style convention is
to keep source code 64 characters wide:
http://docs.factorcode.org/content/word-margin,prettyprint.config.html

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-12

Couldn't this be a `CONSTANT:`?  I mean, if you even want to bother
defining it as such, instead of just inlining the regular expression
into `extract-symbols`.

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-14

Don't worry, the length is constant-folded by the compiler already:

IN: scratchpad USE: compiler.tree.debugger
IN: scratchpad [ [ "q?s=" length + ] 2dip ] optimized.
[ "COMPLEX SHUFFLE" 4 + "COMPLEX SHUFFLE" ]

That said, I think code like

USE: splitting

"q?s=FB\">"
"q?s=" ?head drop
"\">" ?tail drop

might be clearer.  But it's a minor point, and you have to balance
that with the fact that `map-matches` is already giving you input
suitable for `subseq`, so you might as well just use that (like you're
doing already).

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-26

product-sequences already implement the sequences protocol; I doubt
you need to call `>array`.

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-28

Consider using http://docs.factorcode.org/content/word-map-sum%2Csequences.html

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-30

You could simplify the logic slightly, if you're so inclined:

: symbol-locations ( assoc key -- hash-set )
swap [ [ HS{ } clone or ] change-at ] [ at ] 2bi ;

Oh, by the way, `assoc` is a more typical stack-effect name than
`hashtable`.  See
http://docs.factorcode.org/content/article-conventions.html

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-34

`[ p ] keep q` is the same as `[ p ] [ q ] bi`.  Here, `[ category>> ]
[ group>> ] bi`.

https://bitbucket.org/jherron/market-movers/src/tip/yahoo/finance/market-movers/private/private.factor?at=default#cl-37

In general, I find `reduce` hard to read.  It looks like you're using
it to try to preserve & return the hashtable at the end.  I'm not
sure, and I won't hazard to rewrite the logic myself in my current
state, but you might be able to just pass around a reference to the
hashtable in a more conventional iteration:

    IN: scratchpad H{ } clone { 1 2 3 } over '[ dup 100 * _ set-at ] each .
H{ { 100 1 } { 200 2 } { 300 3 } }

Hope that helps & happy hacking,
--Alex Vondrak


On Wed, Oct 9, 2013 at 8:10 PM, Jon Herron
 wrote:
> That would be very cool. I'd love to contribute if anyone else would find it
> helpful.
>
> The repo is @ https://bitbucket.org/jherron/market-movers
>
> Thanks for taking the time.
>
> Jon
>
>
> On Wednesday, October 9, 2013 8:05 PM, John Benediktsson 
> wrote:
> Sure, send a link to your code.  We'd be happy to review.  Also, I have some
> support for getting quotes from Yahoo! Finance - maybe you could contribute
> some of your work to the project:
>
> https://github.com/mrjbq7/re-factor/blob/master/yahoo/finance/finance.factor
>
>
>
> On Oct 9, 2013, at 7:53 PM, Jon Herron 
> wrote:
>
> Hi all -
>
>   In my spare time I am working on a backtesting application and I've
> decided

Re: [Factor-talk] Factor packaging for Ubuntu

2013-08-26 Thread Alex Vondrak
On Mon, Aug 26, 2013 at 12:45 AM, Björn Lindqvist  wrote:
> The binary name "factor" was already taken by a program in coreutils
> so I had to change it to "factor-run".

How about something like "factor-lang" or "factor-listener"?

Just a thought,
--Alex Vondrak

--
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Indentation width and other style guidelines

2013-07-21 Thread Alex Vondrak
Yeah, that seems like a problem.  The convention is 4 spaces.

I thought for sure it was documented somewhere, but the closest I could
find was the prettyprinter's control variables (
http://docs.factorcode.org/content/article-prettyprint-variables.html),
which are set to:

  4 tab-size set-global
  64 margin set-global

It'd be cool to have a lint tool for this.  There seem to be a few vocabs
lying around that are 2-space indented:

  $ grep -l "^ \{2\}[^ ]" **/*.factor | wc -l
  226
  $ grep -l "^ \{4\}[^ ]" **/*.factor | wc -l
  3402

I know the 64-character line-length limit isn't obeyed globally.

  $ grep -l ".\{65,\}" **/*.factor | wc -l
  3035
  $ ls **/*.factor | wc -l
  4309
  $ grep -l ".\{65,\}" **/!(*-docs).factor | wc -l
  2362
  $ ls **/!(*-docs).factor | wc -l
  3622

I get the feeling it's a less religious matter than Python.  But 4 space
indentation is still clearly the standard.

The prettyprinter's not perfect, but it might help if you're trying to
decide how to split up a long expression.  For example, there's code in
alien.endian indented like this:

```
nip
[
[
[ alien-unsigned-4 4 f byte-reverse 32 shift ]
[ 4 + alien-unsigned-4 4 f byte-reverse ] 2bi bitor
]
] dip [ [ 64 >signed ] compose ] when
```

If we give it to the prettyprinter, we get back nearly the same thing:

```
IN: scratchpad [ nip [ [ [ alien-unsigned-4 4 f byte-reverse 32 shift ] [ 4
+ alien-unsigned-4 4 f byte-reverse ] 2bi bitor ] ] dip [ [ 64 >signed ]
compose ] when ] .

[
nip [
[
[ alien-unsigned-4 4 f byte-reverse 32 shift ]
[ 4 + alien-unsigned-4 4 f byte-reverse ] 2bi bitor
]
] dip [ [ 64 >signed ] compose ] when
]
```

Not perfect, but gives you a general idea.  And the prettyprinter's output
for the above isn't awful.

Documenting these conventions would clearly be better, of course...

Hope that helps,
--Alex Vondrak
--
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Using find-by-class in html.parser.analyzer

2013-07-15 Thread Alex Vondrak
On Mon, Jul 15, 2013 at 12:11 PM, Mark Green wrote:

> I expect it could be written up as a quotation.
>

Maybe something like this?

```
IN: scratchpad "mmm, candy
bar" parse-html
[ "class" attribute "foo" swap subseq? ] find-all .
{
{
2
T{ tag
{ name "div" }
{ attributes H{ { "class" "food is good" } } }
}
}
}
```

Or like this?

```
IN: scratchpad "mmm, candy
bar" parse-html
[ "class" attribute " " split "food" swap member? ] find-all .
{
{
2
T{ tag
{ name "div" }
{ attributes H{ { "class" "food is good" } } }
    }
}
}
```

Just some ideas; I'm sure this could/should all be factored out into the
proper helper words.

Regards,
--Alex Vondrak
--
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Using find-by-class in html.parser.analyzer

2013-07-14 Thread Alex Vondrak
No docs apparently (and unfortunately), but I suppose you can get a feel
for what the words do by looking at the source + tests.  That's what I've
done to give you this reply, anyhow.  :-)

I'm not sure how you were invoking the word before to not see the desired
behavior---I'm guessing probably on a raw HTML string, like

```
"bar"
"foo" find-by-class
```

which results in a cryptic error.  It turns out the word is actually
supposed to be called on a vector of `tag` tuples, which you can generate
using the `parse-html` word from html.parser:

```
IN: scratchpad "bar" parse-html
"foo" find-by-class

--- Data stack:
2
T{ tag f "div" H{ ~array~ } f f }
```

Because it uses `find`, this leaves two values on the stack: the index of
the element, and the element itself---a `tag` instance.
http://docs.factorcode.org/content/word-find,sequences.html

To find *every* tag with the given class, there's apparently no predefined
word.  But I do spy a `find-all` helper:

```
IN: scratchpad "bar" parse-html
[ "class" attribute "foo" = ] find-all .
{
{
2
T{ tag
{ name "div" }
{ attributes H{ { "class" "foo" } } }
}
}
{
3
T{ tag
{ name "p" }
{ attributes H{ { "class" "foo" } } }
}
}
}
```

In general, I'm not sure if html.parser is very mature compared to, say,
the XML vocab: http://docs.factorcode.org/content/article-xml.html

```
IN: scratchpad "bar" string>xml
"foo" "class" deep-tags-with-attr children-tags [
"Found: " write xml>string print
] each
Found: bar
Found: bar
```

But there are some answers anyway.

Hope that helps,
--Alex Vondrak

On Sun, Jul 14, 2013 at 3:52 PM, Mark Green wrote:

> Hi,
>
> Is there any documentation for find-by-class in html.parser.analyzer? I'm
> not sure what it does. It doesn't seem to search for elements with a given
> value in the class attribute and I'm not sure how it would return them
> anyway (is it a filter?)
>
> Thanks!
>
>
>
> --
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Bresenham Linedraw: unbalanced conditionals

2013-07-04 Thread Alex Vondrak
ble-juggling, because I have the state packaged up into one
parameter.  I don't even need to have return values from the other words
I'm calling, because they'll be destructive on the state.  And you'll see
I'm easily breaking the problem down into calls to other words.  Aside: the
name `?move-x` can be read as "maybe move x", by convention.

```
:: bresenham's-algorithm ( state -- )
[
[ t ] [
state plot
state done? [ return ] when
state ?move-x
state done? [ state plot return ] when
state ?move-y
] while
] with-return ;
```

The `done?` check looks to see if the current point (p) matches the end
point (q).  Because I'm representing points as tuples, calling `=` on them
will compare their respective slots' values.  Points only have the `x` slot
and the `y` slot, so `point0 point1 =` effectively works like the "x0 = x1
and y0 = y1" pseudocode.

```
: done? ( state -- ? ) [ p>> ] [ q>> ] bi = ;
```

`?move-x` and `?move-y` are the "meat" of the algorithm.  They happen to
use locals, but only so we can conveniently extract the right parts of the
state.  Since we're using tuple slots to store the state (look ma, no
variables!), we can just use words like change-x, change-y, and
change-error.  Not only does it read pretty well, but it will modify the
tuple we're pointing to ("the stack" is a stack of pointers) without us
worrying about returning any fancy values on the stack or using
destructive! local! variables!.

```
:: ?move-x ( state -- )
state error>> 2 *
state dy>> neg > [
state p>> [ state sx>> + ] change-x drop
state [ state dy>> - ] change-error drop
] when ;

:: ?move-y ( state -- )
state error>> 2 *
state dx>> < [
state p>> [ state sy>> + ] change-y drop
state [ state dx>> + ] change-error drop
] when ;
```

Finally, though I have the freedom to define `plot` however I want, my
thought was to collect the points of the line into one sequence.  This is
where `make` comes in.  The final two words I define are:

```
: plot ( state -- ) p>> clone , ;

: draw-line ( from to -- points )
 [ bresenham's-algorithm ] { } make ;
```

Note that I have to clone the `p>>`, because I'm destructively updating the
point's coordinates as I loop.  If I didn't `clone`, then `draw-line` would
return an array of references to the same point tuple in memory---so each
element of the sequence would have the same coordinates!

So, with the clone, I get:

```
IN: scratchpad 1 1  11 5  draw-line .
{
T{ point { x 1 } { y 1 } }
T{ point { x 2 } { y 2 } }
T{ point { x 3 } { y 2 } }
T{ point { x 4 } { y 3 } }
T{ point { x 5 } { y 3 } }
T{ point { x 6 } { y 3 } }
T{ point { x 7 } { y 4 } }
T{ point { x 8 } { y 4 } }
T{ point { x 9 } { y 5 } }
T{ point { x 10 } { y 5 } }
T{ point { x 11 } { y 5 } }
}
```

Without the clone, I'd get:

```
IN: scratchpad 1 1  11 5  draw-line .
{
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
T{ point { x 11 } { y 5 } }
}
```

because each element would be a pointer to the same tuple. :)

Now, if you want to play with my code as a base, I leave you with this
challenge / suggested improvement: instead of having a static `plot` word,
modify it so that a user can pass in their own quotation to do whatever
plotting they want---draw a pixel on the screen, set an array coordinate,
print a message, send commands to a robot, whatever.  Essentially, turn the
`bresenham's-algorithm` word into a combinator that acts on each point
along the line.  Then my `make`-based definition could be something like

```
 [ [ clone , ] each-point ] { } make
```

and your code to set grid cells could be something like

```
  '[ _ set-cell ] each-point
```

and so on.

Hope that helps,
--Alex Vondrak
--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Bresenham Linedraw: unbalanced conditionals

2013-07-03 Thread Alex Vondrak
On Wed, Jul 3, 2013 at 5:47 PM, Mark Green wrote:

> Thanks very much for your reply, Alex. I only have a few minutes to post
> but I can reply to some of these :)
>
> 4 - Is it permissible to include declarations of that type inside a word
> definition that's using the local variable syntax? I did want to put a
> description of the quotation into the stack effect but I wasn't sure if I
> could do it while at the same time giving the local variable holding the
> quotation a name. In your example, is the quotation variable named "quot"?
>

Ah, I missed that part!  You're right, that doesn't get along with locals.


> 5 - It's the Bresenham linedraw code taken from the Wikipedia page; the
> final optimised version on that page.
>

I had found that and am now spending my evening attempting to understand
it.  :-)

Hope I'll be able to help after studying this,
--Alex Vondrak
--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Bresenham Linedraw: unbalanced conditionals

2013-07-03 Thread Alex Vondrak
1. As a style thing, use hyphens to separate the "words" in your names:
cell-address, cell-at, do-cell! (probably better-named change-cell, to be
consistent with the convention of "changer" words), set-cell, do-line.

2. Short-circuiting can be accomplished with short-circuit combinators:
http://docs.factorcode.org/content/article-combinators.short-circuit.htmlE.g.,

  { [ cy by = ] [ cx bx = ] } 0&& [ f continue! ] when

3.  Isn't your "continue" logic just trying to break out of the loop at
some specific point?  I.e., if this were a C-style language, you'd just use
a break statement?  If so, you could look into with-return:
http://docs.factorcode.org/content/word-with-return,continuations.html

4.  Your stack effects would read better if you followed the naming
conventions: http://docs.factorcode.org/content/article-effects.html  Also
worth doing is declaring the "nested" stack-effects of the input
quotations.  E.g.,

:: change-cell ( array x y quot: ( elt -- newelt ) -- ) ... ;

5.  In general, I can't make heads or tails of do-line.  Is there a working
C-style implementation you're trying to port?  If so, could you link to it?

Regards,
--Alex Vondrak

On Wed, Jul 3, 2013 at 11:18 AM, Mark Green wrote:

> Hi,
>
> Thanks very much for the previous help. Since then I've tried to refine
> the Bresenham routine a bit and did actually get it working, but then
> decided to indulge my functional-programmer urges and try to make it higher
> level. Unfortunately, this hit another problem..
>
> The idea of doline is that it takes two coordinates and a quotation,
> traces a line between the coordinates, and calls the quotation at each
> point along the line, leaving the x and y coordinates on the stack for it.
> The quotation is expected to leave two value on the stack itself: a
> "return" value which is what doline should return if that's the end of the
> line, and a "continue" value which specifies if the quotation wants to
> force the line loop to halt at that point. The line loop may halt without
> being forced if it has reached the destination coordinate, which is why the
> quotation is always expected to push a return and continue value, rather
> than only pushing a return if continue is f.
>
> The problem, is after calling the quotation, if the quotation's continue
> value is t (ie, it doesn't want to halt) and the line has not reached the
> end, then an unused return value is left on the stack and I want to drop
> it. Unfortunately it seems that there is no conditional function that will
> allow me to drop a value based on a condition, as all of the conditions
> seem to require that the stack is balanced on both sides of the
> conditional. So this code refuses to compile because of the drop inside the
> when block. Is there any way of doing this?
>
> (Also, is the manual short circuit optimization of "and" into two whens
> necessary or would the compiler have done it automatically? And, the code
> is still.. um, rather C-like.. is there a way to style this better?)
>
> Mark
>
>
> ! Create a new 10x10 grid
> :  ( -- byte-array ) 100  ;
>
> ! Get address of cell x,y
> : celladdress ( n n -- n ) 10 * + ;
>
> ! Get value of cell at x,y
> : cellat ( byte-array n n -- n ) celladdress swap nth ;
>
> ! Do operation on cell at x,y
> :: docell! ( array x y op -- ) x y celladdress array op change-nth ; inline
>
> ! Set value of cell at x,y
> :: setcell! ( array x y val -- )  array x y [ drop val ] docell! ; inline
>
> :: doLine ( ax ay bx by code -- codeout )
>  bx ax - abs :> dx!
>  by ay - abs :> dy!
>  dx dy - :> err!
>  t :> continue!
>  ax :> cx!
>  ay :> cy!
>  [ continue ] [
> cx cy code call continue!
> cy by = [ cx bx = [ f continue! ] when ] when
> [ continue ] [ drop
>   err 2 *
>   dup 0 dy - > [ err dy - err! cx dx sgn + cx! ] when
>   dx < [ err dx + err! cy dy sgn + cy! ] when
> ] when
>  ] while ; inline
>
> :: los? ( map ax ay bx by -- bool ) ax ay bx by [| cx cy | map cx cy
> cellat 0 = dup ] doLine ;
>
>
> --
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] RFC: AES implementation

2013-06-27 Thread Alex Vondrak
Hey Fred,

I haven't gotten the time to look at this code thoroughly, but I just
wanted to say (before too much time passes) that I'm pleased to see an
optimized version come out of the woodwork.  I'm unfamiliar with all the
ways that AES gets optimized in the wild, so porting a project's actual
implementation is really interesting.  I look forward to reading your code
more carefully.

> All of this may turn out to be just an academic exercise on my part.  ;-)

Well, strictly speaking I assume implementing crypto on your own (even
existing algorithms) is usually an academic exercise regardless, unless
you're an expert cryptographer working on an established crypto library.
Cf.
http://web.archive.org/web/20130121031415/http://chargen.matasano.com/chargen/2009/7/22/if-youre-typing-the-letters-a-e-s-into-your-code-youre-doing.html

Doesn't mean it's not fun.  :)

Regards,
--Alex Vondrak

On Sun, Jun 16, 2013 at 10:32 AM, Fred Alger  wrote:

>  Oh my, this is what I get for not reading the Factor mailing list.
>
> I've done my own independent implementation of crypto.aes:
> https://github.com/phred/factor/tree/implement-aes
>
> It's based on the original, which used 7zip's infuriatingly optimized C
> implementation as a reference.  It uses 32-bit integer arithmetic and
> lookup tables for encrypt and decrypt.
>
> Reading through the smart commentary in this thread, I've already found
> some cleanup to do.  I'd also like to benchmark my code.
>
>
> All of this may turn out to be just an academic exercise on my part.  ;-)
>
> I actually find Gabriel's "pure" implementation much more aesthetically
> pleasing than my own.  Lookup tables muddy the code's readability, and feel
> more like "hey, I'm shoehorning C into Factor" than an elegant expression
> of the core AES algorithms.  Adding OpenSSL bindings also limits the
> utility of a "pure Factor" optimized lookup-table implementation (unless we
> can get close to OpenSSL's numbers, that'd be wicked!)
>
> So pleased to see that the community's chugging along!  It will be nice to
> have a working crypto.aes implementation in the core.  I don't wish to
> compete for submission to the project, nor step on anyone's toes.
>
> Some notes on my implementation:
> ---
> I used HOOKs to implement a generic AES "crypt" algorithm, which to me
> seems concise and elegant:
> : (aes-crypt) ( aes -- aes' )
> (first-round) [
> dup nrounds>> (counter)
> [ [ (do-round) ] dip add-round-key drop ] with each
> ] keep
> (final-round) ;
>
> aes-encrypt and aes-decrypt "strategies" provide their own implementations
> of the (first-round), (final-round), etc. words.
>
> I tried to use the '-unsafe' sequence words, inline, and unrolled-map
> wherever I could in the implementation.  This was more of a sprinkling of
> "hey, that'd be good" rather than driven by hard benchmark numbers.
>
> Your feedback is most welcome.  Thanks!
>
> --
> Fred Alger
> @_phred
>
>
>
> --
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] RFC: AES implementation

2013-06-06 Thread Alex Vondrak
Great work!  Nice-looking code.

The only things I notice now are just curiosities.  I can see a lot of
`map`s and such involved, and wonder if you could gain any performance by
using the destructive equivalents.  See
http://docs.factorcode.org/content/article-sequences-destructive.html and
some extra words in
http://docs.factorcode.org/content/vocab-sequences.extras.html  In
particular, the double `flip` in `shift-rows` caught my eye, but I'm not
sure there are any existing words to help for that use-case.

Another curiosity: I wonder if some `inline` declarations would help
tighten up the compiled code.  Most of the word definitions are pretty
short, and are involved in a lot of loops.  Something to experiment with.
http://docs.factorcode.org/content/word-inline,syntax.html

Although, I guess you probably stand to gain more from using uints instead
of arrays (though byte-arrays were a good move!).  Speaking of which, I
don't think `inv-sub-bytes` gets typed like `sub-bytes` (an untyped `[
inv-sbox nth ] map` vs the typed `sub-word`).  In case it makes a
difference.  :-)

Good stuff,
--Alex Vondrak

On Thu, Jun 6, 2013 at 8:42 AM, Gabriel Kerneis wrote:

> On Thu, Jun 06, 2013 at 06:58:53AM -0700, Doug Coleman wrote:
> > Nice job! The ``inv-sbox`` problem is that ``sbox`` is not compiled yet.
>
> Oh, I didn't expect CONSTANT: to need a compilation, but it makes sense in
> hindsight.
>
> Thanks,
> --
> Gabriel
>
>
> --
> How ServiceNow helps IT people transform IT departments:
> 1. A cloud service to automate IT design, transition and operations
> 2. Dashboards that offer high-level views of enterprise services
> 3. A single system of record for all IT processes
> http://p.sf.net/sfu/servicenow-d2d-j
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] RFC: AES implementation

2013-06-06 Thread Alex Vondrak
Also, using OpenSSL to compare was a great idea!  And a good idea for a
real-world library besides---"never roll your own crypto" and all that.
But at least it's still fun to see AES done in Factor.

Regards,
--Alex Vondrak

On Thu, Jun 6, 2013 at 9:36 AM, Alex Vondrak  wrote:

> Great work!  Nice-looking code.
>
> The only things I notice now are just curiosities.  I can see a lot of
> `map`s and such involved, and wonder if you could gain any performance by
> using the destructive equivalents.  See
> http://docs.factorcode.org/content/article-sequences-destructive.html and
> some extra words in
> http://docs.factorcode.org/content/vocab-sequences.extras.html  In
> particular, the double `flip` in `shift-rows` caught my eye, but I'm not
> sure there are any existing words to help for that use-case.
>
> Another curiosity: I wonder if some `inline` declarations would help
> tighten up the compiled code.  Most of the word definitions are pretty
> short, and are involved in a lot of loops.  Something to experiment with.
> http://docs.factorcode.org/content/word-inline,syntax.html
>
> Although, I guess you probably stand to gain more from using uints instead
> of arrays (though byte-arrays were a good move!).  Speaking of which, I
> don't think `inv-sub-bytes` gets typed like `sub-bytes` (an untyped `[
> inv-sbox nth ] map` vs the typed `sub-word`).  In case it makes a
> difference.  :-)
>
> Good stuff,
> --Alex Vondrak
>
>
> On Thu, Jun 6, 2013 at 8:42 AM, Gabriel Kerneis wrote:
>
>> On Thu, Jun 06, 2013 at 06:58:53AM -0700, Doug Coleman wrote:
>> > Nice job! The ``inv-sbox`` problem is that ``sbox`` is not compiled yet.
>>
>> Oh, I didn't expect CONSTANT: to need a compilation, but it makes sense in
>> hindsight.
>>
>> Thanks,
>> --
>> Gabriel
>>
>>
>> --
>> How ServiceNow helps IT people transform IT departments:
>> 1. A cloud service to automate IT design, transition and operations
>> 2. Dashboards that offer high-level views of enterprise services
>> 3. A single system of record for all IT processes
>> http://p.sf.net/sfu/servicenow-d2d-j
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
>
--
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] RFC: AES implementation

2013-05-27 Thread Alex Vondrak
On Mon, May 27, 2013 at 11:18 AM, Gabriel Kerneis wrote:

> I kept the implementation provided by crypto.aes for this one.  I too
> wondered what was going on at first, but it is in fact correct thanks to
> "8 bits" which gets rid off leading "1" bits.
>

Ohhh, that makes sense.  Thanks for the clarification!

--Alex Vondrak
--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] RFC: AES implementation

2013-05-27 Thread Alex Vondrak
Warning: stream of thought/opinion.  I'm pretty prone to bikeshedding.

1) The first thing I noticed was the code representing words as 4-byte
arrays, which initially made me see red---red ink, that is, from all my
memories of getting stuck grading college students' AES implementations.
:-) But I see you're aware of it.  It's probably a nice "next step" to
take.  This is also the first I've seen of Factor's math.bits /
math.bitwise vocabs.  Very nice, indeed.  Might consider another virtual
sequence for words, then the implementations might not have to change.
Although, I'm not sure if a virtual sequence could even translate rot-word
(i.e., `cut-slice prepend`) into a simple rotational bitwise shift...

2) `sbox` could be defined as a `CONSTANT:`.
http://docs.factorcode.org/content/article-words.constant.html

3) You could use the `literals` vocab for `rcon` to make it a constant,
too: `CONSTANT: rcon $[ 0x01 11 make-xtime ]`.  Might run into parse-time
problems, I suppose, in which case `MEMO:` is perfectly suitable.  I see
`t-table` and `d-table` are defined as such, which is probably what you
were following.  http://docs.factorcode.org/content/article-literals.html

4) Whenver you use `sbox` or `inv-sbox`, you immediately have to call
`nth`.  It might be nice to have words like `: sub-byte ( b -- b' ) sbox
nth ; inline`.

5) Am I missing something, or is `xtime` using 0x1b where it should be
using 0x11b?

6) I would call `nxtime` something like `mult` or `gf-mult`, since it's
multiplication in GF(2^8) modulo m(x) = x^8 + x^4 + x^3 + x + 1.  And I'd
probably use a more meaningful stack effect declaration, like ( a(x) b(x)
-- a(x)*b(x) ) or even ( a(x) b(x) -- a(x)*b(x)%m(x) ).  Then, I think
`nxtime` is a better name for what `make-xtime` is currently doing (calling
`xtime` `n` times).  Maybe `nxtimes`, so it reads like "n `xtimes`s".

7) It's technically OK, but uncommon to see stack effects like you have on
`xor-word`.  ( word word -- word ) reads like "takes two of the same value,
outputs an unchanged value".  If you were to use locals, it wouldn't even
work out correctly:

  IN: scratchpad :: foo ( a a -- a ) a a + ;
  IN: scratchpad 100 2 foo .
  4

You could go with a lengthy stack effect like ( word1 word2 -- word1^word2
), or at least give the values distinct names like ( a b -- c ), though
that's clearly a worse declaration because a, b, and c are meaningless.

Similarly, you'd more commonly see stack effects like ( state -- state' )
rather than the ( state -- state ) you have on various words.

8) It'd be spiffy to wrap all this implementation into some `encrypt` and
`decrypt` words that would crank through a sequence/stream of bytes and
encrypt/decrypt block-wise.  So that, for example, you could
encrypt/decrypt an entire file.  But then, this gets into block cipher
modes, so I'm sure there are subtleties to iron out there...I'm no
cryptographer.

All in all, good work!  I'm impressed by how short & simple all the word
definitions are, coming from grading Java implementations.

Nice job,
--Alex Vondrak



On Mon, May 27, 2013 at 10:39 AM, John Benediktsson wrote:

> Two general approaches, where both run the garbage collector before timing
> or profiling:
>
> 1) basic timing information;
>
> gc [ foo ] time
>
> (or if the word is slow, run it a few times)
>
> gc [ 1,000 [ foo ] times ] time
>
> 2) profiling
>
>gc [ foo ] profile
>
>This saves the profile, allowing you to view it various ways:
>
>top-down profile.
>top-down-max-depth profile.
>flat profile.
>
>Etc
>
>
>
> On May 27, 2013, at 10:19 AM, Gabriel Kerneis 
> wrote:
>
> > On Mon, May 27, 2013 at 09:51:04AM -0700, John Benediktsson wrote:
> >> Nice!  Have you had a chance to look at performance?
> >
> > Not yet, but this is on my TODO list.  I'm working on ECB and CBC modes,
> so it's
> > probably worth finishing that first and then test with large files.
> >
> > Is there any recommanded way to benchmark execution time (or performance
> in
> > general) in Factor?
> >
> > Best regards,
> > --
> > Gabriel
> >
> >
> --
> > Try New Relic Now & We'll Send You this Cool Shirt
> > New Relic is the only SaaS-based application performance monitoring
> service
> > that delivers powerful full stack analytics. Optimize and monitor your
> > browser, app, & servers with just a few lines of code. Try New Relic
> > and get this awesome Nerd Life shirt!
> http://p.sf.net/sfu/newrelic_d2d_may
> > ___
> > Factor-talk mailing

Re: [Factor-talk] List Comprehension in Factor

2013-05-20 Thread Alex Vondrak
Oo, or even

: triples ( n -- seq )
iota rest 3 [ first3 triple? ] filter-combinations ;


On Mon, May 20, 2013 at 7:06 PM, Alex Vondrak  wrote:

> Or, going by the algorithms in the wiki:
>
> ```
> USING: arrays kernel locals math math.ranges sequences
> sequences.extras ;
>
> :: triples ( n -- seq )
> n [1,b] [| x |
> x n [a,b] [| y |
> y n [a,b]
> [| z | x sq y sq + z sq = ]
> [| z | x y z 3array ]
> filter-map
> ] map concat
> ] map concat ;
> ```
>
> Fun bug report: using `map-concat` from `sequences.extras` fails to
> compile for me---complains about using `call` on a run-time computed value.
>
> But, I really like your approach using `all-combinations`.  It yields a
> much nicer-looking version:
>
> ```
> : triple? ( x y z -- ? )
> [ sq ] tri@ [ + ] dip = ;
>
> : triples ( n -- seq )
>     iota rest 3 all-combinations [ first3 triple? ] filter ;
> ```
>
> Regards,
> --Alex Vondrak
>
>
>
> On Mon, May 20, 2013 at 8:18 AM, _ _  wrote:
>
>> ! Copyright (C) 2013 Your name.
>> ! See http://factorcode.org/license.txt for BSD license.
>> USING: kernel sequences math math.functions arrays math.combinatorics ;
>> IN: pythagorean-triples
>>
>> : a-b-list ( n -- seq )
>> iota rest 2 all-combinations ;
>>
>> : a-b-c ( seq1 -- seq2 )
>> [ first ]
>> [ second ]
>> [ [ first sq ] [ second sq ] bi + sqrt ]
>> tri
>> 3array ;
>>
>> : a-b-c-list ( n -- seq )
>> a-b-list [ a-b-c ] map ;
>>
>> : float.0? ( n -- ? )
>> dup floor 0 ~ ;
>>
>> : (pythagoreans) ( n -- seq )
>> a-b-c-list [ third float.0? ] filter ;
>>
>> : pythagoreans ( n -- seq )
>> (pythagoreans) [ [ first ] [ second ] [ third >integer ] tri 3array ]
>> map ;
>>
>>
>> --
>> AlienVault Unified Security Management (USM) platform delivers complete
>> security visibility with the essential security capabilities. Easily and
>> efficiently configure, manage, and operate all of your security controls
>> from a single console and one unified framework. Download a free trial.
>> http://p.sf.net/sfu/alienvault_d2d
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>
>
--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] List Comprehension in Factor

2013-05-20 Thread Alex Vondrak
Or, going by the algorithms in the wiki:

```
USING: arrays kernel locals math math.ranges sequences
sequences.extras ;

:: triples ( n -- seq )
n [1,b] [| x |
x n [a,b] [| y |
y n [a,b]
[| z | x sq y sq + z sq = ]
[| z | x y z 3array ]
filter-map
] map concat
] map concat ;
```

Fun bug report: using `map-concat` from `sequences.extras` fails to compile
for me---complains about using `call` on a run-time computed value.

But, I really like your approach using `all-combinations`.  It yields a
much nicer-looking version:

```
: triple? ( x y z -- ? )
[ sq ] tri@ [ + ] dip = ;

: triples ( n -- seq )
iota rest 3 all-combinations [ first3 triple? ] filter ;
```

Regards,
--Alex Vondrak



On Mon, May 20, 2013 at 8:18 AM, _ _  wrote:

> ! Copyright (C) 2013 Your name.
> ! See http://factorcode.org/license.txt for BSD license.
> USING: kernel sequences math math.functions arrays math.combinatorics ;
> IN: pythagorean-triples
>
> : a-b-list ( n -- seq )
> iota rest 2 all-combinations ;
>
> : a-b-c ( seq1 -- seq2 )
> [ first ]
> [ second ]
> [ [ first sq ] [ second sq ] bi + sqrt ]
> tri
> 3array ;
>
> : a-b-c-list ( n -- seq )
> a-b-list [ a-b-c ] map ;
>
> : float.0? ( n -- ? )
> dup floor 0 ~ ;
>
> : (pythagoreans) ( n -- seq )
> a-b-c-list [ third float.0? ] filter ;
>
> : pythagoreans ( n -- seq )
> (pythagoreans) [ [ first ] [ second ] [ third >integer ] tri 3array ]
> map ;
>
>
> --
> AlienVault Unified Security Management (USM) platform delivers complete
> security visibility with the essential security capabilities. Easily and
> efficiently configure, manage, and operate all of your security controls
> from a single console and one unified framework. Download a free trial.
> http://p.sf.net/sfu/alienvault_d2d
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] site down

2013-05-04 Thread Alex Vondrak
Looks like it's back now.  I'm guessing it was this:
https://github.com/slavapestov/factor/issues/882


On Fri, May 3, 2013 at 11:35 PM, mr w  wrote:

> Site down, no posts ... factorcode rapture?
>
>
> --
> Get 100% visibility into Java/.NET code with AppDynamics Lite
> It's a free troubleshooting tool designed for production
> Get down to code-level detail for bottlenecks, with <2% overhead.
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap2
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Confused about run-pipeline

2013-04-22 Thread Alex Vondrak
Well, there's your problem: you don't want `run-pipeline` at all.  :)

  IN: scratchpad "echo \"Hi\"" run-detached my-process set-global
  IN: scratchpad my-process get-global .
  T{ process
  { command "echo \"Hi\"" }
  { environment H{ } }
  { environment-mode +append-environment+ }
  { group +same-group+ }
  { status 0 }
  }

`run-pipeline` is like a series of Unix pipes.  So,

  { "cat log.txt" "grep error" "sort" "uniq" } run-pipeline

is like typing

  $ cat log.txt | grep error | sort | uniq

at a bash prompt.  Except not every element of the pipeline has to be a
process descriptor---you can insert Factor code along the way.

Roughly, it works by sequentially calling `run-pipeline-element` on each
item in your sequence.  `run-pipeline-element` is defined by:

  IN: scratchpad \ run-pipeline-element see-methods
  USING: combinators destructors io io.pipes.private kernel
  quotations ;
  M: callable run-pipeline-element
  [
  [ [ ?reader ] [ ?writer ] bi* ] dip
  [ ( -- result ) call-effect ] curry with-streams*
  ] with-destructors ;

  USING: accessors destructors io.launcher io.pipes.private kernel
  ;
  M: object run-pipeline-element
  [ >process swap >>stdout swap >>stdin run-detached ]
  [ drop [ [ dispose ] when* ] bi@ ] 3bi wait-for-process ;

I.e., it's already calling `run-detached` on anything in the pipeline
that's just a process description.  Otherwise, it expects a quotation that
takes no inputs, produces one output, and then calls that quotation with
the I/O streams rebound.  E.g.,

  IN: scratchpad { "cat /tmp/patch" [ readln >string ] } run-pipeline .
  {
  0
  "diff --git a/basis/prettyprint/prettyprint-tests.factor
b/basis/prettyprint/prettyprint-tests.factor"
  }

We see that the result of the first item in the pipeline is 0 (the exit
code of cat), and the result of the second item in the pipeline the output
from the Factor quotation, which it read from standard-input.  Except that
standard-input was bound to the output of the prior pipeline element (the
output of cat).

Hope that helps,
--Alex Vondrak
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Factor 0.96 now available

2013-04-21 Thread Alex Vondrak
I got asked an interesting question that I didn't know the answer to.  Any
thoughts on the 1.0 timeline?  What sort of goals are we setting for that?
I mean, the last time Slava threatened to release a 1.0 was in 2008, aiming
for 2009:
http://factor-language.blogspot.com/2008/08/factor-is-now-five-years-old.html
And we only have a few minor versions left to use!

Also, it occurs to me that we've yet to do a GSoC.  Isn't that time
approaching soon?  (This probably enters the scope of a different thread...)

--Alex Vondrak


On Sat, Apr 20, 2013 at 9:44 PM, John Benediktsson  wrote:

> "You're smart too late and old too soon." - Mike Tyson
>
> I'm very pleased to announce the release of Factor 0.96! You can
> find download links on the Factor website:
>
> http://factorcode.org
>
> This release is brought to you with over 1,100 commits by the following
> individuals:
>
> Alex Vondrak, Benjamin Pollack, Daniel Nagel, Doug Coleman, John
> Benediktsson, Jon Harper, Michael T. Richter, and @PGGB.
>
> Aside from bug fixes and various library improvements, I want to highlight
> the
> following changes:
>
> * Major compiler improvements (thanks Alex Vondrak!):
>   * Global Value Numbering (disabled currently by default)
>   * Parallel-Copy Semantics
> * Performance improvements to hashtables, hash-sets, heaps, and
> bloom-filters.
> * Support for Retina Displays on OS X
> * Greatly improved table gadget performance
> * PDF streams (and related PDF documentation)!
> * Speed up math comparisons
> * Support resize-window (thanks Jon Harper!)
> * New logo and icons for Factor
> * Added editor support for Textadept, Sublime Text, Geany, BBEdit, and
> XCode.
>
> Some possible backwards compatibility issues:
>
> * Changed , , and  to use slices.
> * Removed , , .
> * Renamed editors.notepadpp to editors.notepad++.
>
> For more details, please see the full announcement at:
>
> http://re-factor.blogspot.com/2013/04/factor-0-96-now-available.html
>
>
> --
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Factor 0.96 now available

2013-04-21 Thread Alex Vondrak
We should write a bingo vocabulary that integrates with some hacker-news /
reddit submission API so we can play whenever there's a new release:

"Good to see Factor isn't dead."
"What ever happened to Slava?"
"Does it have native threading yet?"
"Does it compile to [insert unsupported CPU architecture here]?  Why not?"
"Is there a Learn You A Factor For Great Good yet?"
"Where can I find some examples of Factor code?  Not the standard library,
I just mean code that does something nontrivial in an idiomatic way."
"I played with Factor one afternoon.  Didn't like it."
"I should really try Factor one of these days..."
"What's wrong with Haskell's (.) function?"
"Forth is stupid; by extension, so is Factor."
"So, it's basically like Forth?"
"It should be more like Forth."
"This is even more confusing than HP calculators."
"I love HP calculators, so it stands to reason that Factor should be like
an HP calculator."
"So, the only data structure you have is a stack?  Isn't that inefficient?"
"So, it's like Lisp but all your code is a stack instead of a linked list?"
"Stack languages are too low-level."
"Why would I want to manipulate the call-stack by hand?"
"It's impossible to program without variable names."
"Stacks are cute, but postfix is too confusing for the Real World."
"You have to read it backwards!"
"Infix languages are easier to read because I know an infix language."
"But what about arithmetic expressions?  Betcha didn't think of that!"
"What's the point of having another language if there are already
Turing-complete ones just lying around?"

I kid.  :)  The discussion's actually been pretty tame, especially on
reddit.

--Alex Vondrak



On Sat, Apr 20, 2013 at 9:44 PM, John Benediktsson  wrote:

> "You're smart too late and old too soon." - Mike Tyson
>
> I'm very pleased to announce the release of Factor 0.96! You can
> find download links on the Factor website:
>
> http://factorcode.org
>
> This release is brought to you with over 1,100 commits by the following
> individuals:
>
> Alex Vondrak, Benjamin Pollack, Daniel Nagel, Doug Coleman, John
> Benediktsson, Jon Harper, Michael T. Richter, and @PGGB.
>
> Aside from bug fixes and various library improvements, I want to highlight
> the
> following changes:
>
> * Major compiler improvements (thanks Alex Vondrak!):
>   * Global Value Numbering (disabled currently by default)
>   * Parallel-Copy Semantics
> * Performance improvements to hashtables, hash-sets, heaps, and
> bloom-filters.
> * Support for Retina Displays on OS X
> * Greatly improved table gadget performance
> * PDF streams (and related PDF documentation)!
> * Speed up math comparisons
> * Support resize-window (thanks Jon Harper!)
> * New logo and icons for Factor
> * Added editor support for Textadept, Sublime Text, Geany, BBEdit, and
> XCode.
>
> Some possible backwards compatibility issues:
>
> * Changed , , and  to use slices.
> * Removed , , .
> * Renamed editors.notepadpp to editors.notepad++.
>
> For more details, please see the full announcement at:
>
> http://re-factor.blogspot.com/2013/04/factor-0-96-now-available.html
>
>
> --
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] matrices

2013-04-16 Thread Alex Vondrak
Couple of tips (I don't really have anything to add about the algorithm,
just pointing out stylistic things in case they help):

- In `col-of-n`, instead of `[ drop ] dip`, use `nip`.

- If [ p ] and [ q ] have stack effects ( x y z -- a ), then `3dup p [ q ]
dip` is just the same as `[ p ] [ q ] 3bi`.  So, instead of

  : different-row-different-col? ( size n m -- ? )
  3dup same-row? not [ same-col? not ] dip and ;

you could write

  : different-row-different-col? ( size n m -- ? )
  [ same-row? not ] [ same-col? not ] 3bi and ;

- Similarly, instead of

  : coeffs-minors ( matrix -- coeffs minors )
  dup coeffs
  swap minors ;

you could write

  : coeffs-minors ( matrix -- coeffs minors )
  [ coeffs ] [ minors ] bi ;

- If p has the stack effect ( x -- y ), then instead of `swap p swap` you
can write `[ p ] dip`.  So, instead of

  : matrix-filter-index ( matrix1 quot -- matrix2 )
  swap concat swap  ! ( flattened quot )
  filter-index'
  flat-to-matrix ; inline

you could write

  : matrix-filter-index ( matrix1 quot -- matrix2 )
  [ concat ] dip filter-index' flat-to-matrix ; inline

- You've got an extra `+` in `ij-to-n`:

  : ij-to-n ( size row col -- n )
  [ * ] dip + ! already adds the elements
  + ; ! stack effect error

- You've got an unmatched `]` in your tests.

Regards,
--Alex Vondrak
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] optimizing refactorer

2013-04-10 Thread Alex Vondrak
Ugh.  Should think before hitting "send".

Point is, the code in `similarity` should count how many nodes are
different; in the case where one sequence is long than another, I wanted it
to effectively add the difference between the lengths (all the "remainder"
nodes on the longer sequence are necessarily different).  Which isn't what
the code in my previous message did.  Maybe just

: similarity ( def1 def2 -- score )
[ weighted-number-of-shared-nodes ]
[
identity-tuple new pad-longest
[ number-of-different-nodes ] 2map-sum
] 2bi over + / ;

I'll have to step away now, before I make more of a fool of myself.  :)

Spam spam spam,
--Alex Vondrak


On Wed, Apr 10, 2013 at 7:57 PM, Alex Vondrak  wrote:

> Self bug-report:
>
> IN: scratchpad [ 1 2 3 ] [ 1 ] similarity .
> 1
>
> Oh well.  Suppose we'd need
>
> : similarity ( def1 def2 -- score )
> [ weighted-number-of-shared-nodes ]
> [
> [ max-length ]
> [ [ number-of-different-nodes ] 2map-sum ] 2bi -
> ] 2bi over + / ;
>
> But again, a little ambiguous (treating sequences as n-ary trees).  Just a
> heuristic, I guess.
>
> --Alex Vondrak
>
>
>
> On Wed, Apr 10, 2013 at 7:51 PM, Alex Vondrak  wrote:
>
>> In case anyone's interested, attached is my interpretation of the "tree
>> similarity" metric given in the paper I linked.  The definition was
>> somewhat vague, so I just did what I thought made sense.
>>
>> IN: scratchpad \ move-to-file \ move-to-dir word-similarity .
>> 35/39
>> IN: scratchpad \ move-to-file \ usage word-similarity .
>> 0
>> IN: scratchpad \ move-to-dir \ move-to-dir word-similarity .
>> 1
>>
>> It would be interesting to implement the rest of the algorithm.  See how
>> it does in Factor.
>>
>> Regards,
>> --Alex Vondrak
>>
>>
>>
>> On Wed, Apr 10, 2013 at 6:35 PM, John Benediktsson wrote:
>>
>>> You don't really want a flattened intersection:
>>>
>>> A word definition like this:
>>>
>>> : foo ( x -- x ) [ 2^ ] [ bitor ] bi ;
>>>
>>> Shouldn't match ``set-bit``:
>>>
>>> : set-bit ( x n -- y ) 2^ bitor ; inline
>>>
>>> You probably want something that does something like a deep-each, then
>>> for each subsequence, collecting any subsequence that is a duplicate of all
>>> possible subsequences of all quotations, or something ambitious like that.
>>>
>>> In the lint vocabulary, the lint word looks at all callable's trying to
>>> find any definition that includes it as a subsequence:
>>>
>>> GENERIC: lint ( obj -- seq )
>>>
>>> M: callable lint
>>> [ lint-definitions-keys get-global ] dip [ subseq? ] curry
>>> filter ;
>>>
>>> M: object lint drop f ;
>>>
>>> M: word lint
>>> def>> [ callable? ] deep-filter [ lint ] map concat ;
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Apr 10, 2013 at 5:19 PM, leonard  wrote:
>>>
>>>> On Wed, Apr 10, 2013 at 2:33 PM, John Benediktsson wrote:
>>>>
>>>>> You should really look at how the lint tool works.
>>>>>
>>>>> In particular, look at "lint" and see how it looks for a word which
>>>>> has a definition that is contained in another word (where the second word
>>>>> should be calling the first instead of duplicating its definition).
>>>>>
>>>>> Your version could look for common subsequences instead, perhaps.
>>>>>
>>>>
>>>> Is there a word for calculating the intersection of two deep sequences?
>>>>
>>>>
>>>>
>>>> --
>>>> Precog is a next-generation analytics platform capable of advanced
>>>> analytics on semi-structured data. The platform includes APIs for
>>>> building
>>>> apps and a phenomenal toolset for data science. Developers can use
>>>> our toolset for easy data analysis & visualization. Get a free account!
>>>> http://www2.precog.com/precogplatform/slashdotnewsletter
>>>> ___
>>>> Factor-talk mailing list
>>>> Factor-talk@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>>
>>>>
>>>
>>>
>>> 

Re: [Factor-talk] optimizing refactorer

2013-04-10 Thread Alex Vondrak
Self bug-report:

IN: scratchpad [ 1 2 3 ] [ 1 ] similarity .
1

Oh well.  Suppose we'd need

: similarity ( def1 def2 -- score )
[ weighted-number-of-shared-nodes ]
[
[ max-length ]
[ [ number-of-different-nodes ] 2map-sum ] 2bi -
] 2bi over + / ;

But again, a little ambiguous (treating sequences as n-ary trees).  Just a
heuristic, I guess.

--Alex Vondrak



On Wed, Apr 10, 2013 at 7:51 PM, Alex Vondrak  wrote:

> In case anyone's interested, attached is my interpretation of the "tree
> similarity" metric given in the paper I linked.  The definition was
> somewhat vague, so I just did what I thought made sense.
>
> IN: scratchpad \ move-to-file \ move-to-dir word-similarity .
> 35/39
> IN: scratchpad \ move-to-file \ usage word-similarity .
> 0
> IN: scratchpad \ move-to-dir \ move-to-dir word-similarity .
> 1
>
> It would be interesting to implement the rest of the algorithm.  See how
> it does in Factor.
>
> Regards,
> --Alex Vondrak
>
>
>
> On Wed, Apr 10, 2013 at 6:35 PM, John Benediktsson wrote:
>
>> You don't really want a flattened intersection:
>>
>> A word definition like this:
>>
>> : foo ( x -- x ) [ 2^ ] [ bitor ] bi ;
>>
>> Shouldn't match ``set-bit``:
>>
>> : set-bit ( x n -- y ) 2^ bitor ; inline
>>
>> You probably want something that does something like a deep-each, then
>> for each subsequence, collecting any subsequence that is a duplicate of all
>> possible subsequences of all quotations, or something ambitious like that.
>>
>> In the lint vocabulary, the lint word looks at all callable's trying to
>> find any definition that includes it as a subsequence:
>>
>> GENERIC: lint ( obj -- seq )
>>
>> M: callable lint
>> [ lint-definitions-keys get-global ] dip [ subseq? ] curry
>> filter ;
>>
>> M: object lint drop f ;
>>
>> M: word lint
>> def>> [ callable? ] deep-filter [ lint ] map concat ;
>>
>>
>>
>>
>>
>> On Wed, Apr 10, 2013 at 5:19 PM, leonard  wrote:
>>
>>> On Wed, Apr 10, 2013 at 2:33 PM, John Benediktsson wrote:
>>>
>>>> You should really look at how the lint tool works.
>>>>
>>>> In particular, look at "lint" and see how it looks for a word which has
>>>> a definition that is contained in another word (where the second word
>>>> should be calling the first instead of duplicating its definition).
>>>>
>>>> Your version could look for common subsequences instead, perhaps.
>>>>
>>>
>>> Is there a word for calculating the intersection of two deep sequences?
>>>
>>>
>>>
>>> --
>>> Precog is a next-generation analytics platform capable of advanced
>>> analytics on semi-structured data. The platform includes APIs for
>>> building
>>> apps and a phenomenal toolset for data science. Developers can use
>>> our toolset for easy data analysis & visualization. Get a free account!
>>> http://www2.precog.com/precogplatform/slashdotnewsletter
>>> ___
>>> Factor-talk mailing list
>>> Factor-talk@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>>
>>>
>>
>>
>> --
>> Precog is a next-generation analytics platform capable of advanced
>> analytics on semi-structured data. The platform includes APIs for building
>> apps and a phenomenal toolset for data science. Developers can use
>> our toolset for easy data analysis & visualization. Get a free account!
>> http://www2.precog.com/precogplatform/slashdotnewsletter
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] optimizing refactorer

2013-04-10 Thread Alex Vondrak
In case anyone's interested, attached is my interpretation of the "tree
similarity" metric given in the paper I linked.  The definition was
somewhat vague, so I just did what I thought made sense.

IN: scratchpad \ move-to-file \ move-to-dir word-similarity .
35/39
IN: scratchpad \ move-to-file \ usage word-similarity .
0
IN: scratchpad \ move-to-dir \ move-to-dir word-similarity .
1

It would be interesting to implement the rest of the algorithm.  See how it
does in Factor.

Regards,
--Alex Vondrak



On Wed, Apr 10, 2013 at 6:35 PM, John Benediktsson  wrote:

> You don't really want a flattened intersection:
>
> A word definition like this:
>
> : foo ( x -- x ) [ 2^ ] [ bitor ] bi ;
>
> Shouldn't match ``set-bit``:
>
> : set-bit ( x n -- y ) 2^ bitor ; inline
>
> You probably want something that does something like a deep-each, then for
> each subsequence, collecting any subsequence that is a duplicate of all
> possible subsequences of all quotations, or something ambitious like that.
>
> In the lint vocabulary, the lint word looks at all callable's trying to
> find any definition that includes it as a subsequence:
>
> GENERIC: lint ( obj -- seq )
>
> M: callable lint
> [ lint-definitions-keys get-global ] dip [ subseq? ] curry
> filter ;
>
> M: object lint drop f ;
>
> M: word lint
> def>> [ callable? ] deep-filter [ lint ] map concat ;
>
>
>
>
>
> On Wed, Apr 10, 2013 at 5:19 PM, leonard  wrote:
>
>> On Wed, Apr 10, 2013 at 2:33 PM, John Benediktsson wrote:
>>
>>> You should really look at how the lint tool works.
>>>
>>> In particular, look at "lint" and see how it looks for a word which has
>>> a definition that is contained in another word (where the second word
>>> should be calling the first instead of duplicating its definition).
>>>
>>> Your version could look for common subsequences instead, perhaps.
>>>
>>
>> Is there a word for calculating the intersection of two deep sequences?
>>
>>
>>
>> --
>> Precog is a next-generation analytics platform capable of advanced
>> analytics on semi-structured data. The platform includes APIs for building
>> apps and a phenomenal toolset for data science. Developers can use
>> our toolset for easy data analysis & visualization. Get a free account!
>> http://www2.precog.com/precogplatform/slashdotnewsletter
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>
>
> --
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>


similarity.factor
Description: Binary data
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] optimizing refactorer

2013-04-10 Thread Alex Vondrak
On Wed, Apr 10, 2013 at 12:38 AM, leonard  wrote:

> We need to actually parse each word definition into an abstract syntax
> tree.
>
> We need to traverse each tree, from top to bottom, BFS.
>
> For each node, check whether an equivalent subtree occurs elsewhere.
>
> In code that doesn't use variables, equivalence should be easy to
> determine.
>

Luckily, building the AST is work you don't need to do, because that's how
Factor code is already represented:

: usage ( -- ) "Usage: move source ... target" print ;

: move-to-dir ( args -- )
dup last file-info directory?
[ unclip-last move-files-into ] [ drop usage ] if ;

IN: scratchpad \ move-to-dir def>> .
[
dup last file-info directory?
[ unclip-last move-files-into ] [ drop usage ] if
]
IN: scratchpad [ ] sequence? . ! quotations are sequences
t

Really, Factor words are just nested sequences (quotations), so they're
already a tree structure.

Wikipedia ( http://en.wikipedia.org/wiki/Duplicate_code ) points to an
interesting and very relevant paper:
http://www.semanticdesigns.com/Company/Publications/ICSM98.pdf

Regards,
--Alex Vondrak
--
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Directed graph queries via closure?

2013-03-24 Thread Alex Vondrak
The graphs vocabulary is pretty primitive.  Until recently, it belonged to
Factor's core vocabulary root, used early-on in the bootstrapping process.
[1]  It was written awhile ago, using idioms that existed before the
current sets vocabulary. [2]  But mostly, it's not much of a
general-purpose graph library.  The only purpose it's built for is its
limited usage in cross-referencing (e.g., in the classes, tools.crossref,
and compilers.crossref vocabs).  There was some work on a better vocab, but
it's unmaintained and incomplete. [3]

The graphs vocab treats directed graphs as a hash table from a vertex to a
set of vertices representing its in-neighborhood a.k.a. predecessor set.
[4]  In various parts of the code base (not just the graphs vocab), you
still see hashtables getting used as sets [5], so hashtables like H{ { 1 1
} } are used instead of HS{ 1 }.  Thus, we get the following:

IN: scratchpad USE: graphs
IN: scratchpad H{ } ! this is our graph
IN: scratchpad 1 { 2 3 } pick add-vertex ! add the edges 1 -> 2 & 1 -> 3
IN: scratchpad . ! show the graph
H{ { 2 H{ { 1 1 } } } { 3 H{ { 1 1 } } } }

Alternatively, you could think of `add-vertex` as instead adding the edges
1 <- 2 & 1 <- 3.  Then the digraph becomes a hash table from vertices to
out-neighborhoods, and the `closure` word makes more sense.  But the docs
[7] insist on the above interpretation!  And it's a more ordinary way to
read the call---think like in graphviz, where you would write `1 -> { 2 3
}`.

The `closure` word computes the transitive closure of the graph [6] at a
given vertex---telling us which vertices are reachable from the input
vertex.  Instead of taking a graph as its input, it takes a quotation that
tells you how to get the in/out-neighborhood of any given vertex.  Now, the
way the graphs vocab is set up, this pretty much means you'll get the
transitive closure flowing in the *backwards* direction of your edges,
because your hashtable will only be able to access the vertex's
in-neighborhood.  Which is confusing!  But again, suitable for the graphs
vocab's usages.

An example would be clearer.  So, say we set up the following:

IN: scratchpad USE: graphs
IN: scratchpad H{ } clone ! our graph
IN: scratchpad 1 { 2 } pick add-vertex ! 1 -> 2
IN: scratchpad 2 { 3 } pick add-vertex ! 2 -> 3
IN: scratchpad 3 { 4 } pick add-vertex ! 3 -> 4
IN: scratchpad dup . ! our graph: 1 -> 2 -> 3 -> 4
H{ { 4 H{ { 3 3 } } } { 2 H{ { 1 1 } } } { 3 H{ { 2 2 } } } }
IN: scratchpad '[ _ at ] ! quot to get the in-neighborhood of a vertex

Now we can start querying the `closure`.  But somewhat confusingly, it's a
"backwards" closure.  Maybe think of it as the closure of the graph "4 -> 3
-> 2 -> 1" instead of "1 -> 2 -> 3 -> 4".

IN: scratchpad 1 over closure .
H{ { 1 1 } }
IN: scratchpad 2 over closure .
H{ { 1 1 } { 2 2 } }
IN: scratchpad 3 over closure .
H{ { 1 1 } { 2 2 } { 3 3 } }
IN: scratchpad 4 over closure .
H{ { 1 1 } { 2 2 } { 3 3 } { 4 4 } }

Or how about trying this graph on for size?

IN: scratchpad H{ } clone
IN: scratchpad 1 { 2 3 } pick add-vertex
IN: scratchpad 2 { 4 5 } pick add-vertex
IN: scratchpad 3 { 6 } pick add-vertex
IN: scratchpad '[ _ at ]
IN: scratchpad 6 over closure .
H{ { 1 1 } { 6 6 } { 3 3 } }
IN: scratchpad 5 over closure .
H{ { 1 1 } { 5 5 } { 2 2 } }
IN: scratchpad 4 over closure .
H{ { 4 4 } { 1 1 } { 2 2 } }
IN: scratchpad 3 over closure .
H{ { 1 1 } { 3 3 } }
IN: scratchpad 2 over closure .
H{ { 1 1 } { 2 2 } }
IN: scratchpad 1 over closure .
H{ { 1 1 } }

Now, the duplicated code in the classes vocab has a much shorter
explanation: that was John fucking around with speed improvements a couple
weeks back. :) [8]  He uses HS{ } instead of H{ } to represent the sets,
since (as explained) H{ } is kind of vestigial.  Then, sets:members is used
to turn the HS{ } into a sequence. [9]

Hope that helps,
--Alex Vondrak

[1] See
http://factor-language.blogspot.com/2010/01/factors-bootstrap-process-explained.htmlfor
more on that.  Pretty much all the links are now broken, but you can
easily track down the source code at https://github.com/slavapestov/factor

[2]
https://github.com/slavapestov/factor/commit/0f0571e48ad5e91d5fdf3717204d3812f0e72787

[3]
https://github.com/slavapestov/factor/tree/master/unmaintained/graph-theory

[4] https://en.wikipedia.org/wiki/Adjacent_%28graph_theory%29#Direction

[5] http://docs.factorcode.org/content/article-assocs-sets.html

[6] https://en.wikipedia.org/wiki/Transitive_closure#In_graph_theory

[7] http://docs.factorcode.org/content/word-add-vertex%2Cgraphs.html

[8]
https://github.com/slavapestov/factor/commit/03e6f48943c767d286e402b5c1833e8673339b3dWhich,
incidentally, is also around the time graphs got moved from core to
basis:
https://github.com/slavapestov/factor/commit/3ffacf75d269d58f6f28fe14590f6e472a6fa6cf

[9] http://docs.factorcode.or

Re: [Factor-talk] a script

2013-03-16 Thread Alex Vondrak
On Sat, Mar 16, 2013 at 6:05 AM, Fox McCloud  wrote:

> Wondering if one stock symbol is typed incorrectly.
>
> Is there a way to determine the specific value in a sequence on which map
> fails?
>

In the UI listener, clicking the "Traceback" button on top of an error
dialog will let you see the data & call stacks at the time of the error.
In the command-line listener, type `:s` and `:c` to see the data & calls
stacks, respectively.  Here, "call stack" isn't even a Factor-specific
concept: it's just like the stack trace you'd get from most other languages.

In the interest of "teaching a man to fish", I won't point out the issue
you're having, but it becomes pretty obvious when you take a look.  Your
hunch is on the right track.  :)

Hope that helps,
--Alex Vondrak
--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Raw string syntax in Factor

2013-02-24 Thread Alex Vondrak
Good work!  Glad you were able to learn enough from the docs & source alone.

Only suggestion I have is that instead of `124`, you can use `CHAR: |`.  If
you try it out in the listener, you'll see that it just pushes `124` onto
the stack.  But it obviously reads much better!  Unfortunately, the
listener can be misleading, because when it shows you the source code of a
word, it'll just show an integer even if the actual source code uses the
`CHAR:` word.

It also occurs to me that raw strings probably need to support some sort of
escape sequences, if only for their delimiters (i.e., how do you include a
pipe character in your string?).  For the use-case of Windows paths, this
version of course does fine.  But just in case you want to get an idea of
how Factor parses escape sequences in normal strings, take a look through
https://github.com/slavapestov/factor/blob/master/core/strings/parser/parser.factor

--Alex Vondrak

On Sun, Feb 24, 2013 at 7:38 AM, Joan Arnaldich wrote:

> Hi there!
>
> I'm beginning to give Factor a try as a replacement for the shell. We
> use Windows at work and wanted to have something like Python's raw
> string syntax so I can use unescaped backslashes for paths.
>
> I skimmed through the help system and couldn't find the feature, so I
> decided to roll my own parsing word. All in all it was something easy
> to do and an interesting experience for a beginner, so I blogged
> about it: http://jarnaldich.me/2013/02/24/raw-strings-in-factor.html
>
> ... but, of course, being one of the first things I code in Factor,
> maybe I just got it completely wrong... so any
> corrections/comments/suggestions will be welcome.
>
> Thanks!
>
> Jan.
>
>
>
> --
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] matrices

2013-02-07 Thread Alex Vondrak
On Thu, Feb 7, 2013 at 4:24 PM, Leonard P  wrote:

> Also looking for an example implementation of a virtual sequence.
>

http://docs.factorcode.org/search?search=virtual+sequence
takes you to
http://docs.factorcode.org/content/article-virtual-sequences.html
which, for instance, takes you to
http://docs.factorcode.org/content/word-reversed%2Csequences.html
which gives you all the code actually used to implement the `reversed`
virtual sequence, with further links to documentation for the words whose
definitions you see (like `virtual@`).

Hope that helps,
--Alex Vondrak
--
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] matrices

2013-02-07 Thread Alex Vondrak
On Thu, Feb 7, 2013 at 4:11 PM, Leonard P  wrote:

> Before going that far, not sure how to define constructors and make-matrix.
>

http://docs.factorcode.org/content/article-tuples.html and in particular
http://docs.factorcode.org/content/article-tuple-constructors.html may be
of help, if you aren't sure about how constructors are defined.

--Alex Vondrak
--
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Iterating over arrays and string

2013-01-20 Thread Alex Vondrak
What about adding to the list at
https://github.com/slavapestov/factor/blob/master/basis/compiler/tree/propagation/known-words/known-words.factor#L224as
a stop gap?

--Alex Vondrak

On Sun, Jan 20, 2013 at 11:44 AM, John Benediktsson wrote:

> I noticed this before and made a patch:
>
>
> https://github.com/slavapestov/factor/commit/cd6026e70efef3416d08160cd7cbaa5f67d8e0c7
>
> But then reverted it, because of some test failures that asserted the
> image size was below a certain size.
>
>
> https://github.com/slavapestov/factor/commit/3b94eb5fb78d72af9b6fd25f706008d21bf81c09
>
> I think it would be best to inline these words, but the side effects
> should be looked at...
>
>
> On Sun, Jan 20, 2013 at 8:26 AM, Joe Groff  wrote:
>
>> On Sun, Jan 20, 2013 at 8:20 AM, Alex Vondrak wrote:
>>
>>> and noticed the same types being inferred (object vs string).  So,
>>> looking at the definitions,
>>>
>>>   IN: scratchpad \ >array see
>>>   USING: sequences ;
>>>   IN: arrays
>>>   : >array ( seq -- array ) { } clone-like ;
>>>   IN: scratchpad \ >string see
>>>   USING: sequences ;
>>>   IN: strings
>>>   : >string ( seq -- str ) "" clone-like ; inline
>>>
>>> we notice that >array isn't inlined, while >string is.  So perhaps the
>>> type
>>> information of >array isn't getting propagated because it's not inlined?
>>
>>
>> That's it. Inlining `>array` makes `{ } like` propagate its type as you'd
>> expect.
>>
>> -Joe
>>
>>
>> --
>> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
>> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
>> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
>> MVPs and experts. ON SALE this month only -- learn more at:
>> http://p.sf.net/sfu/learnmore_123012
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>
>
> --
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_123012
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Iterating over arrays and string

2013-01-20 Thread Alex Vondrak
> This is a bug. It should know that `M\ array like` returns an array. (Why
> it's unable to infer that from the definition isn't immediately obvious to
> me—from the definition of `M\ array like` it seems to me it ought to.)
> Monkey-patching an `{ array } declare` onto the end of the method makes it
> optimize as you'd expect.

Using compiler.tree.debugger to check out the type propagation,

  [ "" like ] cleaned-up-tree .

indeed infers an output type of `string`, while

  [ { } like ] cleaned-up-tree .

infers an output type of `object`.  Checking out the definitions of both
`like`
methods, I tried looking at

  [ >array ] cleaned-up-tree .

vs

  [ >string ] cleaned-up-tree .

and noticed the same types being inferred (object vs string).  So, looking
at the definitions,

  IN: scratchpad \ >array see
  USING: sequences ;
  IN: arrays
  : >array ( seq -- array ) { } clone-like ;
  IN: scratchpad \ >string see
  USING: sequences ;
  IN: strings
  : >string ( seq -- str ) "" clone-like ; inline

we notice that >array isn't inlined, while >string is.  So perhaps the type
information of >array isn't getting propagated because it's not inlined?

--Alex Vondrak
--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] matrices

2013-01-12 Thread Alex Vondrak
The thing with Turing completeness is that it says something about the
capabilities of a computational model (e.g., a programming language), not
the
practicality with which computations can be done.

Literally, Turing equivalence is saying: hey, instead of using that fancy
programming language, you could accomplish the same thing by using a long
strip
of paper and taking turns either writing a mark on a specific spot of the
paper, reading from a spot, or moving around to a different spot.

Thus, since Algol and Factor (and any other programming language we've been
able to think of) aren't doing anything that couldn't be done by using this
strip of paper, in principle they can express exactly the same computations.

However, in practice, it's not worth using the strip of paper---or even a
particular language, depending on your preferences. :)

> Wondering why the core Factor language was implemented with a compiler
> written in C.
>
> Why not implement Factor on top of an existing Forth?

It's entirely possible, sure.  Heck, Factor used to be written atop the JVM.
The reason to use C++ is really more social than technical.  C++ is much
more
ubiquitous than Forth, so people won't need to install a dependency they
don't
already have.  And despite Factor being stack-based, the representation
you're
working with by the time it gets to the *compiler* is fairly far removed
from
what Factor code actually looks like to the programmer.  So, using another
stack-based language to write the compiler doesn't really confer as many
benefits as you'd think.  In fact, a relatively small part of Factor is
written
in C++ anyway.  The optimizing compiler is written in Factor itself (which
is
interesting for its own reasons).  See
http://concatenative.org/wiki/view/Factor/FAQ/Implementation for more.

Regards,
--Alex Vondrak
--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] matrices

2013-01-12 Thread Alex Vondrak
> Then wondered if there is a way to factor out the remaining local.

Could just use fried quotations:

  : closest-upper-index ( n -- m )
  1 swap '[ dup fibonacci _ < ] [ 1 + ] while ;

> Imagine if it is possible to mimic every Algol construct in Factor with
> objects, quotations, and fry specifiers.

Strictly speaking, it already is possible...which isn't saying much:
https://en.wikipedia.org/wiki/Turing_completeness

> It would essentially make most languages/compilers obsolete, because one
> could "think" in Algol, in Factor.

As much as any one language makes another "obsolete", I suppose.

> "for" is a method on the counter object.

If `for` wouldn't be used on another type of object, it could just as well
be a
normal word.

> Only the result of quot3 gets left on the stack.
>
> Maybe there could be a generic iterator pattern that stores a hashmap of
> variables and quotes.

Seems like a lot of work to reinvent the `while` loop.  There's already
something to store "variables": the stack.  Also, it's explicit what you
want
to stay on the stack and what you want dropped, because you call some
variant
of `drop`.  For instance:

  $ grep -r "while [234]\?drop" *
  basis/json/reader/reader.factor:'[ _ stream-read1 dup ] [ scan ]
while drop ;
  basis/io/encodings/string/string.factor:[ reader stream-read1 dup
] [ buf push ] while drop
  basis/math/primes/factors/factors.factor:[ dupd /mod zero? ] curry [
nip [ 1 + ] dip ] while drop
  basis/random/sfmt/sfmt.factor:] while drop ;
  basis/random/random.factor:] while drop ;
  basis/random/random.factor:while drop ;
  basis/random/random.factor:[ [ 1 + ] 2dip [ random-unit log neg + ]
dip ] while 2drop ;
  basis/csv/csv.factor:[ row ] do while drop ;
  core/sorting/sorting.factor:while 2drop ; inline
  core/io/io.factor:[ dup ] compose swap while drop ; inline
  extra/pdf/layout/layout.factor:] while drop ;
  extra/images/atlas/atlas.factor:[ image-placements atlas-width @y
(pack-stripe) dup ] [ @y + @y! ] while drop
  extra/rosetta-code/happy-numbers/happy-numbers.factor:] while
2drop
  extra/rosetta-code/tree-traversal/tree-traversal.factor:] while drop
; inline
  extra/rosetta-code/luhn-test/luhn-test.factor:while drop ;
  extra/audio/wav/wav.factor:} cond ] while drop
  extra/audio/aiff/aiff.factor:} cond ] while drop
  extra/io/files/trash/unix/unix.factor:] while drop nip ;
  extra/tokyo/assoc-functor/assoc-functor.factor:] while 3drop ;
  extra/libudev/libudev.factor:while drop ; inline
  extra/reddit/reddit.factor:[ next-page ] while drop
  extra/project-euler/112/112.factor:] do while 2drop ;
  unmaintained/graph-theory/graph-theory.factor:   while 2drop ] swap
search-wrap ; inline
  unmaintained/adsoda/adsoda.factor:[ [ test-faces-combinaisons ] 2keep
1 - ] while drop ;

The reason I note `while` in particular being that `for` loops are really
just
variants of `while` in most languages:

  IN: scratchpad USE: combinators.smart
  IN: scratchpad : smart-bi ( p q -- ) [ keep-inputs ] dip call ; inline
  IN: scratchpad : for ( test update body -- ) swap [ smart-bi ] 2curry
while ; inline
  IN: scratchpad 1 [ dup 10 < ] [ 1 + ] [ . ] for drop
  1
  2
  3
  4
  5
  6
  7
  8
  9
  IN: scratchpad 1 10 [ 2dup < ] [ [ 1 + ] [ 1 - ] bi* ] [ 2array . ] for
2drop
  { 1 10 }
  { 2 9 }
  { 3 8 }
  { 4 7 }
  { 5 6 }

Though maybe there's a way to use smart combinators to get rid of the last
iteration's "update" return values, so you don't have to drop them
explicitly.
Or, don't use smart combinators at all, and make explicit words like `for`,
`2for`, etc.

Regards,
--Alex Vondrak


On Sat, Jan 12, 2013 at 3:12 AM, Leonard P  wrote:

> On Fri, Jan 11, 2013 at 9:47 AM, John Benediktsson wrote:
>>
>>> This should be a direct translation of that method, I think
>>>
>>> :: fibonacci? ( n )
>>> 1 [ dup fibonacci n < ] [ 1 + ] while fibonacci n = ;
>>>
>>
> Factored this to have only one reference to a local.
>
> :: closest-upper-index ( n -- m )
> 1 [ dup fibonacci n < ] [ 1 + ] while ;
>
> : closest-upper ( n -- m )
> closest-upper-index fibonacci ;
>
>
> : fibonacci? ( n -- ? )
> dup closest-upper = ;
>
> Then wondered if there is a way to factor out the remaining local.
>
> Wondering if there is a way to generalize a for loop, using [|.
>
> Here's the original Algol code ...
>
>
> boolean fibonacci?( int n ) {
>int i = 1;
>while( fibonacci( i ) < n ) {
>i++;
>}
> return fibonacci( i ) == n;
> }
>
> ... which is the same as ...
>
>
> boolean fibonacci?( int n ) {
>for( int i = 1; fibonacci( i ) &

Re: [Factor-talk] matrices

2013-01-10 Thread Alex Vondrak
Haven't looked at the code, but to answer your question about `for`-loops...

"for each" loops:
http://docs.factorcode.org/content/word-each,sequences.html
"for i = 0 up to n" loops: use `each` with
http://docs.factorcode.org/content/word-iota,sequences.html
If the iteration variable is just indexing into a sequence, you can use
http://docs.factorcode.org/content/word-each-index%2Csequences.html
"while" loops: http://docs.factorcode.org/content/word-while,kernel.htmland
the variant
http://docs.factorcode.org/content/word-until%2Ckernel.html

There are other variants; take a look through the words defined in vocabs
like `sequences`.   All else fails, there's good ol' fashioned tail
recursion: http://docs.factorcode.org/content/article-tail-call-opt.html

Hope these help,
--Alex Vondrak

On Thu, Jan 10, 2013 at 1:42 AM, Leonard P  wrote:

> Here's the algorithm ...
>
> Given n,
> generate successive fibonacci numbers,
> until a number greater than or equal to n is reached.
>
> If the number is equal to n, then n is a fibonacci number.
> If the number is greater than n, then n is not a fibonacci number.
>
> Sounds simple, but I don't see a way to do it recursively.
>
>
>
>
> --
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122712
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Parallel-copy branch

2012-12-26 Thread Alex Vondrak
Just forwarding this along to the list, because it probably gets better
visibility than an ancient github issue:
https://github.com/slavapestov/factor/issues/22#commit-ref-fdc2c16

Happy holidays,
--Alex Vondrak
--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] editors

2012-12-17 Thread Alex Vondrak
Another thought occurs.  Obviously you can edit code in whatever editor you
want.  But if using the UI listener is still annoying, you can run the
listener from the command line by invoking it with the proper flag, like
`./factor -run=listener`.  You can see
http://docs.factorcode.org/content/article-command-line.html for more
flags, if you're curious (though I don't think any others particularly help
here).

Hope that helps,
--Alex Vondrak


On Sun, Dec 16, 2012 at 11:46 PM, Leonard P  wrote:

> Is there a way to use vi to edit factor code?
>
> Graphical listener is slow on old machine.
>
>  - Leonard
>
>
> --
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] editors

2012-12-17 Thread Alex Vondrak
What about it didn't work?  Did you get an error?  Otherwise, what actually
happened, and how did that differ from what you expected?

--Alex Vondrak


On Mon, Dec 17, 2012 at 12:43 AM, Leonard P  wrote:

> On Mon, Dec 17, 2012 at 2:46 AM, Leonard P  wrote:
> > Is there a way to use vi to edit factor code?
> >
> > Graphical listener is slow on old machine.
> >
> >  - Leonard
>
> Eh, sorry, dumb question.
>
> Tried running the example at ...
>
> http://docs.factorcode.org/content/article-first-program-test.html
>
> Couldn't get this to work ...
>
> "palindrome" scaffold-tests
>
>
> --
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] vocabs

2012-12-16 Thread Alex Vondrak
Not much, but to the extent that there seems to be anything:

http://docs.factorcode.org/search?search=Lychrel
http://docs.factorcode.org/search?search=fractions

Or, from the listener, try (for example) `"fractions" apropos`.  But if the
image isn't aware of a particular vocab, it won't show up in the search
results.  The docs.factorcode.org stuff is generated after a `load-all`,
which (as you might guess) loads every vocabulary, so a search there should
comb through everything.

Hope that helps,
--Alex Vondrak



On Sun, Dec 16, 2012 at 7:05 PM, Leonard P  wrote:

> Anyone know of vocabs for Lychrel numbers and continued fractions?
>
>  - Leonard
>
>
> --
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] terrain example

2012-12-16 Thread Alex Vondrak
http://docs.factorcode.org/content/word-run,vocabs.loader.html

E.g., `"terrain" run`

--Alex Vondrak


On Sun, Dec 16, 2012 at 6:49 PM, Leonard P  wrote:

> Anyone know how to run a program from a file, with the listener?
>
> Wanted to see the terrain example.
>
> http://concatenative.org/wiki/view/Factor/Examples
>
>  - Leonard
>
>
> --
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk