From: Oren Ben-K. <or...@ri...> - 2002-09-24 16:19:32
|
Steve Howell [mailto:sh...@zi...] wrote: > Take this YAML: > > translations: > tilde: maps to None > quote quote: maps to empty string > implementation: PyYaml > > If you were to eliminate the 2nd and 3rd lines from the YAML > above, translations: implementation: PyYaml > you might expect either a syntax error (like PyYaml > now gives) or an empty dictionary > (after all, you just removed items from a dictionary). There's no marker that it is a dictionary. All you see is that there's no value. > Instead, you'd get an > empty string, or None, or something else that's not entirely > clear to me. It seems pretty intuitive to me. A null pointer to a dictionary is equal to a null pointer to a sequence and to a null pointer to a string... This works in C/C++/Java/Perl and, I suspect, Python. "No value" is just that - no value and hence no value kind. If you want an empty dictionary/sequence/string, these are all honest non-null objects and deserve some explicit syntax. In YAML you'd write them as: empty dictionary: {} empty sequence: [] empty string: "" All of these are very different from a null ("no value") in the internal representation of any language I'm aware of (except perhaps /bin/sh). > I like flexibility with implicit typing, but allowing > somebody to omit the placeholder altogether just seems like a > recipe for confusion. We'd have to forbid writing this: --- This: ... Forbidding it is artificial. It has an obvious semantics, that 'This' has no value associated with it (i.e., the value is a null). I agree that using an explicit '~' is more readable, and I'd encourage emitters to use it as a default. That's a matter of taste, however. > It also forces a lookahead in the parser. There already is lookahead in the parser: What am I? : # Looking ahead... # Still looking ahead... - value # Ah, a sequence. It has nothing to do with dis/allowing empty plain scalars. Have fun, Oren Ben-Kiki |