MapleUnique - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


return unique copy of an object in external code


Calling Sequence




Calling Sequence

MapleUnique(kv, s)




kernel handle returned by StartMaple



Maple object



This function is part of the OpenMaple interface to Microsoft Visual Basic.


The MapleUnique function processes the Maple expression, s, and returns the unique normalized copy of that expression. For example, if you create the number num = one-billion, and then compute the number val = 2*500-million, an address comparison of num and val does not indicate equality. For example, after calling num = MapleUnique(kv,num);, both num and val point to the same memory.


Because Maple maintains a table of unique elements, only one copy of most objects exists in memory.  The expression x2+x contains two references to x, but both point to the same object.  Similarly, 1,2,1,2 contains two sublists, 1,2.  The surrounding list maintains two pointers to the same sublist.  It is usually not safe to directly modify any object that has been processed by Maple. For example, if the sublist were changed from 1,2 to 3,2, the parent list also changes.  In fact, all references to the list 1,2 in Maple would then point to 3,2. This would cause many problems. For example, table lookups of the 1,2 element would be changed to look up the 3,2 element.  It is safe to directly modify only data blocks of mutable objects like rtables and tables.  Never change strings returned by MapleToString, or expression sequences like the args object given to the external entry point.


Sub TestConvertToMaple(ByVal kv As Long)

    Dim list, args As Long

    list = MapleListAlloc(kv, 15)

    'MapleGcProtect kv, list

    MapleListAssign kv, list, 1, ToMapleBoolean(kv, 1)

    MapleListAssign kv, list, 2, ToMapleBoolean(kv, 0)

    MapleListAssign kv, list, 3, ToMapleBoolean(kv, -1)

    MapleListAssign kv, list, 4, ToMapleBoolean(kv, 2)

    MapleListAssign kv, list, 5, ToMapleChar(kv, "M")

    MapleListAssign kv, list, 6, ToMapleComplex(kv, 1.1, 2.2)

    MapleListAssign kv, list, 7, ToMapleComplexFloat(kv, _

         ToMapleFloat(kv, 3.3), ToMapleFloat(kv, 4.4))

    MapleListAssign kv, list, 8, ToMapleInteger(kv, 98765)

    MapleListAssign kv, list, 9, ToMapleFloat(kv, 3.1415)

    args = NewMapleExpressionSequence(kv, 2)

    MapleExpseqAssign kv, args, 1, ToMapleName(kv, "x", True)

    MapleExpseqAssign kv, args, 2, ToMapleName(kv, "x", True)

    MapleListAssign kv, list, 10, ToMapleFunction(kv, _

         ToMapleName(kv, "int", True), args)

    MapleListAssign kv, list, 11, ToMapleNULLPointer(kv)

    MapleListAssign kv, list, 12, ToMapleRelation(kv, ">", _

         ToMapleName(kv, "X", True), ToMapleInteger(kv, 1))

    MapleListAssign kv, list, 13, ToMapleString(kv, "A string")

    MapleListAssign kv, list, 14, ToMapleUneval(kv, _

         ToMapleName(kv, "Z", True))

    MapleListAssign kv, list, 15, ToMapleNULL(kv)

     'note this will get removed when the list is flattened

    MapleALGEB_Printf1 kv, "%a", MapleUnique(kv, list)

End Sub

See Also