Function executing code as a param

I usualy add prints and such for debugging. I do this by


DEBUG = true

if DEBUG then print("something Here') end

Is there any way to create a function such as debug() that I could insert code as a parameter and have the function execute that code? I know Its easily used with print but is there a way to pass it another function and have it execute the function? such as debug( dump(p) ) and have it execute dump(p) ? Hopefully I am making sense.

Try (nor checked)

function debug(f,args) return f(args) end

-- then you can:
debug(f1,args1)
debug(f2,args2)

Hello @Briarfox. Does this help:


function setup()
    debug(print, "Hello", "World!")
end

function draw() background(0) end

function debug(f, ...)
    return f(unpack(arg))
end

Thanks Guys! @jmv38, it works like a charm. @mpilgrem Any chance you could explain … or have a link? I cant seem to find one googling it.

Scratch that, found it when googling unpack()