- as an in-memory representation, and
- as a serialized representation
The two different captures give different behaviors because they capture different environments. Here's a trace to illustrate:
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :load /Users/lgm/work/src/projex/stellar/mdp4tw/SpecialK.SDEC/scripts/k.scala
cala
Loading /Users/lgm/work/src/projex/stellar/mdp4tw/SpecialK.SDEC/scripts/k.scala...
import scala.collection.mutable.HashMap
import scala.util.continuations._
import com.thoughtworks.xstream.XStream
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver
import biz.source_code.base64Coder.Base64Coder
import java.io.ObjectInputStream
import java.io.ByteArrayInputStream
import java.io.ObjectOutputStream
import java.io.ByteArrayOutputStream
defined module ObjectToString
defined module OK
scala> val ksmap1 = new HashMap[String,String]( )
val ksmap1 = new HashMap[String,String]( )
ksmap1: scala.collection.mutable.HashMap[String,String] = Map()
scala> val kmap1 = new HashMap[String,(String => Unit)]( )
val kmap1 = new HashMap[String,(String => Unit)]( )
kmap1: scala.collection.mutable.HashMap[String,(String) => Unit] = Map()
scala> OK.coral( false )( kmap1, ksmap1, "Erp" )
OK.coral( false )( kmap1, ksmap1, "Erp" )
continuation as string: rO0ABXNyAEdzY2FsYS51dGlsLmNvbnRpbnVhdGlvbnMuQ29udHJvbENvbnRleHQkJGFub25mdW4kbWFwJDIkJGFub25mdW4kYXBwbHkkMQAAAAAAAAAAAgADTAAGJG91dGVydAA4THNjYWxhL3V0aWwvY29udGludWF0aW9ucy9Db250cm9sQ29udGV4dCQkYW5vbmZ1biRtYXAkMjtMAANrJDF0ABFMc2NhbGEvRnVuY3Rpb24xO0wABXRociQxcQB+AAJ4cHNyADZzY2FsYS51dGlsLmNvbnRpbnVhdGlvbnMuQ29udHJvbENvbnRleHQkJGFub25mdW4kbWFwJDIAAAAAAAAAAAIAAkwABiRvdXRlcnQAKUxzY2FsYS91dGlsL2NvbnRpbnVhdGlvbnMvQ29udHJvbEN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MuQ29udHJvbENvbnRleHQkJGFub25mdW4kZm9yZWFjaCQxAAAAAAAAAAACAAB4cA==
resuming...
searching kmap : Map(Erp -> <function1>)
fns is <function1>
scala> kmap1( "Erp" )( "Erp" )
kmap1( "Erp" )( "Erp" )
resuming...
searching kmap : Map(Erp -> <function1>)
fns is <function1>
scala> val rK1 = ObjectToString.fromString( ksmap1( "Erp" ) ).asInstanceOf[( String => Unit )]
ing => Unit )]
rK1: (String) => Unit = <function1>
scala> rK1( "Erp" )
rK1( "Erp" )
resuming...
searching kmap : Map()
scala>
What is the intended semantics? Should they capture the same environments? Should the two executions be the same?
Best wishes in the New Year,
--greg
P.S. As a side note, i used to be able to serialize/deserialize delimited continuations using XStream. This fails now with
scala> val rK1 = new XStream( new JettisonMappedXmlDriver() ).fromXML( ks1 )
val rK1 = new XStream( new JettisonMappedXmlDriver() ).fromXML( ks1 )
com.thoughtworks.xstream.converters.ConversionException: Element fun of type scala.util.continuations.package$$anonfun$shiftR$1 is not defined as field in type scala.util.continuations.ControlContext$$anonfun$map$2
---- Debugging information ----
class : scala.util.continuations.ControlContext$$anonfun$map$2$$anonfun$apply$1
required-type : scala.util.continuations.ControlContext$$anonfun$map$2
path : /scala.util.continuations.ControlContext$$anonfun$map$2$$anonfun$apply$1/$outer[2]/fun
line number : -1
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.writeValueToImplicitCollection(AbstractReflectionConverter.java:283)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:236)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:162)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:63)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:76)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:246)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:218)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:162)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:63)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:76)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:60)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:137)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:33)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:923)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:909)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:845)
at .<init>(<console>:36)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $export(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:592)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$10.apply(IMain.scala:828)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:31)
at java.lang.Thread.run(Thread.java:680)
scala>
--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SW