(Try to) Fix the section that talks about `apply' and keyword arguments.

Closes PR 12438.
This commit is contained in:
Eli Barzilay 2012-05-08 01:08:09 -04:00
parent 07d5fbe1f6
commit d04920c032

View File

@ -84,7 +84,7 @@ above call to @racket[go] can be equivalently written
The syntax for function calls supports any number of arguments, but a The syntax for function calls supports any number of arguments, but a
specific call always specifies a fixed number of arguments. As a specific call always specifies a fixed number of arguments. As a
result, a function that takes a list of arguments cannot directly result, a function that takes a list of arguments cannot directly
apply a function like @racket[+] to all of the items in the list: apply a function like @racket[+] to all of the items in a list:
@def+int[ @def+int[
(define (avg lst) (code:comment @#,elem{doesn't work...}) (define (avg lst) (code:comment @#,elem{doesn't work...})
@ -101,8 +101,8 @@ apply a function like @racket[+] to all of the items in the list:
] ]
The @racket[apply] function offers a way around this restriction. It The @racket[apply] function offers a way around this restriction. It
takes a function and a @italic{list} arguments, and it applies the takes a function and a @italic{list} argument, and it applies the
function to the arguments: function to the values in the list:
@def+int[ @def+int[
(define (avg lst) (define (avg lst)
@ -122,9 +122,16 @@ are effectively @racket[cons]ed onto the argument list:
(anti-sum '(1 2 3)) (anti-sum '(1 2 3))
] ]
The @racket[apply] function supports only by-position arguments. To The @racket[apply] function supports keyword arguments too:
apply a function with keyword arguments, use the
@racket[keyword-apply] function, which accepts a function to apply @racketblock[
(apply go #:mode 'fast '("super.rkt"))
(apply go '("super.rkt") #:mode 'fast)
]
But since the keyword arguments are specified as usual, this form
cannot be used with a list holding keywords and values. For this, use
the @racket[keyword-apply] function, which accepts a function to apply
and three lists. The first two lists are in parallel, where the first and three lists. The first two lists are in parallel, where the first
list contains keywords (sorted by @racket[keyword<]), and the second list contains keywords (sorted by @racket[keyword<]), and the second
list contains a corresponding argument for each keyword. The third list contains a corresponding argument for each keyword. The third