Declarative programming: Difference between revisions

Content deleted Content added
Rescuing 9 sources and tagging 0 as dead.) #IABot (v2.0.9.5
copy editing: info is accurate, tho would be better nicer with citations; has some relevance bc functional lang is a declarative programming paradigm
Line 60:
 
===Lisp===
[[Lisp (programming language) | Lisp]] is a family of programming languages loosely inspired by mathematical notation and [[Alonzo Church]]'s [[lambda calculus]]. While someSome dialects, such aslike [[Common Lisp]], are primarily imperative, these lispsbut support functional programming,. and other lispsOthers, such aslike [[Scheme (programming language) |Scheme]], are designed for functional programming.
{{copyedit|section|reason=checking relevance and factual accuracy|date=December 2023}}
[[Lisp (programming language) | Lisp]] is a family of programming languages loosely inspired by mathematical notation and [[Alonzo Church]]'s [[lambda calculus]]. While some dialects, such as [[Common Lisp]] are primarily imperative, these lisps support functional programming, and other lisps, such as [[Scheme (programming language) |Scheme]] are designed for functional programming.
 
In schemeScheme, one may define the [[factorial]] function can be defined as suchfollows:
 
<syntaxhighlight lang=scheme>
Line 72 ⟶ 71:
</syntaxhighlight>
 
This can be construed as definingdefines the factorial function using its recursive mathematicaldefinition. definitionIn contrast, asit opposedis more typical to simply definingdefine a procedure, as one would typically do infor an imperative language.
 
In lisps, as inand lambda calculus, functions are generally [[first-class citizen |first-class citizens]]. Loosely, this means that functions can returnbe functions,inputs and beoutputs usedfor asother parametersfunctions. forThis othercan simplify the definition of some functions.
 
For example, if one wants to createwriting a function thatto returnsoutput the first n [[Square number|square numbers |squares]] in [[Racket (programming language) |Racket]], one can simplybe write thedone followingaccordingly:
This can greatly simplify the definition of certain functions.
 
For example, if one wants to create a function that returns the first n [[square numbers |squares]] in [[Racket (programming language) |Racket]], one can simply write the following:
 
<syntaxhighlight lang=scheme>
Line 87 ⟶ 84:
</syntaxhighlight>
 
The [[Map (higher-order function) | Mapmap]] in the abovefunction takesaccepts a function and list; the output is a list, applyingof results of the input function toon each memberelement of the input list.
 
===ML===