Lumaktaw sa pangunahing content

EP: 11 - cond Expressions

Part 11. cond Expressions

There are some cases where we need to have 3 or more parallel conditions. Unlike most languages, racket, a lisp dialect, has only 2 expressions for an if-expression. 

This is solved using an elseif or a switch, the racket equivalent is the cond expression.

Here is an example.


We can use cond to have multiple questions without relying on if-expressions. We can also use square brackets but parenthesis also works.

A cond has a question and answer pair. The last question can use else in place of the question.

Evaluation rules

First, the question and answer pairs are evaluated each. The question is then evaluated which outputs a boolean. If true, then the entire cond expression is then replaced with the answer. If false, the pair is dropped.

Mga Komento