Paste: Bend experiment

Author: Kacarott
Mode: factor
Date: Wed, 5 Jun 2024 14:35:48
Plain Text |
SYMBOL: fork

SINGLETON: bend-parser

: parse-bend-until-step ( accum end -- accum ? )
    ?scan-datum {
        { [ 2dup eq? ] [ 2drop f ] }
        { [ dup \ fork = ] [ drop bend-parser get pick push \ >quotation pick push \ call pick push drop t ] }
        { [ dup not ] [ drop throw-unexpected-eof t ] }
        { [ dup delimiter? ] [ unexpected t ] }
        { [ dup parsing-word? ] [ nip execute-parsing t ] }
        [ pick push drop t ]
    } cond ;

: parse-bend-until ( accum end -- accum )
    [ parse-bend-until-step ] keep swap [ parse-bend-until ] [ drop ] if ;

: parse-bend ( -- vec ) bend-parser get \ ] parse-bend-until >quotation ;
M: bend-parser parse-quotation 100 <vector> \ ] parse-bend-until >quotation ;

SYNTAX: B[ 100 <vector> '{
        { bend-parser _ }
        { quotation-parser bend-parser }
    } [ parse-bend ] with-variables append! ;

Annotation: dcvz. bcc vvc cf

Author: change checked
Mode: factor
Date: Tue, 4 Jun 2024 08:05:35
Plain Text |
cc both cbc cbc

Annotation: other ways

Author: mrjbq7
Mode: factor
Date: Wed, 5 Jun 2024 15:33:03
Plain Text |
! define a BEND word

SYNTAX: BEND:
    [
        scan-new-word scan-effect
        over "fork" associate [ parse-definition ] with-words swap
    ] with-definition define-declared ;

! define an inline BEND operation

SYMBOL: fork

SYNTAX: BEND[
    gensym dup parse-quotation over
    '[ dup fork eq? [ drop _ ] when ] deep-map
    dup infer define-declared suffix! ;

Annotation: better

Author: mrjbq7
Mode: factor
Date: Wed, 5 Jun 2024 15:37:50
Plain Text |
SYNTAX: BEND[
    gensym dup
    dup "fork" associate 
    [ parse-quotation ] with-words
    dup infer define-declared suffix! ;


! : foo ( x -- x ) BEND[ 1 - dup 0 > [ dup fork + ] when ] ;

! IN: scratchpad 10 foo .
! 45

New Annotation

Summary:
Author:
Mode:
Body: