Is having a dedicated fn keyword necessary? I mean, what’s the fundamental difference between a func and a fn ?
55 karma · joined June 11, 2014
> But learning programming language theory is the best part :)
That's very true :)
This might be another reason why I find macros less appealing: macros introduce DSL in form of normal s-expression, but they don't actually behave like a function; macros introduce their own mini-language/syntax.
In the last example you provided, I bet the macro implementation would look like a little interpreter? If that's the case, having a function call like
doTexture(myTexture, ['op1', 'op0', 'opR'])
and let doTexture handle each cases(ops), might be able to achieve the same behavior, right?I'm not trying to argue that macros are unnecessary, I really want to like them! Just most of the time, I find functions are sufficient enough.
People use callback function to achieve almost the same thing
function doTexture(texture, fn) {
beginTextureMode(texture)
fn()
endTextureMode()
}
doTexture(myTexture, () => {
drawCircle()
drawRectagle()
})
At the cost of being more verbose, we get the benefit of one thing less to learn; and simplicity is a powerful feature IMO.I guess why this is less popular in lispy languages is because
1. macro
2. callback functions introduce more indent levels :(