Introspection for checking an implementation

Mikhail_Kagalenko
Thu, 18 Sep 2025 16:05:41 +0000
General Usage

I am trying to implement an automated checking procedure for programming assignments. For example, I may ask a user to write function my_sum() for computing the sum of elements of a vector, then verify that he did not use the sum() function. Then I ask to write function to compute the mean of a vector’s elements, and would like to automatically verify that he used my_sum(), rather than copy-pasting its internal implementation.

All that is implemented in a Pluto notebook, so I can’t analyze the Expr tree. So, as suggested in this discussion, I look at the IR:

ci=Base.code_typed(my_mean,(AbstractVector,))[1][1]

Is it enough to verify that one of Expr elements of ci.code

a=[c.args[1] for c in ci.code if isa(c,Expr) && c.head===:call]

matches my_sum?

any(x->x.name===:my_sum, a)

11 posts - 5 participants