inducer / pymbolic

A simple package to do symbolic math (focus on code gen and DSLs)

Home Page:http://mathema.tician.de/software/pymbolic

Repository from Github https://github.cominducer/pymbolicRepository from Github https://github.cominducer/pymbolic

disable_subscript_by_getitem

damiendr opened this issue · comments

From the documentation:

In prior versions of pymbolic, directly subscripting an Expression subclass generated a Subscript. For various reasons, this was a very bad idea. For example, the following code snippet would result in an infinite loop

If the only issue was the infinite loop, I would argue against the change. It is very nice to be able to write natural subscripts when building expression trees for an embedded DSL that represents arrays.

The infinite loop issue can be prevented by adding the following method to Expression:

def __iter__(self): raise Exception()

Thanks for the suggestion. The way I remember it, the infinite loop was really the one issue.

IndexError might actually be the best exception class here, now that I think of it.

damiendr notifications@github.com writes:

IndexError might actually be the best exception class here, now that I think of it.

Disagreed:

>>> iter(int())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable