Macaulay2 » Documentation
Packages » Serialization :: serialize
next | previous | forward | backward | up | index | toc

serialize -- reversible conversion of all Macaulay2 objects to strings

Synopsis

Description

A convenient thing to serialize is the list of all user symbols provided by userSymbols, as in the following example.

i1 : R = QQ[x,y]

o1 = R

o1 : PolynomialRing
i2 : I = ideal (x^2+y^3-1)

            3    2
o2 = ideal(y  + x  - 1)

o2 : Ideal of R
i3 : S = R/I

o3 = S

o3 : QuotientRing
i4 : X = new Type of List

o4 = X

o4 : Type
i5 : g = new MutableList

o5 = MutableList{}

o5 : MutableList
i6 : h = new MutableList

o6 = MutableList{}

o6 : MutableList
i7 : g#0 = h

o7 = MutableList{}

o7 : MutableList
i8 : h#0 = g

o8 = MutableList{...1...}

o8 : MutableList
i9 : save := serialize userSymbols()

o9 = -- -*- mode: M2; coding: utf-8 -*-
     s0:=QQ -- Ring : QQ
     s1:=global QQ -- Symbol : QQ
     s2:=monoid[x..y, Degrees => {2:1}, Heft => {1}] -- GeneralOrderedMonoid : monoid[x..y, Degrees => {2:1}, Heft => {1}]
     s3:=s0 s2 -- PolynomialRing : R
     s4:=global R -- Symbol : R
     s5:=s3_{0, 3} -- R : y^3
     s6:=s3_{2, 0} -- R : x^2
     s7:=-1/1 -- QQ : -1
     s8:=1_s3 -- R : 1
     s9:=s5+s6+s7*s8 -- R : y^3+x^2-1
     s10:=ideal(s9) -- Ideal : ideal(y^3+x^2-1)
     s11:=global I -- Symbol : I
     s12:=s3/s10 -- QuotientRing : S
     s13:=global S -- Symbol : S
     s14:=Type -- Type : Type
     s15:=global Type -- Symbol : Type
     s16:=List -- Type : List
     s17:=global List -- Symbol : List
     s18:=newClass(s14,s16,hashTable{}) -- Type : X
     s19:=global X -- Symbol : X
     s20:=MutableList -- Type : MutableList
     s21:=global MutableList -- Symbol : MutableList
     s22:=newClass(s20,{}) -- MutableList : MutableList{...1...}
     s23:=newClass(s20,{}) -- MutableList : MutableList{...1...}
     s24:=global g -- Symbol : g
     s25:=global h -- Symbol : h
     s26:=s12_{1, 0} -- S : x
     s27:=global x -- Symbol : x
     s28:=s12_{0, 1} -- S : y
     s29:=global y -- Symbol : y
     s30:={s11,s4,s13,s19,s24,s25,s27,s29} -- List : {I, R, S, X, g, h, x, y}
     s4<-s3
     s11<-s10
     s13<-s12
     globalAssignFunction(s15,s14)
     globalAssignFunction(s17,s16)
     globalAssignFunction(s19,s18)
     s19<-s18
     globalAssignFunction(s21,s20)
     s22#0=s23
     s23#0=s22
     s24<-s23
     s25<-s22
     s27<-s26
     s29<-s28
     s30
i10 : clearAll
i11 : I

o11 = I

o11 : Symbol
i12 : value save

o12 = {I, R, S, X, g, h, x, y}

o12 : List
i13 : I

             3    2
o13 = ideal(y  + x  - 1)

o13 : Ideal of QQ[x..y]
i14 : g

o14 = MutableList{...1...}

o14 : MutableList
i15 : g#0 === h

o15 = true

For the programmer

The object serialize is a function closure.