Re: Compile function and AppendTo for lists (vrs. 8.0.4)

*To*: mathgroup at smc.vnet.net*Subject*: [mg124689] Re: Compile function and AppendTo for lists (vrs. 8.0.4)*From*: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>*Date*: Tue, 31 Jan 2012 05:39:59 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

Hi Fred, some short notes: > appendBag2a = Compile[{{k, _Integer, 0}}, Module[{p = Bag[Most[{0}]]}, > Do[StuffBag[p, Bag[{1, i}]], {i, 1, k}]; > Table[BagPart[BagPart[p, i], All], {i, 1, k}]]]; > > That works fine and fast, But look that your type p is clearly wrong. p is a bag of bags of Integer and has to be initialized with Internal`Bag[Most[{Internal`Bag[{1}]}]] We can only guess about the reasons why it works anyway. If it is implemented with pointers, than it seems the integers of your p-Bag are used to store the pointers. > The problem seems to be the initialization of the > locale variable p. I tried compilation with the definitions p=Bag[], > p=Bag[{}], p=Bag[Rest[{0}]], p=Bag[Rest[{{0,0}}]], or e.g. Now you know how. Cheers Patrick