Skip to content

Commit 1214519

Browse files
authored
Add a max_iterations field to the repeat/until loop (and make until optional) and remove repeat/num_iterations loops. (#434)
1 parent 6af7898 commit 1214519

File tree

20 files changed

+544
-1967
lines changed

20 files changed

+544
-1967
lines changed

docs/tutorial.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,12 @@ The chatbot keeps looping by making a call to a model, asking the user if the ge
399399
and asking `why not?` if the answer (stored in variable `eval`) is `no`. The loop ends when `eval` becomes `yes`. This is specified with a Jinja expression on line 18.
400400

401401
Notice that the `repeat` and `then` blocks are followed by `text`. This is because of the semantics of lists in PDL. If we want to aggregate the result by stringifying every element in the list and collating them together, then we need the keyword `text` to precede a list. If this is omitted then the list is treated as a programmatic sequence where all the blocks are executed in sequence but result of the overall list is the result of the {\em last} block in the sequence. This behavior can be marked explicitly with a `lastOf` block.
402-
403-
Another form of iteration in PDL is `repeat` followed by `num_iterations`, which repeats the body `num_iterations` times.
402+
The number of iterations of a loop can be bounded by adding a `max_iterations` field.
404403

405404
The way that the result of each iteration is collated with other iterations can be customized in PDL using
406405
the `join` feature (see the following section).
407406

408-
## For Loops
407+
### For Loops
409408

410409
PDL also offers `for` loops over lists.
411410
The following [example](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/for.pdl) stringifies and outputs each number.

examples/hello/hello-iteration.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ text:
44
- "\n"
55
- repeat:
66
"This is your first PDL program\n"
7-
num_iterations: 3
7+
max_iterations: 3

0 commit comments

Comments
 (0)