Citizendia
Your Ad Here

In computer science, a programming language is said to support first-class functions (or function literal) if it treats functions as first-class objects. Computer science (or computing science) is the study and the Science of the theoretical foundations of Information and Computation and their A programming language is an Artificial language that can be used to write programs which control the behavior of a machine particularly a Computer. In Computer science, a subroutine ( function, method, procedure, or subprogram) is a portion of code within a larger In Computing, a first-class object (also value, entity, and citizen) in the context of a particular Programming language, is an entity Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning them as the values of other functions. This concept doesn't cover any means external to the language and program (metaprogramming), such as invoking a compiler or an eval function to create a new function. Metaprogramming is the writing of Computer programs that write or manipulate other programs (or themselves as their data or that do part of the work at Compile time A compiler is a Computer program (or set of programs that translates text written in a computer language (the source language) into another In some Programming languages eval is a function which eval uates a string as though it were an expression and returns a result in others it executes

These features are a necessity for the functional programming style, in which (for instance) the use of higher-order functions is a standard practice. In Computer science, functional programming is a Programming paradigm that treats Computation as the evaluation of mathematical functions and In Mathematics and Computer science, higher-order functions or '''functionals''' are functions which do at least one of the following A simple example of a higher-ordered function is the map or mapcar function, which takes as its arguments a function and a list, and returns the list formed by applying the function to each member of the list. In many Programming languages map is the name of a Higher-order function that applies a given function to a sequence of elements (such as a list For a language to support map, it must support passing a function as an argument.

There are certain implementation difficulties in passing functions as arguments and returning them as results. Historically, these were termed the funarg problems, the name coming from "function argument". Funarg is an abbreviation for "functional argument" in Computer science, the funarg problem relates to a difficulty in implementing functions A different set of difficulties arises when programs can create functions at runtime; if the program is compiled, this means that the runtime environment must itself include a compiler.

Contents

Availability

Languages which are strongly associated with functional programming, such as Lisp, Scheme, ML, and Haskell, all support first-class functions. Lisp (or LISP) is a family of Computer Programming languages with a long history and a distinctive fully parenthesized syntax Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is ML is a general-purpose Functional programming language developed by Robin Milner and others in the late 1970s at the University of Edinburgh, whose syntax Haskell is a standardized Purely functional Programming language with non-strict semantics, named after the Logician Haskell Curry Other languages which also support them include Perl, Python, Lua, ECMAScript (JavaScript, ActionScript), Ruby, Io, Scala, and Nemerle. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below Python is a general-purpose High-level programming language. Its design philosophy emphasizes programmer productivity and code readability In Computing, Lua (ˈluːa LOO-ah is a lightweight, reflective, imperative and procedural Programming language, ECMAScript is a Scripting language, standardized by Ecma International in the ECMA-262 specification. JavaScript is a Scripting language most often used for Client-side web development ActionScript is a scripting language based on ECMAScript. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player Ruby is a dynamic, reflective, general purpose Object-oriented programming language that combines syntax inspired by Perl with Smalltalk Io is a pure object-oriented programming language inspired by Smalltalk, Self, Lua, Lisp, Act1 Scala ( Scalable Language) is a multi-paradigm Programming language designed to integrate features of Object-oriented programming and Nemerle is a high-level statically-typed Programming language for the.

Most modern, natively compiled programming languages (e. g. C and Pascal) support function pointers, which can be stored in data structures and passed as arguments to other functions. tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured Pascal is an influential imperative and procedural Programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small Nevertheless, they are not considered to support first-class functions since, in general, functions cannot be created dynamically during the execution of a program. The closest analog would be a dynamically compiled function created by a just-in-time compiler, which is compiled as an array of machine language instructions in memory and then cast to a function pointer. In Computing, just-in-time compilation ( JIT) also known as dynamic translation, is a technique for improving the runtime performance of a Computer Machine code or machine language is a system of instructions and data executed directly by a Computer 's Central processing unit. However, this technique is specific to the underlying hardware architecture and is, therefore, neither general nor portable. The C++ programming language supports user-defined operators, including the '()' operator, which allows first-class objects to be treated as functions. C++ (" C Plus Plus " ˌsiːˌplʌsˈplʌs is a general-purpose Programming language. Those objects can be manipulated just like any other first-class object in C++, but such manipulations do not include changing the function itself at runtime. Additionally, real Lambdas (see Lambda Calculus) have no language support in the last C++ standard (although there may be in C++0x). In Mathematical logic and Computer science, lambda calculus, also written as λ-calculus, is a Formal system designed to investigate function C++0x is the planned new standard for the C++ programming language.

Examples

Lisp

(lambda (a b) (* a b)) ; function literal
((lambda (a b) (* a b)) 4 5) ; function is passed 4 and 5

ALGOL 68

PROC newton = (REAL x, error, PROC (REAL) REAL f, f prime) REAL:
# Newton's method #
  IF f(x) <= error
  THEN x
  ELSE newton (x - f(x) / f prime (x), error, f, f prime)
  FI;

print((
  newton(0. Lisp (or LISP) is a family of Computer Programming languages with a long history and a distinctive fully parenthesized syntax Time-line of ALGOL 68 The Algorithmic Language ALGOL 68 Reports Mar In Numerical analysis, Newton's method (also known as the Newton–Raphson method, named after Isaac Newton and Joseph Raphson) is perhaps the 5, 0. 001, (REAL x) REAL: x**3 - 2*x**2 + 6, (REAL x) REAL: 3*x**2 - 4**x),
  newline
));

ECMAScript

function(message) { print(message); } // function literal
SomeObject. ECMAScript is a Scripting language, standardized by Ecma International in the ECMA-262 specification. SomeCallBack=function(message) { print(message); } // function literal assigned to callback

Note that the callee keyword in ECMAScript makes it possible to write recursive functions without naming them.

Python

Python does not have a (full) function literal, because lambda can only be followed by an expression and not statements. Python is a general-purpose High-level programming language. Its design philosophy emphasizes programmer productivity and code readability

lambda x:x*x # function literal 
map(lambda x:x*x,range(1,10)) # array of first ten square numbers

Javascript

Javascript supports both first class functions and lexical scope. JavaScript is a Scripting language most often used for Client-side web development In Computer programming, scope is an enclosing context where values and expressions are associated

// f: function that takes a number and returns a number
// deltaX: small positive number
// returns a function that is an approximate derivative of f
function makeDerivative( f, deltaX )
{
   var deriv = function(x)
               { 
                return ( f(x + deltaX) - f(x) )/ deltaX;
               }
   return deriv;
}
var cos = makeDerivative( Math. sin, 0. 000001);
// cos(0)     ~> 1
// cos(pi/2)  ~> 0

See also

In Computer science, a closure is a function that is evaluated in an environment containing one or more Bound variables When called the function can access A function object, also called a functor or functional, is a Computer programming construct allowing an object to be invoked or called as if In Computing, a first-class object (also value, entity, and citizen) in the context of a particular Programming language, is an entity
© 2009 citizendia.org; parts available under the terms of GNU Free Documentation License, from http://en.wikipedia.org
Dapyx Software network: MP3 Explorer | Ebook Manager | Zenithic