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 " <slice> 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> 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 <naveen.g...@gmail.com> 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 " <slice> 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

Reply via email to