Wednesday, August 16, 2006

Closing the Loop on Erlang Metaprogramming with Smerl

Earlier today after work, I went jogging in the Hudson River Park. Jogging must do something postivie for the flow of mental juices, because as I was making my way back home, it suddenly struck me that I hadn't fully closed the loop on Erlang metaprogramming with Smerl! Smerl let you add functions to and remove functions from modules, but it didn't let you modify existing functions. Duh!

After I got back home, I sat by my MacBook and frantically hacked away until I fixed this unfortunate omission. I added two new functions: smerl:get_func and smerl:replace_func. You can use smerl:get_func to get the abstract form for a function. smerl:replace_func is a convenience function you can use instead of called smerl:remove_func and then smerl:add_func.

Finally, Smerl has all the capabilites for transforming Erlang modules from solid to liquid and then back to solid.

Does your language let you do that? If not, I think you should seriously forget everything you know and break on through to the other side :)


erlangist said...

How about export_fun,unexport_fun,define_record,import_fun...
and add something to support encrypt_debug_info?

Yariv said...

Interesting... I'll think about that. Currently, add_func lets you specifiy if the function should be exported or not. Also, IMO records aren't very useful in this scenario, because in this style of metaprogramming you generally get "down and dirty" with the underlying structure of the language. I haven't looked into encrypt_debug_info, but it sounds like that's a feature worth supporting. Thanks!