Paste: boa-tuple-with-shadowed-slots

Author: kenanb
Mode: factor
Date: Sat, 23 Apr 2011 17:48:35
Plain Text |
TUPLE: tuple1 s1 s2 s3 s4 s5 s6 ;
TUPLE: tuple2 < tuple1 s2 s5 s7 s8 ;
TUPLE: tuple3 < tuple2 s4 s5 s8 s9 s10 ;

1 2 3 4 5 6 7 8 9 10 tuple3

[ all-slots [ name>> ] map
  [ reverse! members
    [ swap 2array ] map ] keep ] keep
    [ initial-values reverse!
      [ 2array ] 2map
      [ '[ [ first ] [ last ]
           bi _ swap '[ drop _ ]
           change-at ] each ] keep
      reverse! [ last ] each ] keep boa

Annotation: problems with macro version

Author: kenanb
Mode: factor
Date: Sat, 23 Apr 2011 20:25:43
Plain Text |
MACRO: shadowing-boa ( class -- tuple ) 
[ all-slots [ name>> ] map
  [ reverse! sets:members [ length ] keep 
  [ narray reverse! ] dip
    [ swap 2array ] 2map ] keep ] keep
    [ initial-values reverse!
      [ 2array ] 2map
      [ '[ [ first ] [ last ]
           bi _ swap '[ drop _ ]
           change-at ] each ] keep
      reverse! [ last ] each ] keep boa ;

Annotation: formatting

Author: erg
Mode: factor
Date: Sat, 23 Apr 2011 20:41:10
Plain Text |
MACRO: shadowing-boa ( class -- tuple ) 
    [
        all-slots [ name>> ] map
        [
            reverse! sets:members [ length ] keep 
            [ narray reverse! ] dip
            [ swap 2array ] 2map ] keep
        ] keep
        [
            initial-values reverse!
            [ 2array ] 2map
            [
                '[ [ first ] [ last ]
                bi _ swap '[ drop _ ]
                change-at
            ] each
        ] keep
        reverse! [ last ] each
    ] keep boa ;

Annotation: ugh

Author: erg
Mode: factor
Date: Sat, 23 Apr 2011 20:46:19
Plain Text |
MACRO: shadowing-boa ( class -- tuple )
    [
        all-slots [ name>> ] map
        [
            reverse! sets:members [ length ] keep 
            [ narray reverse! ] dip
            [ swap 2array ] 2map
        ] keep
    ] keep
    [
        initial-values reverse!
        [ 2array ] 2map
        [
            '[
                [ first ] [ last ] bi
                _ swap '[ drop _ ] change-at
            ] each
        ] keep
        reverse! [ last ] each
    ] keep boa ;

Annotation: some refactoring

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 13:44:02
Plain Text |
    [
        all-slots [ name>> ] map
        [
            reverse! members 
            [ length narray reverse! ] keep 
            [ swap 2array ] 2map
        ] keep
    ]
    [
        initial-values reverse!
        [ 2array ] 2map
        [
            '[
                [ first ] [ last ] bi
                _ swap '[ drop _ ] change-at
            ] each
        ] keep
        reverse! [ last ] each
    ] 
    [
        boa
    ] tri

Annotation: even better

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 14:14:02
Plain Text |
[
    all-slots [ name>> ] map
    [
        reverse! members 
        [ length narray reverse! ] keep 
        [ swap 2array ] 2map
    ] keep
]
[
    initial-values reverse!
    [ 2array ] 2map
    swap assoc-union!
    reverse! [ last ] each
] 
[
    boa
] tri

Annotation: ?

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 14:31:57
Plain Text |
[
    all-slots [ name>> ] map
    [
        reverse! members 
        [ length ] keep 
    ] keep
] keep

[
        [ narray reverse! ] dip
        [ swap 2array ] 2map
] 2dip

[
    initial-values reverse!
    [ 2array ] 2map
    swap assoc-union!
    reverse! [ last ] each
] 
[
    boa
] bi

Annotation: some more refactoring

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 14:35:33
Plain Text |
[
    all-slots [ name>> ] map
    [
        reverse! members 
        [ length ] keep 
    ] keep
] keep

[
        [ narray reverse! ] dip
        swap zip
] 2dip

[
    initial-values reverse!
    zip
    swap assoc-union!
    reverse! [ last ] each
] 
[
    boa
] bi

Annotation: at last

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 19:35:04
Plain Text |
QUALIFIED: sets

: class-length-and-slot-lists ( class -- seq1 seq2 )
    all-slots [ name>> ] map [ reverse! sets:members ] keep ;

: assoc-slots ( slots... length seq -- assoc ) 
    [ narray reverse! ] dip swap zip ; inline

: assoc-slots-to-initial ( seq class -- assoc ) 
    initial-values reverse! zip ;

: extract-slot-values ( slot-assoc initial-slot-assoc length -- slots... )
    [ swap assoc-union!
    reverse! [ last ] map ] dip firstn ; inline

MACRO: shadowed-boa ( class -- tuple ) 
    [ class-length-and-slot-lists 
    [ [ length ] keep ] dip ] keep 

   '[ _ _ _ _ [ assoc-slots ] 2dip 
        [ assoc-slots-to-initial dup length extract-slot-values ] 
        [ boa ] bi 
    ] ;

Annotation: dirty

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 19:38:37
Plain Text |
QUALIFIED: sets

: generate-slot-sequences ( class -- seq1 seq2 )
    all-slots [ name>> ] map [ reverse! sets:members ] keep ;

: assoc-slots ( slots... length seq -- assoc ) 
    [ narray reverse! ] dip swap zip ; inline

: assoc-slots-to-initial ( seq class -- assoc ) 
    initial-values reverse! zip ;

: extract-slot-values ( slot-assoc initial-slot-assoc length -- slots... )
    [ swap assoc-union!
    reverse! [ last ] map ] dip firstn ; inline

MACRO: shadowed-boa ( class -- tuple ) 
    [ 
        generate-slot-sequences 
        [ [ length ] keep ] dip 
    ] keep 

   '[ _ _ _ _ [ assoc-slots ] 2dip 
        [ assoc-slots-to-initial dup length extract-slot-values ] 
        [ boa ] bi 
    ] ;

Annotation: quick fix

Author: blei
Mode: factor
Date: Sun, 24 Apr 2011 19:47:48
Plain Text |
MACRO: shadowed-boa ( class -- tuple ) 
    [ 
        generate-slot-sequences 
        [ [ length ] keep ] dip 
    ] keep 
 dup all-slots length
   '[ _ _ _ _ [ assoc-slots ] 2dip 
        [ assoc-slots-to-initial _ extract-slot-values ] 
        [ boa ] bi 
    ] ;

Annotation: i think this is the last one

Author: kenanb
Mode: factor
Date: Sun, 24 Apr 2011 21:29:49
Plain Text |
QUALIFIED: sets

: (assoc-slots) ( slots... length seq -- assoc ) 
    [ narray reverse! ] dip swap zip ; inline

: (assoc-slots-to-initial) ( seq class -- assoc ) 
    initial-values reverse! zip ;

: (extract-slot-values) ( initial-slot-assoc slot-assoc length -- slots... )
    [ assoc-union! reverse! [ last ] map ] dip firstn ; inline

MACRO: shadowed-boa ( class -- tuple ) 
    [
        all-slots [ name>> ] map 
        [ reverse! sets:members ] keep
        [ [ length ] bi@ ] 2keep swapd
    ] keep
   '[ _ _ (assoc-slots) _ _ _
        [ (assoc-slots-to-initial) -rot (extract-slot-values) ] 
        [ boa ] bi 
    ] ;

New Annotation

Summary:
Author:
Mode:
Body: