[] \= '[]' (was Re: Ann: SWI-Prolog 7.1.0)
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
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