3.7 Procedure Applications and #%app

► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

▼ | 3 | Syntactic Forms

3.1 | Modules: module, module*, ...
3.2 | Importing and Exporting: require and provide
3.3 | Literals: quote and #%datum
3.4 | Expression Wrapper: #%expression
3.5 | Variable References and #%top
3.6 | Locations: #%variable-reference
3.7 | Procedure Applications and #%app
3.8 | Procedure Expressions: lambda and case-lambda
3.9 | Local Binding: let, let*, letrec, ...
3.10 | Local Definitions: local
3.11 | Constructing Graphs: shared
3.12 | Conditionals: if, cond, and, and or
3.13 | Dispatch: case
3.14 | Definitions: define, define-syntax, ...
3.15 | Sequencing: begin, begin0, and begin-for-syntax
3.16 | Guarded Evaluation: when and unless
3.17 | Assignment: set! and set!-values
3.18 | Iterations and Comprehensions: for, for/ list, ...
3.19 | Continuation Marks: with-continuation-mark
3.20 | Quasiquoting: quasiquote, unquote, and unquote-splicing
3.21 | Syntax Quoting: quote-syntax
3.22 | Interaction Wrapper: #%top-interaction
3.23 | Blocks: block
3.24 | Internal-Definition Limiting: #%stratified-body
3.25 | Performance Hints: begin-encourage-inline
3.26 | Importing Modules Lazily: lazy-require
3.27 | Unsafe Access to Core Compiler Forms

On this page:

#%app
#%plain-app

Racket
top contents ← prev up next →

### 3.7 Procedure Applications and #%app🔗ℹ

> > > Function Calls in The Racket Guide introduces procedure applications.

> syntax (proc-expr arg ...)

Applies a procedure, when proc-expr is not an identifier that has a transformer binding (see Expansion).

More precisely, the expander converts this form to (#%app proc-expr arg ...), giving #%app the lexical context that is associated with the original form (i.e., the pair that combines proc-expr and its arguments). Typically, the lexical context of the pair indicates the procedure-application #%app that is described next. See also Expansion Steps.

Examples:

> > (+ 1 2)
> 3
> > ((lambda (x #:arg y) (list y x)) #:arg 2 1)
> '(2 1)

> syntax (#%app proc-expr arg ...)

Applies a procedure. Each arg is one of the following:

> > arg-expr

> The resulting value is a non-keyword argument.

> > keyword arg-expr

> The resulting value is a keyword argument using keyword. Each keyword in the application must be distinct.

The proc-expr and arg-exprs are evaluated in order, left to right. If the result of proc-expr is a procedure that accepts as many arguments as non-keyword arg-exprs, if it accepts arguments for all of the keywords in the application, and if all required keyword-based arguments are represented among the keywords in the application, then the procedure is called with the values of the arg-exprs. Otherwise, the exn:fail:contract exception is raised.

The continuation of the procedure call is the same as the continuation of the application expression, so the results of the procedure are the results of the application expression.

The relative order of keyword-based arguments matters only for the order of arg-expr evaluations; the arguments are associated with argument variables in the applied procedure based on the keywords, and not their positions. The other arg-expr values, in contrast, are associated with variables according to their order in the application form.

See also Expansion Steps for information on how the expander introduces #%app identifiers.

Examples:

> > (#%app + 1 2)
> 3
> > (#%app (lambda (x #:arg y) (list y x)) #:arg 2 1)
> '(2 1)
> > (#%app cons)
> cons: arity mismatch;
> the expected number of arguments does not match the given
> number
> expected: 2
> given: 0

> syntax (#%plain-app proc-expr arg-expr ...)
> (#%plain-app)

Like #%app, but without support for keyword arguments. As a special case, (#%plain-app) produces '().
top contents ← prev up next →