factor-hmc / graph-theory

Graph-theoretic operations in Factor
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Outline graph interfaces #1

Open cole-k opened 4 years ago

cole-k commented 4 years ago
kwshi commented 4 years ago

FYI, here's some excerpt from the built-in sequences vocabulary that might hint at how to define generic interfaces:

MIXIN: sequence

GENERIC: length ( seq -- n ) flushable
GENERIC: set-length ( n seq -- )
GENERIC: nth ( n seq -- elt ) flushable
GENERIC: set-nth ( elt n seq -- )
GENERIC: new-sequence ( len seq -- newseq ) flushable
GENERIC: new-resizable ( len seq -- newseq ) flushable
GENERIC: like ( seq exemplar -- newseq ) flushable
GENERIC: clone-like ( seq exemplar -- newseq ) flushable

M: sequence lengthen 2dup length > [ set-length ] [ 2drop ] if ; inline
M: sequence shorten 2dup length < [ set-length ] [ 2drop ] if ; inline

: empty? ( seq -- ? ) length 0 = ; inline

: if-empty ( ..a seq quot1: ( ..a -- ..b ) quot2: ( ..a seq -- ..b ) -- ..b )
    [ dup empty? ] [ [ drop ] prepose ] [ ] tri* if ; inline
kwshi commented 4 years ago

Proposed vocabulary organization:

nandeeka commented 4 years ago

Extension Ideas:

kwshi commented 4 years ago

Help page on naming conventions, for reference: (help page "Conventions") factor-conventions