refactor: Avoid use of a "magic string " 'T'

This commit is contained in:
Glen Whitney 2022-07-31 09:13:41 -07:00
parent d4a4d8f331
commit 5c3716ff99
1 changed files with 6 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import {subsetOfKeys, typesOfSignature} from './utils.mjs'
const anySpec = {} // fixed dummy specification of 'any' type
const theTemplateParam = 'T' // First pass: only allow this one exact parameter
export default class PocomathInstance {
/* Disallowed names for ops; beware, this is slightly non-DRY
* in that if a new top-level PocomathInstance method is added, its name
@ -339,7 +341,7 @@ export default class PocomathInstance {
* We will start this out very simply: the special string `T` is always
* a template parameter, and that's the only one
*/
_templateParam(t) { return t === 'T' }
_templateParam(t) { return t === theTemplateParam }
_addAffect(dependency, dependent) {
if (dependency in this._affects) {
@ -401,8 +403,8 @@ export default class PocomathInstance {
Object.defineProperty(this, name, {configurable: true, value: 'limbo'})
const tf_imps = {}
for (const [rawSignature, {uses, does}] of usableEntries) {
/* For now, replace 'T' with 'any' */
const signature = rawSignature.replaceAll('T', 'any')
/* For now, replace theTemplateParam with 'any' */
const signature = rawSignature.replaceAll(theTemplateParam, 'any')
if (uses.length === 0) {
tf_imps[signature] = does()
} else {
@ -413,7 +415,7 @@ export default class PocomathInstance {
let [func, needsig] = dep.split(/[()]/)
const needTypes = needsig ? typesOfSignature(needsig) : new Set()
/* For now, punt on template parameters */
if (needTypes.has('T')) needsig = ''
if (needTypes.has(theTemplateParam)) needsig = ''
if (func === 'self') {
if (needsig) {
if (full_self_referential) {