Declarative programming: Difference between revisions

Content deleted Content added
See also: Remove recently unlinked item: Comparison of programming paradigms
Lisp: Get rid of unnecessary piping. Use "such as", not "like", for examples.
Line 60:
 
===Lisp===
[[Lisp (programming language) |Lisp]] is a family of programming languages loosely inspired by mathematical notation and [[Alonzo Church]]'s [[lambda calculus]]. Some dialects, likesuch as [[Common Lisp]], are primarily imperative but support functional programming. Others, likesuch as [[Scheme (programming language)|Scheme]], are designed for functional programming.
 
In Scheme, the [[factorial]] function can be defined as follows:
Line 73:
This defines the factorial function using its recursive definition. In contrast, it is more typical to define a procedure for an imperative language.
 
In lisps and lambda calculus, functions are generally [[first-class citizen |first-class citizens]]s. Loosely, this means that functions can be inputs and outputs for other functions. This can simplify the definition of some functions.
 
For example, writing a function to output the first n [[Squaresquare number|square numbers]]s in [[Racket (programming language)|Racket]] can be done accordingly:
 
<syntaxhighlight lang=scheme>
Line 84:
</syntaxhighlight>
 
The [[Map (higher-order function) |map]] function accepts a function and a list; the output is a list of results of the input function on each element of the input list.
 
===ML===