A lambda expression which takes a function (of one argument) and a number, and applies the function to twice the number.
The syntactic elements of the Lisp programming language are symbolic expressions, also known as s-expressions. Both programs and data are represented as s-expressions: an s-expression may be either an atom or a list. Lisp atoms are the basic syntactic units of the language and include both numbers and symbols.
Scheme is a dialect of Lisp that stresses conceptual elegance and simplicity. It is specified in R4RS and IEEE standard P1178. (See the Scheme FAQ for details on standards for Scheme.) Scheme is much smaller than Common Lisp; the specification is about 50 pages, compared to Common Lisp's 1300 page draft standard.
A variable is a box-like object that can hold any Scheme value. It is said to be undefined if its box holds a special Scheme value that denotes undefined-ness (which is different from all other Scheme values, including for example #f ); otherwise the variable is defined.
Scheme is a multi-paradigm programming language. It is a dialect of Lisp which supports functional and procedural programming. It was developed by Guy L. Steele and Gerald Jay Sussman in the 1970s.
Applying the function to twice the number:
(lambda (f x) (f (* 2 x)))
Applying the function to the number twice (which is what you may have intended to ask):
(lambda (f x) (f (f x)))
Greg's answer is correct, but you might think about how you might break apart this problem to find the answer yourself. Here is one approach:
; A lambda expression
;(lambda () )
; which takes a function (of one argument) and a number
;(lambda (fun num) )
; and applies the function
;(lambda (fun num) (fun num))
; to twice the number
;(lambda (fun num) (fun (* 2 num)))
((lambda (fun num) (fun (* 2 num))) + 12)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With