Re: [Factor-talk] Managing many vocabularies

2012-11-30 Thread Leon Konings
Hi John and Alexander,

Thanks for the very useful advice.

I prefer not to use DEFER: (pun intended), but if it turns out to be  
the best solution I will.

Best regards,
Leon Konings


Quoting John Benediktsson :

> Alex has good advice.
>
> In addition, if you have a circularity inside a single vocab, the DEFER:
> mechanism allows something like this to be resolved properly:
>
> DEFER: bar
>
> : foo ( -- x ) bar ;
>
> : bar ( -- x ) 12 ;
>
> Usually circularities between vocabs can be resolved by using a central
> vocabulary or a hierarchy to place the word in a commonly used location.
>  If you are having difficulties still, you can use a HOOK: to define a word
> that dispatches based on the value of a namespace variable.  For more
> details, see:
>
> http://docs.factorcode.org/content/word-HOOK__colon__,syntax.html
>
> Best,
> John.
>
>
>
> On Tue, Nov 27, 2012 at 8:09 PM, Alexander J. Vondrak <
> ajvond...@csupomona.edu> wrote:
>
>> Finding circularities: maybe something like
>> https://gist.github.com/4158963?
>> Though it's not the smartest thing around (just because there's a vocab
>> circularity doesn't mean there will necessarily be an issue with a word
>> definition).
>>
>> Avoiding circularities is really an engineering thing...
>>
>> Fixing circularities is trickier, and it'll generally vary case-by-case.
>>  Check
>> out http://docs.factorcode.org/content/article-deferred.html, perhaps?
>>
>> Good luck,
>> --Alex Vondrak
>>
>> 
>> From: Leon Konings [fac...@koningssoftware.com]
>> Sent: Saturday, November 24, 2012 8:29 AM
>> To: factor-talk@lists.sourceforge.net
>> Subject: Re: [Factor-talk] Managing many vocabularies
>>
>> Hi Alexander,
>>
>> Thank you for your very long answer.
>>
>> You where guessing right about the circular dependencies. Because
>> there are so many vocabularies, problems like that happen rather often.
>>
>> I am really looking for better and faster ways to find these, and a
>> way of working that make it less likely that they happen.
>>
>> Best regards,
>> Leon
>>
>>
>> Quoting "Alexander J. Vondrak" :
>>
>> > I'm not really sure if there was a question in there...
>> >
>> >> Loading all the vocabularies, which all load many other vocabularies,
>> >> is not easy to do.
>> >
>> > If you're just sitting down at your editor, typing vocab names into the
>> > `USING:` line, then yeah, it's going to be difficult to know exactly
>> which
>> > vocabs you're supposed to specify.  That's why you use the listener.
>> >
>> > Say I'm working on a file, factor/work/blah/blah.factor.  While I'm
>> jotting
>> > down some code, I either don't know what I need in the `USING:` or
>> forget to
>> > put something in there.
>> >
>> >   USING: ; ! ???
>> >
>> >   "Blah" print
>> >
>> >> From the listener, I type `USE: blah`, and I get a helpful error
>> message.
>> >
>> >   IN: scratchpad USE: blah
>> >   Loading resource:work/blah/blah.factor
>> >   1: USE: blah
>> >   ^
>> >   resource:work/blah/blah.factor
>> >
>> >   1: "Blah" print
>> >  ^
>> >   No word named ?print? found in current vocabulary search path
>> >
>> >   The following restarts are available:
>> >
>> >   :1  Use the io vocabulary
>> >   :2  Defer word in current vocabulary
>> >   :3  Load resource:work/blah/blah.factor again
>> >
>> >   Type :help for debugging help.
>> >
>> > It gives me several options to recover from this error, including a
>> > suggestion
>> > for which vocab to load to find the word `print` (note that this
>> > doesn't always
>> > work, if Factor can't find a particular word name in the current
>> > search path).
>> > In this case, I can type `:1` to use the `io` vocab.
>> >
>> >   IN: scratchpad :1
>> >   resource:work/blah/blah.factor:1: Note:
>> >   Added "io" vocabulary to search path
>> >
>> >   Restarts were invoked adding vocabularies to the search path.
>> >   To avoid doing this in the future, add the following forms
>> >   at the top of the source file:
>> >
>> >   USING: io ;
>> >
>> > Also, take a look at
>> > http://docs.factorcode.org/content/article-images.html and
>> > http://docs.factorcode.org/content/word-auto-use__que__%2Cparser.html
>> >
>> >> I often have to solve problems with interdependencies. It is not
>> >> easy to find
>> >> the cause of these problems.
>> >
>> > What sort of problems?  And what sort of interdependencies?  Like vocabs
>> > depending on vocabs?  I struggle to think of a problem with that,
>> because the
>> > chain of dependencies shouldn't be an issue, unless there's a cycle.
>>  E.g.,
>> >
>> >   ! In a.factor
>> >   USING: b ;
>> >   IN: a
>> >   : a-word ( -- ) b-word ;
>> >
>> >   ! In b.factor
>> >   USING: io ;
>> >   IN: b
>> >   : b-word ( -- ) "Called b-word" print ;
>> >
>> >   ! At the listener
>> >   IN: scratchpad USE: a
>> >   Loading resource:work/a/a.factor
>> >   Loading resource:work/b/b.factor
>> >   IN: scratchpad a-word
>> >   Called b-word
>>

[Factor-talk] embedding factor

2012-11-30 Thread Naveen Garg
Hey guys,
I am playing around with factor again, and getting some useful work done.
I am trying to use factor embedded...
Unfortunately, the function "init_factor_from_args" that is mentioned in
the documentation is no longer in the source...
There is a new function: start_standalone_factor in master.hpp.
Has anyone used it successfully to embed factor ?
Thanks,
Naveen
--
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] embedding factor

2012-11-30 Thread Michael Clagett
Also interested in this.


Sent from my iPhone

On Nov 30, 2012, at 3:25 PM, "Naveen Garg"  wrote:

> Hey guys, 
> I am playing around with factor again, and getting some useful work done.
> I am trying to use factor embedded...
> Unfortunately, the function "init_factor_from_args" that is mentioned in the 
> documentation is no longer in the source...
> There is a new function: start_standalone_factor in master.hpp.
> Has anyone used it successfully to embed factor ? 
> Thanks,
> Naveen
> --
> Keep yourself connected to Go Parallel: 
> TUNE You got it built. Now make it sing. Tune shows you how.
> http://goparallel.sourceforge.net
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
--
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk
--
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] regexp words on string slices

2012-11-30 Thread Naveen Garg
Any reason slices are not allowed to be passed to regexp words like
"first-match" ?
I tried modifiying the word:
: check-string ( string -- string )
! Make this configurable
!  dup string? [ "String required" throw ] unless ;
dup dup string?
swap regexp? or [ "String required" throw ] unless ;

but doing a
> refresh-all
doesn't change anything, running
> 0 4 "foo "  R/ foo/ first-match
still throws error " string required "

For the curious, I am working on an optimized / space efficient version of
the re-pair semi-static dictionary compression algorithm (
http://www.cbrc.jp/~rwan/en/restore.html) .
I have it working in autohotkey, trying to port it to factor to see if I
get any performance gains, and just for fun / learn factor.
--
Keep yourself connected to Go Parallel: 
INSIGHTS What's next for parallel hardware, programming and related areas?
Interviews and blogs by thought leaders keep you ahead of the curve.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] regexp words on string slices

2012-11-30 Thread Naveen Garg
Oops, I had a typo, i was checking for regexp? instead of slice?
: check-string ( string -- string )
! Make this configurable
!dup string? [ "String required" throw ] unless ;
dup dup string?
swap slice? or [ "String required" throw ] unless ;

> 0 4 "foo bar "  R/ foo/ first-match
but now I get a memory access error: ...
Naveen
--
Keep yourself connected to Go Parallel: 
INSIGHTS What's next for parallel hardware, programming and related areas?
Interviews and blogs by thought leaders keep you ahead of the curve.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] regexp words on string slices

2012-11-30 Thread John Benediktsson
Probably the restrictions to strings were a performance optimization...?
 It should be pretty easy to get the behavior you want:

IN: scratchpad 0 4 "foo "  R/ foo/ first-match .
T{ slice { from 0 } { to 3 } { seq "foo " } }

Using this diff makes it work, but causes the regexp benchmark to be 20-30%
slower...:

```diff
diff --git a/basis/regexp/compiler/compiler.factor
b/basis/regexp/compiler/compi
index a8b3c91..fb5fa4f 100644
--- a/basis/regexp/compiler/compiler.factor
+++ b/basis/regexp/compiler/compiler.factor
@@ -101,7 +101,7 @@ C:  box
 : transitions>quot ( transitions final-state? -- quot )
 dup shortest? get and [ 2drop [ drop nip ] ] [
 [ split-literals swap case>quot ] dip backwards? get
-'[ { fixnum string } declare _ _ _ step ]
+'[ { fixnum sequence } declare _ _ _ step ]
 ] if ;

 : word>quot ( word dfa -- quot )
diff --git a/basis/regexp/regexp.factor b/basis/regexp/regexp.factor
index 6070921..3e66785 100644
--- a/basis/regexp/regexp.factor
+++ b/basis/regexp/regexp.factor
@@ -29,7 +29,7 @@ M: lookbehind question>quot ! Returns ( index string -- ?
)

 : check-string ( string -- string )
 ! Make this configurable
-dup string? [ "String required" throw ] unless ;
+dup sequence? [ "String required" throw ] unless ;

 : match-index-from ( i string regexp -- index/f )
 ! This word is unsafe. It assumes that i is a fixnum
@@ -166,7 +166,7 @@ DEFER: compile-next-match
 dup '[
 dup \ next-initial-word = [
 drop _ [ compile-regexp dfa>> def>> ] [ reverse-regexp? ] bi
-'[ { array-capacity string regexp } declare _ _ next-match ]
+'[ { array-capacity sequence regexp } declare _ _ next-match ]
 ( i string regexp -- start end string ) define-temp
 ] when
 ] change-next-match ;
```


On Fri, Nov 30, 2012 at 5:43 PM, Naveen Garg  wrote:

> Any reason slices are not allowed to be passed to regexp words like
> "first-match" ?
> I tried modifiying the word:
> : check-string ( string -- string )
> ! Make this configurable
> !  dup string? [ "String required" throw ] unless ;
> dup dup string?
> swap regexp? or [ "String required" throw ] unless ;
>
> but doing a
> > refresh-all
> doesn't change anything, running
> > 0 4 "foo "  R/ foo/ first-match
> still throws error " string required "
>
> For the curious, I am working on an optimized / space efficient version of
> the re-pair semi-static dictionary compression algorithm (
> http://www.cbrc.jp/~rwan/en/restore.html) .
> I have it working in autohotkey, trying to port it to factor to see if I
> get any performance gains, and just for fun / learn factor.
>
>
> --
> Keep yourself connected to Go Parallel:
> INSIGHTS What's next for parallel hardware, programming and related areas?
> Interviews and blogs by thought leaders keep you ahead of the curve.
> http://goparallel.sourceforge.net
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
--
Keep yourself connected to Go Parallel: 
INSIGHTS What's next for parallel hardware, programming and related areas?
Interviews and blogs by thought leaders keep you ahead of the curve.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] regexp words on string slices

2012-11-30 Thread Naveen Garg
Awesome.  Thanks John.
For my specific project, the current weaker link is memory usage compared
to speed.


On Fri, Nov 30, 2012 at 8:03 PM, John Benediktsson  wrote:

> Probably the restrictions to strings were a performance optimization...?
>  It should be pretty easy to get the behavior you want:
>
> IN: scratchpad 0 4 "foo "  R/ foo/ first-match .
> T{ slice { from 0 } { to 3 } { seq "foo " } }
>
> Using this diff makes it work, but causes the regexp benchmark to be
> 20-30% slower...:
>
>
--
Keep yourself connected to Go Parallel: 
INSIGHTS What's next for parallel hardware, programming and related areas?
Interviews and blogs by thought leaders keep you ahead of the curve.
http://goparallel.sourceforge.net___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk