ANN: Dogelog Runtime, Prolog to the Moon (2021)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 16 21:34:35 EDT 2021


On 16/09/21 2:56 pm, Mostowski Collapse wrote:
> I can access the functor of a compound via:
> 
>       obj.functor
> 
> but when I flatten Compound into arrays, it would become:
> 
>       obj[0]
> 
> Should I declare a constant FUNCTOR = 0?

You could, but keep in mind that access to a global in Python
is somewhat expensive, since it requires a dictionary lookup.

There's always a tradeoff between clarity and efficiency.
In this case, I think obj[0] is clear enough -- the reader
will be well aware that the first item of a term is the
functor. Especially if you use a name that makes it clear
what kind of object it is, rather than a generic name such
as "obj".

-- 
Greg



More information about the Python-list mailing list