Do something when value is stated as top-level

Is there any way to create a hook that is called when some values (say, values of a certain type) are stated as top-level? Perhaps by overloading the eval function?

Do you mean when the values are displayed? For that you can overload the display function.

1 Like

I mean not only in the REPL (sorry for not clarifying) but also when executing a file, e.g. in batch mode, or via embedding in a C program.

You can use the optional mapexpr argument of include to transform the parsed top-level expressions in the included file to do anything you want.

2 Likes