Skip to content

Commit

Permalink
Simplify toExternalString for mutable types
Browse files Browse the repository at this point in the history
The error message was essentially the same for mutable lists and
mutable hash tables, so we combine them.  We also drop
toExternalString(Type), since Type is a subclass of MutableHashTable,
and we can just use inheritance.
  • Loading branch information
d-torrance committed Aug 6, 2024
1 parent 9369e3e commit 05f5c46
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions M2/Macaulay2/m2/nets.m2
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ toExternalString Net := x -> if height x + depth x == 0 then
concatenate("(horizontalJoin())", "^", toString height x) else
concatenate(format toString x, "^", toString(height x - 1))

toExternalString MutableHashTable := s -> (
if hasAttribute(s,ReverseDictionary) then return toString getAttribute(s,ReverseDictionary);
error "anonymous mutable hash table cannot be converted to external string";
)
toExternalString Type := s -> (
if hasAttribute(s,ReverseDictionary) then return toString getAttribute(s,ReverseDictionary);
error "anonymous type cannot be converted to external string";
)
toExternalString MutableHashTable :=
toExternalString MutableList := s -> (
if hasAttribute(s,ReverseDictionary)
then toString getAttribute(s,ReverseDictionary)
else error("anonymous ", synonym class s,
" cannot be converted to external string"))

toExternalString HashTable := s -> (
concatenate (
"new ", toExternalString class s,
Expand All @@ -86,10 +85,6 @@ toExternalString HashTable := s -> (
then demark(", ", apply(pairs s, (k,v) -> toExternalString k | " => " | toExternalString v) )
else "",
"}"))
toExternalString MutableList := s -> (
error "anonymous mutable list cannot be converted to external string";
-- concatenate("new ",toExternalString class s, " from {...", toString(#s), "...}" )
)
mid := s -> (
if #s === 1 then toExternalString s#0
else between(",",apply(toSequence s,x -> if x === null then "" else toExternalString x))
Expand Down

0 comments on commit 05f5c46

Please sign in to comment.