开发者

What is this symbolic code transformation called?

开发者 https://www.devze.com 2023-01-01 23:46 出处:网络
I often cross this kind of code transformation (or even mathematical transformation).(Python example, but applies to any language.)

I often cross this kind of code transformation (or even mathematical transformation). (Python example, but applies to any language.)

I've go a function

def f(x):
  return x

I use it into another one.

def g(x):
  return f(x)*f(x)

print g(2)

leads to 4

But I want to remove the functional dependency, and I change the fu开发者_运维问答nction g into

def g(f):
  return f*f

print g( f(2) )

leads to 4 too

How do you call this kind of transformation, locally turning a function into a scalar ?


I'm not sure there is a specific term for it.

In general terms for functional programming there usually isn't a distinction made between passing scalar arguments and passing functions as arguments.

In the first example I could still call g(f(2)) and it should calculate f(f(2))*f(f(2)), which (since f(x) is the identity transformation) will also result in 4 as the answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消