From: Steve H. <sh...@zi...> - 2002-08-19 19:31:25
|
From: "Brian Ingerson" <in...@tt...> > On 19/08/02 14:27 -0400, Steve Howell wrote: > > From: "Brian Ingerson" <in...@tt...> > > > > > > Perl can use this particular interface a bit more powerfully because it > > > is list oriented: > > > > > > yaml_stream = YAML::dump(object_list) > > > object_list = YAML::load(yaml_stream) > > > > > > > This was actually a source of confusion, not convenience, for me in using the > > yaml.pm interface, although I blame Perl culture, not yaml.pm, for it. > > > > How do you distinguish these case when using YAML::dump? > > > > 1) You have a list of objects that should be written as separate documents. > > 2) You have an object that happens to be a list, but which should be written as > > a single document. > > That's the beauty of Perl lists: they're not a data structure, they're a > series of zero or more disjoint objects. I leverage this in YAML, > because in YAML (not coincidentally) a stream is a series of zero or more > disjoint documents. You didn't really answer my question, but I guess you're saying that the answer is #1. It's coming back to me now, though. If you have a Perl array and you want to dump it (use case #2), you pass in a reference to the array, not the array itself, which makes sense. How do you intend to add additional arguments to the dump method? Where would the list of thingies to dump end, and where would the formatting arguments start? It would be pretty ambiguous, and I think once you add more arguments to dump(), you're back to my original conundrum. > This doesn't apply as well to Python, because to emulate Perl list behaviour, > you need to use a data structure, namely an array, (which to make matters > ultimately confusing, Python calls a "list"). > My gosh, the only thing worse than YAML FUD is Python FUD. There is almost a direct correspondence between Perl lists and Python tuples, and likewise between Perl arrays and Python lists. Python's lists are actual objects, though, which is perhaps why Guido didn't call them arrays, although I agree it's confusing to call them lists. After you upgrade from Python 0.0003 to the latest version, try running this simple program, which gives a flavor for how tuples and lists are handled in Python: def hello(*people): for person in people: print "hello " + str(person) hello('ingy', 'steve') folks = ['neil', 'why', 'clark'] folks.sort() hello(folks) Cheers, Steve |