# DECIDE

Defines a named value or function with a body. The primary way to create computations in L4.

## Syntax

```l4
DECIDE name IS expression
DECIDE name MEANS expression
name MEANS expression
```

## Forms

### Named Values

```l4
DECIDE pi IS 3.14159
DECIDE greeting IS "Hello, World!"
```

### Functions with GIVEN

```l4
GIVEN x IS A NUMBER
DECIDE double x IS x TIMES 2
```

### Using MEANS

MEANS introduces the body of a function:

```l4
GIVEN n IS A NUMBER
DECIDE factorial n MEANS
  IF n EQUALS 0
  THEN 1
  ELSE n TIMES factorial (n MINUS 1)
```

### Omitting DECIDE

For functions, DECIDE can be omitted:

```l4
GIVEN x IS A NUMBER
double x MEANS x TIMES 2
```

## Examples

**Example file:** 

```l4-file
-- DECIDE keyword examples

-- Simple Named Values

DECIDE `the answer` IS 42
DECIDE `approximate pi` IS 3.14159
DECIDE `welcome greeting` IS "Hello, World!"
DECIDE `is enabled` IS TRUE

#EVAL `the answer`
#EVAL `welcome greeting`

-- Functions with DECIDE and MEANS

-- Simple function using MEANS
GIVEN x IS A NUMBER
`double a number` x MEANS x TIMES 2

#EVAL `double a number` 21

-- Function with DECIDE ... IS
GIVEN n IS A NUMBER
DECIDE `square of` n IS n TIMES n

#EVAL `square of` 7

-- Conditional Decisions

GIVEN age IS A NUMBER
`age category for` age MEANS
  IF age < 13 THEN "child"
  ELSE IF age < 20 THEN "teenager"
       ELSE IF age < 65 THEN "adult"
            ELSE "senior"

#EVAL `age category for` 25
#EVAL `age category for` 10

-- Boolean Decisions with IF

ASSUME `person age` IS A NUMBER
ASSUME `has valid ID` IS A BOOLEAN
DECIDE `can enter venue` IF
  `person age` >= 21 AND `has valid ID`

#CHECK `can enter venue`

-- Decisions with WHERE Clauses

GIVEN radius IS A NUMBER
DECIDE `area of circle with radius` radius IS
  `local pi` TIMES radius TIMES radius
  WHERE
    `local pi` MEANS 3.14159

#EVAL `area of circle with radius` 10

-- Recursive Decisions

GIVEN num IS A NUMBER
GIVETH A NUMBER
`factorial of` num MEANS
  IF num EQUALS 0
  THEN 1
  ELSE num TIMES `factorial of` (num MINUS 1)

#EVAL `factorial of` 5

-- Multi-parameter Functions

GIVEN a IS A NUMBER
      b IS A NUMBER
`maximum of two numbers` a b MEANS IF a > b THEN a ELSE b

#EVAL `maximum of two numbers` 10 25
```



### Simple Values

```l4
DECIDE answer IS 42
DECIDE isEnabled IS TRUE
DECIDE message IS "Welcome"
```

### Conditional Decisions

```l4
GIVEN age IS A NUMBER
DECIDE isAdult age IS
  IF age >= 18
  THEN TRUE
  ELSE FALSE
```

### With WHERE Clauses

```l4
DECIDE circleArea radius IS
  pi TIMES radius TIMES radius
  WHERE
    pi MEANS 3.14159
```

### Boolean Decisions with IF

For boolean-returning functions, use `DECIDE ... IF`:

```l4
GIVEN age IS A NUMBER
GIVEN income IS A NUMBER
DECIDE isEligible IF
  age >= 18 AND income > 30000
```

## Related Keywords

- **[MEANS](/l4/reference/functions/MEANS.md)** - Introduces the function body
- **[GIVEN](/l4/reference/functions/GIVEN.md)** - Introduces parameters
- **[GIVETH](/l4/reference/functions/GIVETH.md)** - Specifies return type
- **[WHERE](/l4/reference/functions/WHERE.md)** - Local definitions
- **[IF](/l4/reference/control-flow/IF.md)** - Boolean condition form

## Tutorials

- **[Using Infix, Postfix, and Mixfix Functions](/l4/tutorials/natural-language-functions/natural-language-functions.md)** - Define functions that read like natural language
