read(`code_utilities.txt`): ##NOTE: If S=0, a selector returns its description Help_selectors:=proc() print(` CatSelectors(s1,s2) , StrCatSelectors(s1,s2) `): print(` AddSelectors(s1,s2) , SubtractSelectors(s1,s2) `): print(` MultSelectors(s1,s2) , DivideSelectors(s1,s2) `): print(` ModSelectors(s1,s2) , NegateSelector(s1) `): print(` AccumulateSelector(s1,accum,disc:="an accumulator") `): print(` ComposeSelector(s1,f,disc:="a function") `): print(` StringSelector(s1) , ListSelector(s1) `): print(` RedescribeSelector(s1,disc) `): print(` MakeConstantSelector(n) , SSelector(S,F,P,G,L,E) `): print(` FSelector(S,F,P,G,L,E) , PSelector(S,F,P,G,L,E) `): print(` GSelector(S,F,P,G,L,E) , LSelector(S,F,P,G,L,E) `): print(` ESelector(S,F,P,G,L,E) `): end: ##SELECTOR MANIPULATORS #Returns a selector that is the concatenation (comma) of s1 and s2 CatSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), ", ", s2(S,F,P,G,L,E)): fi: return s1(S,F,P,G,L,E), s2(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the concatenation (string) of s1 and s2 StrCatSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), ".", s2(S,F,P,G,L,E)): fi: return cat(s1(S,F,P,G,L,E), s2(S,F,P,G,L,E)): end: return s: end: #Returns a selector that is the sum of s1 and s2 AddSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), " plus ", s2(S,F,P,G,L,E)): fi: return s1(S,F,P,G,L,E) + s2(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the difference of s1 and s2 SubtractSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), " minus ", s2(S,F,P,G,L,E)): fi: return s1(S,F,P,G,L,E) - s2(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the product of s1 and s2 MultSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), " times ", s2(S,F,P,G,L,E)): fi: return s1(S,F,P,G,L,E) * s2(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the quotient of s1 and s2 DivideSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), " divided by ", s2(S,F,P,G,L,E)): fi: return s1(S,F,P,G,L,E) / s2(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the mod of s1 and s2 ModSelectors:=proc(s1,s2) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat(s1(S,F,P,G,L,E), " mod ", s2(S,F,P,G,L,E)): fi: return s1(S,F,P,G,L,E) mod s2(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the negative of s1 NegateSelector:=proc(s1) local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat("negative of ",s1(S,F,P,G,L,E)): fi: return -s1(S,F,P,G,L,E): end: return s: end: #Returns a selector that is the result of accumulating the return #value of s1 (starting from the left) #disc is a description of accum AccumulateSelector:=proc(s1,accum,disc:="an accumulator") local s: s:=proc(S,F,P,G,L,E) local rval,ret,i: if S=0 then return cat("result of accumulating ",s1(S,F,P,G,L,E), " with ", disc): fi: rval:=s1(S,F,P,G,L,E): if nops(rval) <= 1 then return rval: else ret:=accum(rval[1],rval[2]): for i from 3 to nops(rval) do ret:=accum(ret,rval[i]): od: return ret: fi: end: return s: end: #Returns a selector that is the result of composing f with the #return value of the selector #disc is a description of f ComposeSelector:=proc(s1,f,disc:="a function") local s: s:=proc(S,F,P,G,L,E) if S=0 then return cat("result of composing ",disc," with ", s1(S,F,P,G,L,E)): fi: return f(s1(S,F,P,G,L,E)): end: return s: end: #Return a selector that is the result of converting the return #value of s1 to a string StringSelector:=proc(s1) local s: s:=proc(S,F,P,G,L,E) if S=0 then return s1(S,F,P,G,L,E): fi: return convert(s1(S,F,P,G,L,E),string): end: return s: end: #Return a selector that is the result of putting the return #value of s1 into a list ListSelector:=proc(s1) local s: s:=proc(S,F,P,G,L,E) if S=0 then return s1(S,F,P,G,L,E): fi: return [s1(S,F,P,G,L,E)]: end: return s: end: #Returns a selector that has the same return values as s1 but uses #disc as its description instead RedescribeSelector:=proc(s1,disc) local s: s:=proc(S,F,P,G,L,E) if S=0 then return disc: fi: return s1(S,F,P,G,L,E): end: return s: end: ##SELECTOR GENERATORS #Constant selector, value=n MakeConstantSelector:=proc(n) local s: if S=0 then return cat("constant value ",convert(n,string)): fi: s:=proc(S,F,P,G,L,E) return n: end: return s: end: ##SELECTORS #S selector SSelector:=proc(S,F,P,G,L,E) if S=0 then return "subtraction set" fi: return S: end: #F selector FSelector:=proc(S,F,P,G,L,E) if S=0 then return "prefix" fi: return F: end: #P selector PSelector:=proc(S,F,P,G,L,E) if S=0 then return "period" fi: return P: end: #G selector GSelector:=proc(S,F,P,G,L,E) if S=0 then return "prefix length" fi: return G: end: #L selector LSelector:=proc(S,F,P,G,L,E) if S=0 then return "period length" fi: return L: end: #E selector ESelector:=proc(S,F,P,G,L,E) if S=0 then return "contractions" fi: return E: end: