Hacker News new | past | comments | ask | show | jobs | submit login

Eager evaluation prevents many forms from being implemented at the function level. You can't for instance easily write a short-circuiting and() function in most languages, because arguments to a function are eagerly evaluated.

So given an and() function, you can't safely do "and(False, fire_missiles())", because the language will evaluate both arguments.

But an and!() macro could: macro expansion is essentially "lazy", in that it happens prior to the evaluation phase, so it can avoid evaluating any pieces of code it wants to, such that "and!(False, fire_missiles());" is perfectly safe, because our macro can stop expanding after "False" and thus fire_missiles() is never evaluated.

Incidentally, this is why at least some macro patterns are unnecessary in lazy languages like Haskell: you can write short-circuiting and() as a function there, because a function in Haskell only evaluates as much as is necessary (provided it's been written properly). Yet even there, Haskell still has support for macros and things like TemplateHaskell and so forth, because there's just some things you can't do solely with functions, like arbitrary syntax, language extensions, etc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: