LogoList toString

21 views
Skip to first unread message

Corey Brady

unread,
Jul 30, 2014, 10:56:22 AM7/30/14
to netlogo-devel
hi all

i'm working with logo lists through the embedding API, and I am getting a strange behavior with toString ( or, well, an unfavorable behavior at least)

my context involves passing a list from one embedded instance of NetLogo to another. I get a list from one instance, assemble a NetLogo method call using that list (converted as a string) as an argument, and I use commandLater() to execute it in the other instance.

the conversion to string is needed simply because commandLater takes a string.

for long lists, the string coming through is truncated with ". . . ." at the end

obviously this causes trouble when it's passed to the receiving NetLogo instance :)

i happen to be working with NetLogo 4.1.3, but that can change if it helps

is this a known bug/limitation of LogoList?

would you recommend a workaround that hand-converts lists to strings, or an approach that gets around commandLater()'s need for strings and somehow digs deeper into the receiving-netlogo's workspace for a way to call the netlogo procedure directly and using a LogoList argument? (I'm not familiar with this second path)

thanks
-corey

Jason Bertsche

unread,
Jul 30, 2014, 11:21:11 AM7/30/14
to Corey Brady, netlogo-devel
Generally, using `toString` for serialization is not going to turn out
well for you—especially with Java/Scala collections, since it causes
truncation when the collection is above a certain (small) size. Instead,
use something like Java's `ObjectOutputStream`, Scala's `mkString`, or
simply iterate over the list and the build the proper string, yourself.

Nicolas Payette

unread,
Jul 30, 2014, 11:30:08 AM7/30/14
to Jason Bertsche, Corey Brady, netlogo-devel
I don't know the requirements of `commandLater()`, but wouldn't:

org.nlogo.api.Dump.list(myLogoList)

do the trick in this case?


--
Nicolas


On Wed, Jul 30, 2014 at 11:20 AM, Jason Bertsche
<jason.b...@northwestern.edu> wrote:
> Generally, using `toString` for serialization is not going to turn out well
> for you--especially with Java/Scala collections, since it causes truncation
> --
> You received this message because you are subscribed to the Google Groups
> "netlogo-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to netlogo-deve...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Corey Brady

unread,
Jul 30, 2014, 6:31:17 PM7/30/14
to Nicolas Payette, Jason Bertsche, netlogo-devel
Thanks, Nicolas! -- Dump-ing worked like a charm. Best, -Corey

Seth Tisue

unread,
Jul 31, 2014, 3:52:09 AM7/31/14
to netlog...@googlegroups.com
On Wednesday, July 30, 2014 4:56:22 PM UTC+2, Corey Brady wrote:
or an approach that gets around commandLater()'s need for strings and somehow digs deeper into the receiving-netlogo's workspace for a way to call the netlogo procedure directly and using a LogoList argument? (I'm not familiar with this second path)

It depends on what you are doing. For simple enough things you can get away with using strings. If you need it to work with any kind of NetLogo value, not just simple ones like e.g. lists of numbers, then you can't rely on round-tripping through strings and will need to switch to an approach like the one you describe.

If you end up needing that approach, we can discuss details. I remember discussing it with A****** H****** in the context of his über top secret L********** project, and I think I might have even made some tweaks to the workspace code and/or Evaluator to make it easier. Those conversations and commits could be dug up.

Seth

Reply all
Reply to author
Forward
0 new messages