Go to the first, previous, next, last section, table of contents.


Scheme modules

A number of C++-defined functions are exported into the (libtour builtin) module and can be used by Scheme procedures within a tournament definition.

A tournament definition which is a list of lists of lists ... can be tedious to write. In order to simplify it as well as bring some fun into rules definition a helper module (libtour common) is provided.

(libtour filters) provides some team and game filters for use in stage definitions.

builtin module

To use these procedures in your modules, do

(use-modules (libtour builtin))

unless you use (libtour common) which uses and re-exports them.

(libtour builtin) procedure: *t-tid* tour-name stage-id group-id pos

Return a list of global team IDs for stage stage-id, group group-id at position pos. If the stage is not initialized (see section TStage state transitions), return #f. Note that this procedure returns a list rather than a string since more than one team can occupy a position within a group due to a sorting conflict.

(libtour builtin) procedure: *t-pos* tour-name stage-id group-id global-team-id

Return a pair of positions (low and high) for the team global-team-id in the group group-id of stage stage-id. Note that global-team-id is a global team ID.

(libtour builtin) procedure: *t-gl-tid* tour-name stage-id local-team-id

Return global team ID for a team with local team ID local-team-id in stage stage-id.

(libtour builtin) procedure: *t-lc-tid* tour-name stage-id global-team-id

Return local team ID for a team with global team ID global-team-id in stage stage-id.

(libtour builtin) procedure: *t-lc-tid-by-name* tour-name stage-id team-name

Return local team ID for a team with name team-name in stage stage-id.

(libtour builtin) procedure: *team-belongs-to-group* tour-name stage-id group-id local-team-id

Return true if the group group-id within stage stage-id contains team with stage-local team id local-team-id.

(libtour builtin) procedure: *make-tmp-group* tour-name stage-id group-spec

Make a temporary group within the stage stage-id according to the group specification group-spec. See section Groups definition, for a complete description of a group specification list. A group created with *make-tmp-group* can later be deleted with *delete-tmp-group*.

(libtour builtin) procedure: *delete-tmp-group* tour-name group-id

Delete a temporary group group-id within stage stage-id. Note that only groups created with *make-tmp-group* can be deleted.

(libtour builtin) procedure: *get-games* tour-name stage-id group-id only-complete-games

Return list of the games for group group-id within stage stage-id. If only-complete-games flag is #t omit the games that haven't been played yet. The return list is in the following format:

Return list: '(<game> ...)

<game>: (<game-spec> <game-res>)

<game-spec>:
fields for the game as defined in SCHEDULE-FORMAT

<game-res>: if the game result is set, fields for the game result as
defined in GAMERES-FIELDS. If the game result is not set, empty
list.

If only-complete-games is #t only games with a result set will be returned.

See section Game schedule definition, for SCHEDULE-FORMAT and See section Standings and Game result fields definitions, for GAMERES-FIELDS definitions.

(libtour builtin) procedure: *is-complete* tour-name stage-id . group-id

Return #t if the group group-id within the stage stage-id is complete. If group-id argument is omitted, return #t if all groups in stage stage-id are complete (the stage is complete).

(libtour builtin) procedure: *home-position* tour-name

Return an interger for a team's home position as defined in SCHEDULE-HOME variable (see section Game schedule definition). The return value can be -1 (no home/away), 0 (home team comes first), or 1 (home team comes second). tour-name is the name of the tournament.

(libtour builtin) procedure: *time-less* tour-name time-1 time-2

This is a "less-than" operation for date/time strings in the format defined in the SCHEDULE-DATE variable (see section Game schedule definition). It returns true if time-1 is less than time-2, and false otherwise. tour-name is the name of the tournament.

common module

Make sure to import the (libtour common) module before calling the procedures described below.

(libtour common) procedure: cmp-assoc-field-p key alist-1 alist-2

Compare values for the key key in two associated lists (alist-1 and alist-2). Return 1 if the value in the first list is greater than the value in the second list, -1 if less, and #f if they are equal. No error checking is done.

(libtour common) procedure: cmp-assoc-field-diff-p key-1 key-2 alist-1 alist-2

Like cmp-assoc-field-p, only compares difference of values denoted by keys key-1 and key-2 in two associated lists.

(libtour common) procedure: cmp-two-teams-p tour-name stage-id team-id-1 team-id-2 cmp-f game-here-f

Compare personal results between two teams specified by local team IDs team-id-1 and team-id-2. The teams must belong to stage stage-id. cmp-f is a procedure to compare the teams (see section Teams comparison procedure), and game-here-f is a procedure to decide which games should be taken into account (see section game-belongs-to-group procedure).

Return 1, -1, or #f if the first teams' result is greater, less, or equal to the second team correspondingly.

cmp-two-teams-p will create a temporary group in the stage stage-id with only two teams, sort them and compare their position within the group. The temporary group is guaranteed to be deleted in the presence of exceptions.

(libtour common) procedure: uniq-tid tour-name stage-id group-id pos

Return global team ID at position pos in group group-id within stage stage-id, or #f if more than one team share that position. Will throw error if stage stage-id is "uninitialized" (see section TStage state transitions). Note that this procedure does not check if stage/group is complete.

(libtour common) procedure: winner-tid tour-name stage-id group-id pos

Just like uniq-tid but return #f immediately if the group group-id is not complete.

(libtour common) procedure: map-value->thunk alist

Replace each value of alist associative list with a thunk that returns the value when called. Return the resulting list.

(libtour common) procedure: map-tid-spec->thunk alist . proc

Given associative list alist in the form (("team-id" "stage-id" "group-id" position) ...) produce new associative list in the form (("team-id" . <thunk>) ...) so that execution of the thunk will produce a corresponding global team id for that specification. If procedure proc is present, use it, else use uniq-tid.

Note: this is a peculiar procedure used to simplify calls to uniq-tid etc. There must be a nicer way...

(libtour common) procedure: mk-res-lists spec

Transform the associative list spec in the form ((key val1 val2) ...) into a pair of associative lists (((key . val1) ...) (key . val2) ...). Used in the game interpretation procedures (see section Game results interpretation procedure).

(libtour common) procedure: make-group #:id group-id #:name group-name #:teams teams-list #:formula group-formula #:cmp-f compare-f #:game-here-f game-belongs-here-f

(libtour common) fluid: g-formula-default
(libtour common) fluid: g-cmp-f-default
(libtour common) fluid: g-game-here-f-default

Make and return a group specification list (see section Groups definition) given the argument denoted by keywords. It is possible to dynamically bind the last three arguments using Guile fluids so that they can be omitted. For instance (from the `ihwc2003_rules.scm'):

(with-fluids
 ((g-game-here-f-default 'ANY)
  (g-formula-default '(ROUND 1))
  (g-cmp-f-default cmp-prelim-stage-f))
 (list (make-group #:id "A" #:teams '("SVK" "GER" "UKR" "JPN"))
       (make-group #:id "B" #:teams '("RUS" "USA" "SUI" "DEN"))
       (make-group #:id "C" #:teams '("SWE" "CAN" "LAT" "BLR"))
       (make-group #:id "D" #:teams '("FIN" "CZE" "AUT" "SLO"))))

(libtour common) procedure: make-stage #:id stage-id #:name stage-name #:standings-fields standings-fields #:gameres-fields gameres-fields #:res-f res-f #:teams teams-spec #:groups groups-spec

Make and return a stage specification list (see section Stages definition). No fluids here.

filters module

Filter-making procedures are used in creation of filtered groups (see section Filtered groups). You have to explicitly list the filter-making procedures you want to make avalable for a stage in the FILTERS field of the stage definition (see section Filters definition).

Make sure to import the (libtour filters) module before using the procedures described below.

(libtour filters) procedure: empty tname st-id gr-id

A game filter. If used will make sure the group has no games. Useful for testing. Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: at-home tname st-id gr-id

A game filter. A group that uses it will only consider home games results. This filter cannot be used if SCHEDULE-HOME is -1 (see section Game schedule definition). Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: at-away tname st-id gr-id

A game filter. A group that uses it will only consider away games results. This filter cannot be used if SCHEDULE-HOME is -1 (see section Game schedule definition). Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: vs-group tname st-id gr-id vs-gr-id

A game filter. A group that uses it will only have games played versus group with ID vs-gr-id (string type). Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: vs-teams tname st-id gr-id action team-ls

A game filter. A group that uses it will only consider games that satisfies action argument against team stage-local IDs in team-ls. action is of the symbol type and one of

Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: time-span tname st-id gr-id time-1 time-2

A game filter. A group that uses it will only have games played between time-1 (inclusive) and time-2 (exclusive). The time arguments are of the string type, and their format should be conform to the SCHEDULE-DATE definition (see section Game schedule definition). Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: game-fld tname st-id gr-id fld-name action val-ls

A game filter. A group that uses it will only consider games that satisfies action argument towards contents of field fld-name (symbol type) in val-ls. val-ls is a list of values (string type). action is of the symbol type and one of

Returns a procedure that takes a game associative list as the sole argument.

(libtour filters) procedure: team-fld tname st-id gr-id fld-name action val-ls

A team filter. A group that uses it will only contain teams that satisfy action argument towards contents of the team field fld-name (symbol type) in val-ls. val-ls is a list of values (string type). action is of the symbol type and one of

Returns a procedure that takes a team associative list as the sole argument.


Go to the first, previous, next, last section, table of contents.