Bug or mis-documented behavior in (collect words)?

Just going through the online docs with 0m03_046.
Chapter 3 talks about (collect words) and states in the code

%% By default, include any words mentioned in the name rule:
(dict $Obj)	(name $Obj)

That all makes sense to me, given what I’ve learned so far and my dabblings in Prolog. However, the generated $List contains redundant words.

As per docs, I am expecting

The green apple can be referred to using the words [yummy green apple].
The mysterious door can be referred to using the words [oaken oak mysteriou door].

and I actually get

The green apple can be referred to using the words [yummy green apple green apple].
The mysterious door can be referred to using the words [oaken oak mysteriou door mysteriou door].

Removing the aforementioned (dict $Obj) predicate produces expected results, but I don’t know why. Code was copy to clipboard from the docs and built to .z5, but the same duplicated words occur in .z5, .z8, and .aastory.

I don’t see anything in the documentation code that looks like it would trigger an extra call to name #apple (for example) which would then include those words twice in the final list. The code appears correct to me; plus even after removing the dict $Obj predicate name #x words are still being included, so something is adding those words to the list, but I don’t know if it’s intentional (and so, a bug in the docs) or a code bug.

The standard library includes that (dict $Obj) (name $Obj) line, so you don’t need to include it a second time in your code.

1 Like

Ahhh… I see. I was searching stdlib for a definition to (collect words)
I hadn’t considered looking specifically for (dict $Obj) but that makes sense. :+1:

Confusingly, the standard library doesn’t actually use (collect words) for this—it uses the more elaborate (determine object) (from words) (matching all of $) construction, which is like a fancy (collect words) with a bunch of optimizations specifically for parsing object names.

I’m not sure if the library actually uses (collect words) anywhere, actually, but it’s a very useful predicate for authors!

1 Like