Refactor function evaluation (#12106).

Functions are now evaluated similarly to how variables are replaced with
their values.

Change-Id: Icba17934955e30557963cc65f90eb97eb3678401