Re: [Factor-talk] Generating symbols at runtime

2019-09-17 Thread KUSUMOTO Norio
> How do I code to generate symbols at runtime? "define-symbol" seems to work 
> only at compile time.

Oh, I was able to do it as follows:

 [ "a-symbol" "factor-logica" create-word define-symbol ] with-compilation-unit


--
KUSUMOTO Norio



> 2019/09/17 19:40、KUSUMOTO Norio のメール:
> 
> Hello all,
> 
> 
> How do I code to generate symbols at runtime? "define-symbol" seems to work 
> only at compile time.
> 
> I'm writing an embedded language that runs on Factor with the capabilities of
> a subset of Prolog. To achieve the anonymous variable functionality, I want to
> generate as many symbols as needed at runtime.
> 
> In the following code, the Prolog anonymous variables '_' are equivalent
> to explicitly generated N1 to N11 logical variables. I want to automate
> that operation.
> 
> 
> USING: actor-logica factor-logica.built-in lists ;
> 
> ! Do the same as this Prolog program
> !
> ! neighbor(L,R,[L,R|_]).
> ! neighbor(L,R,[_|Xs]) :- neighbor(L,R,Xs).
> !
> ! zebra(X) :- Street = [H1,H2,H3],
> ! member(house(red,english,_), Street),
> ! member(house(_,spanish,dog), Street),
> ! neighbor(house(_,_,cat), house(_,japanese,_), Street),
> ! neighbor(house(_,_,cat), house(blue,_,_), Street),
> ! member(house(_,X,zebra),Street).
> 
> LOGIC-PREDS: neighboro zebrao ;
> LOGIC-VARS: L R X Xs H1 H2 H3 Street ;
> LOGIC-VARS: N1 N2 N3 N4 N5 N6 N7 N8 N9 N10 N11 ;
> SYMBOLS: red blue ;
> SYMBOLS: english spanish japanese ;
> SYMBOLS: dog cat zebra ;
> TUPLE: house color nationality pet ;
> 
> { neighboro L R [ L R N1 cons cons ] } semper
> { neighboro L R [ N1 Xs cons ] } { neighboro L R Xs } si
> 
> { zebrao X } {
>{ (=) Street [ { H1 H2 H3 } >list ] }
>{ membero [ T{ house f red english N1 } ] Street }
>{ membero [ T{ house f N2 spanish dog } ] Street }
>{ neighboro [ T{ house f N3 N4 cat } ] [ T{ house f N5 japanese N6 } ]  
> Street }
>{ neighboro [ T{ house f N7 N8 cat } ] [ T{ house f blue N9 N10 } ] Street 
> }
>{ membero [ T{ house f N11 X zebra } ] Street }
> } si
> 
> 
> Loading resource:work/factor-logica/factor-logica.factor
> Loading resource:work/factor-logica/built-in/built-in.factor
> IN: scratchpad { zebrao X } query .
> { H{ { X japanese } } H{ { X japanese } } }
> 
> 
> --
> KUSUMOTO Norio
> 
> 
> 
> 
> 
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk



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


[Factor-talk] Generating symbols at runtime

2019-09-17 Thread KUSUMOTO Norio
Hello all,


How do I code to generate symbols at runtime? "define-symbol" seems to work 
only at compile time.

I'm writing an embedded language that runs on Factor with the capabilities of
a subset of Prolog. To achieve the anonymous variable functionality, I want to
generate as many symbols as needed at runtime.

In the following code, the Prolog anonymous variables '_' are equivalent
to explicitly generated N1 to N11 logical variables. I want to automate
that operation.


USING: actor-logica factor-logica.built-in lists ;

! Do the same as this Prolog program
!
! neighbor(L,R,[L,R|_]).
! neighbor(L,R,[_|Xs]) :- neighbor(L,R,Xs).
!
! zebra(X) :- Street = [H1,H2,H3],
! member(house(red,english,_), Street),
! member(house(_,spanish,dog), Street),
! neighbor(house(_,_,cat), house(_,japanese,_), Street),
! neighbor(house(_,_,cat), house(blue,_,_), Street),
! member(house(_,X,zebra),Street).

LOGIC-PREDS: neighboro zebrao ;
LOGIC-VARS: L R X Xs H1 H2 H3 Street ;
LOGIC-VARS: N1 N2 N3 N4 N5 N6 N7 N8 N9 N10 N11 ;
SYMBOLS: red blue ;
SYMBOLS: english spanish japanese ;
SYMBOLS: dog cat zebra ;
TUPLE: house color nationality pet ;

{ neighboro L R [ L R N1 cons cons ] } semper
{ neighboro L R [ N1 Xs cons ] } { neighboro L R Xs } si

{ zebrao X } {
{ (=) Street [ { H1 H2 H3 } >list ] }
{ membero [ T{ house f red english N1 } ] Street }
{ membero [ T{ house f N2 spanish dog } ] Street }
{ neighboro [ T{ house f N3 N4 cat } ] [ T{ house f N5 japanese N6 } ]  
Street }
{ neighboro [ T{ house f N7 N8 cat } ] [ T{ house f blue N9 N10 } ] Street }
{ membero [ T{ house f N11 X zebra } ] Street }
} si


Loading resource:work/factor-logica/factor-logica.factor
Loading resource:work/factor-logica/built-in/built-in.factor
IN: scratchpad { zebrao X } query .
{ H{ { X japanese } } H{ { X japanese } } }


--
KUSUMOTO Norio





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


Re: [Factor-talk] Co-operative threading

2019-09-17 Thread Jon Harper
Last time I checked ( https://github.com/factor/factor/issues/1129 ),
named pipes support wasn't ideal in factor.. Even if you don't use
with-file-reader and call open and read directly, you won't get
cooperative threading. You can get it from stdin and stdout because
there's special support for that, or from sockets.

Jon

On Sun, Sep 15, 2019 at 10:08 AM murray.calavera--- via Factor-talk
 wrote:
>
> I don't think that's true, if that were the case it would be constantly 
> printing to stdout.
> It's a fifo file created with mkfifo, as soon as data is read from it the 
> data is no longer in the file. Fifos are automatically closed after one 
> process(e.g. echo) writes to it, so I have to reopen it so I can echo to it 
> multiple times.
>
> But I think I worked out the problem thanks to your comment, I think it's 
> because with-file-reader blocks without yielding.
>
> ‐‐‐ Original Message ‐‐‐
> On Sunday, September 15, 2019 3:10 AM, Alexander Ilin  
> wrote:
>
> You open a file, read one line, then reopen the file and do the same again.
> Since you are reopening the stream, there's always data available, thus there 
> is no reason to yield.
>
> 14.09.2019, 21:04, "murray.calavera--- via Factor-talk" 
> :
>
> Hello all,
>
> I'm a bit confused about how threads work with IO in factor.
>
>
> This: https://docs.factorcode.org/content/article-threads.html seems to imply 
> that functions such as readln will yield  to other threads unless data is 
> available on a stream, but the following program only ever reads from the 
> fifo:
>
>
> USING: kernel threads io io.files io.encodings.utf8 ;
> IN: test
>
> : read-fifo ( -- )
> "fifo" utf8 [ readln print flush ] with-file-reader read-fifo ;
>
> : read-stdin ( -- )
> readln print flush read-stdin ;
>
> [ read-fifo ] "fifo-thread" spawn drop
> read-stdin
>
>
>
> What am I misunderstanding here?
>
> Thanks.
>
> Murray.
>
>
> ,,
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
>
> ---=---
> Александр
>
>
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk


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