A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.racket-lang.org/reference/if.html below:

if, cond, and, and or

3.12 Conditionals: if, cond, and, and or🔗ℹ

Conditionals in The Racket Guide introduces conditionals.

(if test-expr then-expr else-expr)

Evaluates

test-expr

. If it produces any value other than

#f

, then

then-expr

is evaluated, and its results are the result for the

if

form. Otherwise,

else-expr

is evaluated, and its results are the result for the

if

form. The

then-expr

and

else-expr

are in tail position with respect to the

if

form.

Examples:

(cond cond-clause ...)

  cond-clause   =   [test-expr then-body ...+]     |   [else then-body ...+]     |   [test-expr => proc-expr]     |   [test-expr]

A cond-clause that starts with else must be the last cond-clause.

If no cond-clauses are present, the result is #<void>.

If only a [else then-body ...+] is present, then the then-bodys are evaluated. The results from all but the last then-body are ignored. The results of the last then-body, which is in tail position with respect to the cond form, are the results for the whole cond form.

Otherwise, the first test-expr is evaluated. If it produces #f, then the result is the same as a cond form with the remaining cond-clauses, in tail position with respect to the original cond form. Otherwise, evaluation depends on the form of the cond-clause:

[test-expr then-body ...+]

The then-bodys are evaluated in order, and the results from all but the last then-body are ignored. The results of the last then-body, which is in tail position with respect to the cond form, provides the result for the whole cond form.

The proc-expr is evaluated, and it must produce a procedure that accepts one argument, otherwise the exn:fail:contract exception is raised. The procedure is applied to the result of test-expr in tail position with respect to the cond expression.

The result of the test-expr is returned as the result of the cond form. The test-expr is not in tail position.

Examples:

> (cond)

5

'here

'(-2 -3)

'(2 3)

Recognized specially within forms like

cond

. An

else

form as an expression is a syntax error.

Recognized specially within forms like

cond

. A

=>

form as an expression is a syntax error.

If no exprs are provided, then result is #t.

If a single expr is provided, then it is in tail position, so the results of the and expression are the results of the expr.

Otherwise, the first expr is evaluated. If it produces #f, the result of the and expression is #f. Otherwise, the result is the same as an and expression with the remaining exprs in tail position with respect to the original and form.

Examples:

If no exprs are provided, then result is #f.

If a single expr is provided, then it is in tail position, so the results of the or expression are the results of the expr.

Otherwise, the first expr is evaluated. If it produces a value other than #f, that result is the result of the or expression. Otherwise, the result is the same as an or expression with the remaining exprs in tail position with respect to the original or form.

Examples:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4