Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Declarative programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Lisp=== [[Lisp (programming language) |Lisp]] is a family of programming languages loosely inspired by mathematical notation and [[Alonzo Church]]'s [[lambda calculus]]. Some dialects, such as [[Common Lisp]], are primarily imperative but support functional programming. Others, such as [[Scheme (programming language)|Scheme]], are designed for functional programming. In Scheme, the [[factorial]] function can be defined as follows: <syntaxhighlight lang=scheme> (define (factorial n) (if (= n 0) 1 ;;; 0! = 1 (* n (factorial (- n 1))))) ;;; n! = n*(n-1)! </syntaxhighlight> 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]]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 [[square number]]s in [[Racket (programming language)|Racket]] can be done accordingly: <syntaxhighlight lang=scheme> (define (first-n-squares n) (map (lambda (x) (* x x)) ;;; A function mapping x -> x^2 (iota n))) ;;; Lists the first n naturals </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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)