Universal apply for custom types: 4‑field Cscore and InstanceSet support; preserve structural equality #324
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a generalized
apply
function that bridges standard library operations with our custom types and data structures, reducing redundant ad-hoc functions and improving ergonomics and reuse.Key changes:
key
projection:mkCscore
(fromscoring/cscore.metta
) and 4-fieldmkCscore
(frommetapopulation/exemplar-type.metta
), computing a composite key(penalizedScore, -complexity)
. For 4-field Cscore,penalizedScore := scor - cpxyPen - uniPen
.apply
onmkSInst
,mkExemplar
,mkXmplr
, andmkInst
delegates to their inner values (e.g., Cscore or List).apply
delegation formkSInstSet
to operate on the inner List when using list-like operations.Map
,MultiMap
,OS
(Ordered Set),OMS
(Ordered Multiset), andList
forlength
/contains
.apply ==
preserves exact equality for scalar keys and uses approximate numeric equality for composite Cscore keys only.(==)
remains the recommended choice for identity/deduplication (e.g.,ScoredInstance
/Exemplar
equality checks).Files of interest:
utilities/general-helpers.metta
:mkCscore
handling inkey
.apply
support formkSInstSet
.length
/contains
.apply
comparison behavior for<
,>=
,==
with the refined equality semantics above.Motivation and Context
cscore>=
) leading to redundancy, cognitive load, and easy-to-miss semantics drift.apply
as a type-aware adapter:(==)
), while ordering and popularity ranking require Cscore-aware comparisons (apply <
,apply >=
). We ensured we don’t change dedup semantics (e.g.,removeDupInsts
), which rely on strict equality.How Has This Been Tested?
mettalog
:apply ==
was used to dedupScoredInstance
/Exemplar
. Restoring structural(==)
for identity resolved it. Ordering still usesapply
comparisons as intended.apply
behavior with both 4-field and 5-fieldmkCscore
forms to confirm consistent ordering and equality where applicable.Types of changes
(==)
where required)Checklist:
apply
behavior (including 4-fieldmkCscore
andmkSInstSet
).mettalog
.(==)
is used where identity is required (e.g.,removeDupInsts
), andapply
ordering comparisons are used where semantically correct.Linking context:
apply
abstraction and clarifying the equality vs. ordering usage guidelines.