Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 4183461[1X4 [33X[0;0YMessage exchange by [5XSCSCP[105X[101X[1X[133X[101X23[33X[0;0YTo ensure the message exchange as required by [5XSCSCP[105X specification, the [5XSCSCP[105X4package extends the global record [10XOMsymRecord[110X from the [5XOpenMath[105X package with5new entries to support [5Xscscp1[105X and [5Xscscp2[105X content dictionaries ([FHK+a],6[FHK+c]), and also service-dependent transient private content dictionaries7(see Chapter [14X5[114X for details about transient content dictionaries). It also8overwrites some [5XOpenMath[105X functions by their extended (but backwards9compatible) versions, and adds some new [5XOpenMath[105X-related functions to send10and receive [5XSCSCP[105X messages, documented below.[133X1112[33X[0;0YNote that functions documented in this chapter belong to the middle-level13interface, and the user may find it more convenient to use functions14developed on top of them and explained in next chapters.[133X151617[1X4.1 [33X[0;0YCommunication with the [5XSCSCP[105X[101X[1X server[133X[101X1819[1X4.1-1 StartSCSCPsession[101X2021[29X[2XStartSCSCPsession[102X( [3Xstream[103X ) [32X function22[6XReturns:[106X [33X[0;10Ystring[133X2324[33X[0;0YInitialises [5XSCSCP[105X session and negotiates with the server about the version25of the protocol. Returns the string with the [10Xservice_id[110X (which may be used26later as a part of the call identifier) or causes an error message if can27not perform these tasks.[133X2829[4X[32X Example [32X[104X30[4X[28X[128X[104X31[4X[25Xgap>[125X [27Xs := InputOutputTCPStream("localhost",26133);[127X[104X32[4X[28X< input/output TCP stream to localhost:26133 >[128X[104X33[4X[25Xgap>[125X [27XStartSCSCPsession(s);[127X[104X34[4X[28X"localhost:26133:5541"[128X[104X35[4X[25Xgap>[125X [27XCloseStream( s );[127X[104X36[4X[28X[128X[104X37[4X[32X[104X3839[33X[0;0YAfter the call to [2XStartSCSCPsession[102X the [5XSCSCP[105X server is ready to accept40procedure calls.[133X4142[1X4.1-2 OMPutProcedureCall[101X4344[29X[2XOMPutProcedureCall[102X( [3Xstream[103X, [3Xproc_name[103X, [3Xobjrec[103X ) [32X function45[6XReturns:[106X [33X[0;10Ynothing[133X4647[33X[0;0YTakes a stream [3Xstream[103X, the string [3Xproc_name[103X and a record [3Xobjrec[103X, and writes48to [3Xstream[103X an [5XOpenMath[105X object [10Xprocedure_call[110X for the procedure [3Xproc_name[103X with49arguments given by the list [10Xobjrec.object[110X and procedure call options (which50should be encoded as [5XOpenMath[105X attributes) given in the list51[10Xobjrec.attributes[110X.[133X5253[33X[0;0YThis function accepts options [10Xcd[110X and [10Xdebuglevel[110X.[133X5455[33X[0;0Y[10Xcd:="cdname"[110X may be used to specify the name of the content dictionary if56the procedure is actually a standard [5XOpenMath[105X symbol. Note that the server57may reject such a call if it accepts only calls of procedures from the58transient content dictionary, see [2XInstallSCSCPprocedure[102X ([14X5.1-1[114X) for59explanation). If the [10Xcdname[110X is not specified, [10Xscscp_transient_1[110X content60dictionary will be assumed by default. The value of the [10Xdebuglevel[110X option is61an integer. If it is non-zero, the [10Xprocedure_completed[110X message will carry on62also some additional information about the call, for example, runtime and63memory used.[133X6465[4X[32X Example [32X[104X66[4X[28X[128X[104X67[4X[25Xgap>[125X [27Xt:="";; stream:=OutputTextString(t,true);;[127X[104X68[4X[25Xgap>[125X [27XOMPutProcedureCall( stream, "WS_Factorial", rec( object:= [ 5 ], [127X[104X69[4X[25X>[125X [27X attributes:=[ [ "call_id", "user007" ], [127X[104X70[4X[25X>[125X [27X ["option_runtime",1000],[127X[104X71[4X[25X>[125X [27X ["option_min_memory",1024], [127X[104X72[4X[25X>[125X [27X ["option_max_memory",2048],[127X[104X73[4X[25X>[125X [27X ["option_debuglevel",1], [127X[104X74[4X[25X>[125X [27X ["option_return_object"] ] ) );;[127X[104X75[4X[25Xgap>[125X [27XPrint(t);[127X[104X76[4X[28X<?scscp start ?>[128X[104X77[4X[28X<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">[128X[104X78[4X[28X <OMATTR>[128X[104X79[4X[28X <OMATP>[128X[104X80[4X[28X <OMS cd="scscp1" name="call_id"/>[128X[104X81[4X[28X <OMSTR>user007</OMSTR>[128X[104X82[4X[28X <OMS cd="scscp1" name="option_runtime"/>[128X[104X83[4X[28X <OMI>1000</OMI>[128X[104X84[4X[28X <OMS cd="scscp1" name="option_min_memory"/>[128X[104X85[4X[28X <OMI>1024</OMI>[128X[104X86[4X[28X <OMS cd="scscp1" name="option_max_memory"/>[128X[104X87[4X[28X <OMI>2048</OMI>[128X[104X88[4X[28X <OMS cd="scscp1" name="option_debuglevel"/>[128X[104X89[4X[28X <OMI>1</OMI>[128X[104X90[4X[28X <OMS cd="scscp1" name="option_return_object"/>[128X[104X91[4X[28X <OMSTR></OMSTR>[128X[104X92[4X[28X </OMATP>[128X[104X93[4X[28X <OMA>[128X[104X94[4X[28X <OMS cd="scscp1" name="procedure_call"/>[128X[104X95[4X[28X <OMA>[128X[104X96[4X[28X <OMS cd="scscp_transient_1" name="WS_Factorial"/>[128X[104X97[4X[28X <OMI>5</OMI>[128X[104X98[4X[28X </OMA>[128X[104X99[4X[28X </OMA>[128X[104X100[4X[28X </OMATTR>[128X[104X101[4X[28X</OMOBJ>[128X[104X102[4X[28X<?scscp end ?>[128X[104X103[4X[28X[128X[104X104[4X[32X[104X105106[1X4.1-3 SCSCPwait[101X107108[29X[2XSCSCPwait[102X( [3Xstream[103X[, [3Xtimeout[103X] ) [32X function109[6XReturns:[106X [33X[0;10Ynothing[133X110111[33X[0;0YThis function may be used by the [5XSCSCP[105X client to wait (using [2XIO_select[102X ([14XIO:112IO_select[114X)) until the result of the procedure call will be available from113[3Xstream[103X. By default the timeout is one hour, to specify another value give it114as the optional second argument in seconds. See the end of this chapter for115the example.[133X116117[1X4.1-4 OMGetObjectWithAttributes[101X118119[29X[2XOMGetObjectWithAttributes[102X( [3Xstream[103X ) [32X function120[6XReturns:[106X [33X[0;10Yrecord with components [10Xobject[110X and [10Xattributes[110X, or [9Xfail[109X[133X121122[33X[0;0YThis function is similar to the function [10XOMGetObject[110X from the [5XOpenMath[105X123package, and the main difference is that it is able to understand [5XOpenMath[105X124attribution pairs. It retrieves exactly one [5XOpenMath[105X object from the stream125[3Xstream[103X, and stores it in the [10Xobject[110X component of the returned record. If the126[5XOpenMath[105X object has no attributes, the [10Xattributes[110X component of the returned127record will be an empty list, otherwise it will contain pairs128[10X[attribute_name,attribute_value][110X, where [10Xattribute_name[110X is a string, and129[10Xattribute_value[110X is a [5XGAP[105X object, whose type is determined by the kind of an130attribute. Only attributes, defined by the SCSCP are allowed, otherwise an131error message will be displayed.[133X132133[33X[0;0YIf the procedure was not successful, the function returns [9Xfail[109X instead of an134error message like the function [2XOMGetObject[102X ([14XOpenMath: OMGetObject[114X) does.135Returning [9Xfail[109X is useful when [10XOMGetObjectWithAttributes[110X is used inside136accept-evaluate-return loop.[133X137138[33X[0;0YAs an example, the file [11Xscscp/tst/omdemo.om[111X contains some [5XOpenMath[105X objects,139including those from the SCSCP Specification [FHK+b]. We can retrieve them140from this file, preliminary installing some SCSCP procedures using the141function [2XInstallSCSCPprocedure[102X ([14X5.1-1[114X):[133X142143[4X[32X Example [32X[104X144[4X[28X[128X[104X145[4X[25Xgap>[125X [27XInstallSCSCPprocedure("WS_Factorial", Factorial );[127X[104X146[4X[25Xgap>[125X [27XInstallSCSCPprocedure("GroupIdentificationService", IdGroup );[127X[104X147[4X[25Xgap>[125X [27XInstallSCSCPprocedure("GroupByIdNumber", SmallGroup );[127X[104X148[4X[25Xgap>[125X [27XInstallSCSCPprocedure( "Length", Length, 1, 1 );[127X[104X149[4X[25Xgap>[125X [27Xtest:=Filename( Directory( Concatenation([127X[104X150[4X[25X>[125X [27X GAPInfo.PackagesInfo.("scscp")[1].InstallationPath,"/tst/" ) ), [127X[104X151[4X[25X>[125X [27X "omdemo.om" );;[127X[104X152[4X[25Xgap>[125X [27Xstream:=InputTextFile(test);;[127X[104X153[4X[25Xgap>[125X [27XOMGetObjectWithAttributes(stream); [127X[104X154[4X[28Xrec( [128X[104X155[4X[28X attributes := [ [ "option_return_object", "" ], [ "call_id", "5rc6rtG62" ] ][128X[104X156[4X[28X , object := 6 )[128X[104X157[4X[25Xgap>[125X [27XOMGetObjectWithAttributes(stream);[127X[104X158[4X[28Xrec( attributes := [ ], object := 1 )[128X[104X159[4X[25Xgap>[125X [27XOMGetObjectWithAttributes(stream);[127X[104X160[4X[28Xrec( attributes := [ ], object := 120 )[128X[104X161[4X[25Xgap>[125X [27XOMGetObjectWithAttributes(stream);[127X[104X162[4X[28Xrec( [128X[104X163[4X[28X attributes := [ [ "call_id", "alexk_9053" ], [ "option_runtime", 300000 ], [128X[104X164[4X[28X [ "option_min_memory", 40964 ], [ "option_max_memory", 134217728 ], [128X[104X165[4X[28X [ "option_debuglevel", 2 ], [ "option_return_object", "" ] ],[128X[104X166[4X[28X object := [ 24, 12 ] )[128X[104X167[4X[25Xgap>[125X [27XOMGetObjectWithAttributes(stream);[127X[104X168[4X[28Xrec( [128X[104X169[4X[28X attributes := [ [ "call_id", "alexk_9053" ], [ "option_return_cookie", "" ] [128X[104X170[4X[28X ], object := <pc group of size 24 with 4 generators> )[128X[104X171[4X[25Xgap>[125X [27XOMGetObjectWithAttributes(stream);[127X[104X172[4X[28Xrec( attributes := [ [ "call_id", "alexk_9053" ], [ "info_runtime", 1234 ], [128X[104X173[4X[28X [ "info_memory", 134217728 ] ], object := [ 24, 12 ] )[128X[104X174[4X[25Xgap>[125X [27XCloseStream( stream );[127X[104X175[4X[28X[128X[104X176[4X[32X[104X177178179[1X4.2 [33X[0;0YCommunication with the [5XSCSCP[105X[101X[1X client[133X[101X180181[1X4.2-1 OMPutProcedureCompleted[101X182183[29X[2XOMPutProcedureCompleted[102X( [3Xstream[103X, [3Xobjrec[103X ) [32X function184[6XReturns:[106X [33X[0;10Y[9Xtrue[109X[133X185186[33X[0;0YTakes a stream [3Xstream[103X, and a record [3Xobjrec[103X, and writes to [3Xstream[103X an [5XOpenMath[105X187object [10Xprocedure_completed[110X with the result being [10Xobjrec.object[110X and188information messages (as [5XOpenMath[105X attributes) given in the list189[10Xobjrec.attributes[110X.[133X190191[4X[32X Example [32X[104X192[4X[28X[128X[104X193[4X[25Xgap>[125X [27Xt:="";; stream:=OutputTextString(t,true);;[127X[104X194[4X[25Xgap>[125X [27XOMPutProcedureCompleted( stream, [127X[104X195[4X[25X>[125X [27X rec(object:=120, [127X[104X196[4X[25X>[125X [27X attributes:=[ [ "call_id", "user007" ] ] ) );[127X[104X197[4X[28Xtrue[128X[104X198[4X[25Xgap>[125X [27XPrint(t);[127X[104X199[4X[28X<?scscp start ?>[128X[104X200[4X[28X<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">[128X[104X201[4X[28X <OMATTR>[128X[104X202[4X[28X <OMATP>[128X[104X203[4X[28X <OMS cd="scscp1" name="call_id"/>[128X[104X204[4X[28X <OMSTR>user007</OMSTR>[128X[104X205[4X[28X </OMATP>[128X[104X206[4X[28X <OMA>[128X[104X207[4X[28X <OMS cd="scscp1" name="procedure_completed"/>[128X[104X208[4X[28X <OMI>120</OMI>[128X[104X209[4X[28X </OMA>[128X[104X210[4X[28X </OMATTR>[128X[104X211[4X[28X</OMOBJ>[128X[104X212[4X[28X<?scscp end ?>[128X[104X213[4X[28X[128X[104X214[4X[32X[104X215216[1X4.2-2 OMPutProcedureTerminated[101X217218[29X[2XOMPutProcedureTerminated[102X( [3Xstream[103X, [3Xobjrec[103X, [3Xerror_cd[103X, [3Xerror_type[103X ) [32X function219[6XReturns:[106X [33X[0;10Ynothing[133X220221[33X[0;0YTakes a stream [3Xstream[103X, and a record with an error message [3Xobjrec[103X (for222example [10Xrec( attributes := [ [ "call_id", "localhost:26133:87643:gcX33cCf" ]223],[110X [10Xobject := "localhost:26133 reports : Rational operations: <divisor> must224not be zero")[110X and writes to the [3Xstream[103X an [5XOpenMath[105X object225[10Xprocedure_terminated[110X containing an error determined by the symbol [3Xerror_type[103X226from the content dictionary [3Xerror_cd[103X (for example, [10Xerror_memory[110X,227[10Xerror_runtime[110X or [10Xerror_system_specific[110X from the [5Xscscp1[105X content dictionary228([FHK+a]).[133X229230[33X[0;0YThis is the internal function of the package which is used only in the code231for the [5XSCSCP[105X server to return the error message to the client.[133X232233234[1X4.3 [33X[0;0YExample: [5XSCSCP[105X[101X[1X session[133X[101X235236[33X[0;0YIn the following example we start an [5XSCSCP[105X session and perform ten procedure237calls in a loop before closing that session. Note that we demonstrate the238usage of the session ID [10Xsid[110X and the function [10XRandomString[110X from the [5XOpenMath[105X239package to produce some unique call identifier. The call ID is a mandatory240attribute for any procedure call, however, it is not nesessarily random; for241example, it may be just a string with the number of the procedure call.[133X242243[4X[32X Example [32X[104X244[4X[28X[128X[104X245[4X[25Xgap>[125X [27Xstream:=InputOutputTCPStream( "localhost", 26133 );[127X[104X246[4X[28X< input/output TCP stream to localhost:26133 >[128X[104X247[4X[25Xgap>[125X [27Xsid := StartSCSCPsession( stream );[127X[104X248[4X[28X"localhost:26133:5541"[128X[104X249[4X[25Xgap>[125X [27Xres:=[];[127X[104X250[4X[28X[ ][128X[104X251[4X[25Xgap>[125X [27Xfor i in [1..10] do[127X[104X252[4X[25X>[125X [27X OMPutProcedureCall( stream, "WS_Factorial", [127X[104X253[4X[25X>[125X [27X rec( object := [ i ], [127X[104X254[4X[25X>[125X [27X attributes := [ [ "call_id", [127X[104X255[4X[25X>[125X [27X Concatenation( sid, ":", RandomString(8) ) ] ] ) );[127X[104X256[4X[25X>[125X [27X SCSCPwait( stream );[127X[104X257[4X[25X>[125X [27X res[i]:=OMGetObjectWithAttributes( stream ).object;[127X[104X258[4X[25X>[125X [27Xod;[127X[104X259[4X[25Xgap>[125X [27XCloseStream(stream);[127X[104X260[4X[25Xgap>[125X [27Xres;[127X[104X261[4X[28X[ 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800 ][128X[104X262[4X[28X[128X[104X263[4X[32X[104X264265[33X[0;0YAlso note the usage of [2XSCSCPwait[102X ([14X4.1-3[114X) to wait until the result of the266computation will be available from [10Xstream[110X.[133X267268[33X[0;0YIn this example we assumed that there is an [5XSCSCP[105X server running at269[10Xlocalhost[110X, port 26133. In the next chapter we will explain how to configure270and run a [5XGAP[105X [5XSCSCP[105X server and how to interrogate it from a [5XGAP[105X client to271learn about its functionality. After that, we will proceed with the [5XSCSCP[105X272client functionality for the end-user.[133X273274275276