This file is indexed.

/usr/share/axiom-20170501/src/algebra/PATRES.spad is in axiom-source 20170501-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
)abbrev domain PATRES PatternMatchResult
++ Author: Manuel Bronstein
++ Date Created: 28 Nov 1989
++ Date Last Updated: 5 Jul 1990
++ Description:
++ A PatternMatchResult is an object internally returned by the
++ pattern matcher; It is either a failed match, or a list of
++ matches of the form (var, expr) meaning that the variable var
++ matches the expression expr.
-- not exported

PatternMatchResult(R,S) : SIG == CODE where
  R : SetCategory
  S : SetCategory

  SIG ==> SetCategory with

    failed? : %  -> Boolean
      ++ failed?(r) tests if r is a failed match.

    failed : () -> %
      ++ failed() returns a failed match.

    new : () -> %
      ++ new() returns a new empty match result.

    union : (%, %) -> %
      ++ union(a, b) makes the set-union of two match results.

    getMatch : (Pattern R, %) -> Union(S, "failed")
      ++ getMatch(var, r) returns the expression that var matches
      ++ in the result r, and "failed" if var is not matched in r.

    addMatch : (Pattern R, S, %) -> %
      ++ addMatch(var, expr, r) adds the match (var, expr) in r,
      ++ provided that expr satisfies the predicates attached to var,
      ++ and that var is not matched to another expression already.

    insertMatch : (Pattern R, S, %) -> %
      ++ insertMatch(var, expr, r) adds the match (var, expr) in r,
      ++ without checking predicates or previous matches for var.

    addMatchRestricted : (Pattern R, S, %, S) -> %
      ++ addMatchRestricted(var, expr, r, val) adds the match
      ++ (var, expr) in r,
      ++ provided that expr satisfies the predicates attached to var,
      ++ that var is not matched to another expression already,
      ++ and that either var is an optional pattern variable or that
      ++ expr is not equal to val (usually an identity).
  
    destruct : % -> List Record(key:Symbol, entry:S)
      ++ destruct(r) returns the list of matches (var, expr) in r.
      ++ Error: if r is a failed match.

    construct : List Record(key:Symbol, entry:S) -> %
      ++ construct([v1,e1],...,[vn,en]) returns the match result
      ++ containing the matches (v1,e1),...,(vn,en).
  
    satisfy? : (%, Pattern R) -> Union(Boolean, "failed")
      ++ satisfy?(r, p) returns true if the matches satisfy the
      ++ top-level predicate of p, false if they don't, and "failed"
      ++ if not enough variables of p are matched in r to decide.

  CODE ==> add

    LR ==> AssociationList(Symbol, S)

    import PatternFunctions1(R, S)

    Rep := Union(LR, "failed")

    new() == empty()

    failed() == "failed"

    failed? x == x case "failed"

    insertMatch(p, x, l) == concat([retract p, x], l::LR)

    construct l == construct(l)$LR

    destruct l == entries(l::LR)$LR

    -- returns "failed" if not all the variables of the pred. are matched
    satisfy?(r, p) ==
      failed? r => false
      lr := r::LR
      lv := [if (u := search(v, lr)) case "failed" then return "failed"
                          else  u::S for v in topPredicate(p).var]$List(S)
      satisfy?(lv, p)

    union(x, y) ==
      failed? x or failed? y => failed()
      removeDuplicates concat(x::LR, y::LR)

    x = y ==
      failed? x => failed? y
      failed? y => false
      x::LR =$LR y::LR

    coerce(x:%):OutputForm ==
      failed? x => "Does not match"::OutputForm
      destruct(x)::OutputForm

    addMatchRestricted(p, x, l, ident) ==
      (not optional? p) and (x = ident) => failed()
      addMatch(p, x, l)

    addMatch(p, x, l) ==
      failed?(l) or not(satisfy?(x, p)) => failed()
      al := l::LR
      sy := retract(p)@Symbol
      (r := search(sy, al)) case "failed" => insertMatch(p, x, l)
      r::S = x => l
      failed()

    getMatch(p, l) ==
      failed? l => "failed"
      search(retract(p)@Symbol, l::LR)