Abstract variable function?

Is a function nothing more than an abstract variable?

+3
source share
5 answers

No, more functions than simply getting the value, say int foo. A function may have side effects, such as allocating memory or opening a file. In addition, C or C ++ functions should not return a value.

+1
source

If you mean "a variable that has no direct use", yes, you can consider it as a variable containing the address of the function.

For example, in a language where functions are objects of the first class, you can pass a function as a parameter to a function.

, C .

0

, , . .

0

" ".

Scala, , :

trait X {
  val y: Int
}

" "!

trait MyMath[T] {
  // abstract
  val square: (T) => T
}

object IntegerMath extends MyMath[Int] {
  // concrete value (implementation) given to [previously-]abstract variable
  val square = (i: Int) => i * i
}

IntegerMath.square(2) // 4

... " ". , , , ​​ . (, ), .

# , , . .

, .

There are many different types of programming languages: some without side effects (bloating) - and this really should be at least mentioned so as not to be automatically packed (lame Java pun) in a certain way (C / C ++, for example) of thinking , especially when it comes to theory of language design.

Happy coding.

0
source

No. A function is nothing more than an abstract variable.

-1
source