Paste: slist with sentinel -> sequence

Author: Erich Ocean
Mode: factor
Date: Fri, 30 Apr 2010 05:18:50
Plain Text |
TUPLE: entity  < identity-tuple id attribute ;
TUPLE: edge    < entity parent start-pvertex end-pvertex geometry ;
TUPLE: pvertex < entity next-pvertex parent vertex ;

: edge-pvertices ( edge - pvertices )
    {  [ start-pvertex>> ] [ end-pvertex>> ] bi [ 2dup eq? not ] [ over next-pvertex>> swap ] while }

Annotation: fixes

Author: Erich Ocean
Mode: factor
Date: Fri, 30 Apr 2010 05:22:00
Plain Text |
: edge-pvertices ( edge - pvertices )
    {  [ start-pvertex>> ] [ end-pvertex>> ] bi [ 2dup eq? not ] [ over next-pvertex>> swap ] while drop }

Annotation: this compiles

Author: mrjbq7
Mode: factor
Date: Fri, 30 Apr 2010 05:26:55
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [ start-pvertex>> ] [ end-pvertex>> ] bi 
    [ 2dup eq? not ] [ [ next-pvertex>> ] dip ] while drop ;

Annotation: another format?

Author: mrjbq7
Mode: factor
Date: Fri, 30 Apr 2010 05:27:53
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [ start-pvertex>> ] [ end-pvertex>> ] bi 
    [ 2dup eq? not ] [ 
        [ next-pvertex>> ] dip 
    ] while drop ;

Annotation: won't compile

Author: Erich Ocean
Mode: factor
Date: Fri, 30 Apr 2010 05:41:09
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [
      [ end-pvertex>> ] [ start-pvertex>> ] bi ,
      [ 2dup eq? not ] [ [ next-pvertex>> , ] dip ] while
    ] V{ } make

Annotation: something like this

Author: mrjbq7
Mode: factor
Date: Fri, 30 Apr 2010 05:45:59
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [
      [ end-pvertex>> ] [ start-pvertex>> ] bi ,
      [ 2dup eq? not ] [ next-pvertex>> dup , ] while 2drop
    ] V{ } make ;

Annotation: final implementation

Author: Erich Ocean
Mode: factor
Date: Fri, 30 Apr 2010 05:51:14
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [
      [ end-pvertex>> ] [ start-pvertex>> ] bi dup ,          ! initialize the loop and push the start pvertex
      [ 2dup eq? not ] [ [ next-pvertex>> dup , ] dip ] while ! push each additional pvertex up to and including the end pvertex
      2drop                                                   ! clear the stack
    ] V{ } make ;

Annotation: sigh. still more fixes

Author: Erich Ocean
Mode: factor
Date: Fri, 30 Apr 2010 05:56:03
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [
      [ start-pvertex>> ] [ end-pvertex>> ] bi over ,         ! push the start pvertex and initialize the while loop
      [ 2dup eq? not ] [ [ next-pvertex>> dup , ] dip ] while ! while loop: push each additional pvertex up to and including the end pvertex
      2drop                                                   ! clear the stack from the while loop
    ] V{ } make ;                                             ! pvertices sequence is now on the stack

Annotation: improved (still untested though)

Author: Erich Ocean
Mode: factor
Date: Fri, 30 Apr 2010 06:10:19
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [ [ end-pvertex>> ] [ start-pvertex>> ] bi dup ,  ! push the start pvertex and initialize the while loop
      [ 2dup eq? not ] [ next-pvertex>> dup , ] while ! keep pushing the next pvertex until we've pushed the end pvertex
      2drop                                           ! clear the stack elements we used to do the loop
    ] V{ } make ;

Annotation: version without 'make'

Author: Slava Pestov
Mode: factor
Date: Fri, 30 Apr 2010 21:39:53
Plain Text |
[ end-pvertex>> ] [ start-pvertex>> ] bi [ 2dup eq? not ] [ [ next-pvertex>> ] keep ] produce

Annotation: corrected implementation without 'make'

Author: Erich Ocean
Mode: factor
Date: Sat, 1 May 2010 11:21:50
Plain Text |
: edge-pvertices ( edge -- pvertices )
    [ end-pvertex>> ] [ start-pvertex>> ] bi
    2dup eq?
      [ drop 1array ]
      [
          ! ( end start )
        dup -rot                                             ! prepare for loop
          ! ( start end start )
        [ 2dup eq? not ] [ [ next-pvertex>> ] keep ] produce ! generate partial pvertices sequence (start is missing)
          ! ( start end end seq )
        4 -nrot 2drop prefix                                 ! prefix start on seq and remove the two end values
      ]   ! ( seq )
    if ;

New Annotation

Summary:
Author:
Mode:
Body: