Re: [] \= '[]' (was Re: Ann: SWI-Prolog 7.1.0)
Alan Baljeu <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Take assurance from Scheme. Guy's decision to distinguish nil from false from etc. was anathema to the LISP community but in retrospect proved valuable. Alan ----- Original Message ----- From: Jan Wielemaker <[email protected]> To: Alan Baljeu <[email protected]>; Aleksey <[email protected]>; "[email protected]" <[email protected]> Cc: Sent: Sunday, November 24, 2013 11:47:49 AM Subject: [] \= '[]' (was Re: Ann: SWI-Prolog 7.1.0) On 11/23/2013 11:56 PM, Alan Baljeu wrote: >> This is all fine, until '[]' may appear as a token in the list. In that > >> case, flatten/2 just removes it. Due to the ambiguity of the empty list, >> creating a multi list and call flatten/2 is considered bad programming. >> Without this ambiguity, using multi lists is safe and can be a handy >> solution, in particular for the not-so-experienced Prolog programmer. > > Also for experienced programmers. I had to resort to ugly tagging > of data in expressions to distinguish [] as a list from atoms, not > to mention strings. I had (and still have) a hard time defending this. Yes, for most code that can work because it relies on [] \== '[]', there are also equally or more elegant ways to achieve your goals and no, it is not very elegant to have to introduce a new type of atomic constants with a single instance. And yes, the real ambiguities it creates on de-facto standard predicates (e.g., consult([]) and format("")) are a bit far-fledged. Also ambiguities it creates when mapping dynamically typed languages that do distinguish lists from symbols only provides weird corner cases that go wrong. I'm happy that quite a few Prolog programmers admit that this distinction is useful. We should also not forget that although I think we should claim that the designers of consult/1 and format/3 and related cases made a mistake by introducing this ambiguity, they were pretty experienced programmers at that time. Certainly much more experienced than the average Prolog programmer. Thanks --- Jan