Skip to content

Commit

Permalink
Update Condition Nodes.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Feb 28, 2024
1 parent 4f5ec65 commit 35d0445
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions darc-docs/docs/DARC Protocol/Condition Nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ struct NodeParam {

There are three logical operators in the DARC protocol: `AND`, `OR`, and `NOT`. The `AND` operator returns true if all of its children are true. The `OR` operator returns true if any of its children are true. The `NOT` operator returns true if its child is false. There must be at least one child for the `AND` and `OR` operators, and only one child for the `NOT` operator.

In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` functions to create the logical operators, for example:
In both By-law Script and darc.js SDK, you can use the `and()`, `or()`, and `not()` wrapper functions to create the logical operators, for example:

In darc.js SDK:

```ts
import {and, or, not} from 'darcjs';
import {and, or, not, AND, OR, NOT} from 'darcjs';

const conditionTree = and(
or(
Expand All @@ -42,6 +42,20 @@ const conditionTree = and(
expression4()
)
);

// or using the class constructor
const conditionTree = new And(
new OR(
expression1(),
expression2()
),

expression3(),

new NOT(
expression4()
)
);
```

In By-law Script:
Expand All @@ -59,6 +73,20 @@ const conditionTree = and(
expression4()
)
);

// or using the class constructor
const conditionTree = new AND(
new OR(
expression1(),
expression2()
),

expression3(),

new NOT(
expression4()
)
);
```

Also you can use `|` for `OR`, `&` for `AND`, and `!` for `NOT` in By-law Script, and these operators will be parsed into the corresponding condition nodes. For example, the above By-law Script can be written as:
Expand All @@ -70,6 +98,10 @@ const conditionTree =
( ! expression4() );
```

### Boolean Values

There are two boolean values in the DARC protocol: class `TRUE` and clss `FALSE`, or wrapper function `boolean_true()` and `boolean_false()`. They are used to represent a boolean node in the condition tree.

### Condition Expression

1. There are multiple batch-operations, including:
Expand Down

0 comments on commit 35d0445

Please sign in to comment.