Lists and records
Programs often need more than one value. A list keeps several values in order. A record keeps related values under clear field names.
Use a list for many similar items. Use a record for facts that belong to one thing.
Make a list
Make list names.
Add "Asha" to names.
Add "Ravi" to names.
Add "Maya" to names.
Show names in JSON.The list is native Creole data. in JSON only changes how it is displayed.
Read every value
For each name in names.
Show name.
End.On each pass, name contains the next item. Use a plural name for the list and a singular name for one item.
Change a list
Add "Noah" to names.
Remove "Ravi" from names.
Show length of names.Keep list changes small and clear. Show or check the result while learning.
Make a record
A record describes one item with named fields:
Make record person.
Name is "Asha".
City is "Mumbai".
Active is true.
End.Read a field naturally:
Show person's name.
Show person's city.Build a record step by step
Create an empty record called book.
In book set title to "Learning Creole".
In book set pages to 120.
In book set available to true.
Show book in JSON.Both forms create native records. The block form is convenient when the fields are known together.
Put records in a list
Make list people.
Make record first_person.
Name is "Asha".
City is "Mumbai".
End.
Add first_person to people.
For each person in people.
Show person's name.
End.This pattern is useful for users, products, messages, tasks, and API results.
Native data and JSON
Do not write braces, colons, and commas to create normal Creole data. Build a list or record with Creole instructions.
Use JSON only when another system needs JSON text:
Show person in JSON.Common mistakes
- Do not use a record when order is the main purpose.
- Do not use a list when every value needs a different field name.
- Use
For eachinstead of repeating the same instruction manually. - Give fields and collections clear names.
- Check that a field exists before depending on external data.
Practice
Make list tasks.
Add "Install Creole" to tasks.
Add "Write a program" to tasks.
Add "Run the checker" to tasks.
For each task in tasks.
Show task.
End.
Make record progress.
Name is "First lesson".
Finished is true.
Step count is 3.
End.
Show progress in JSON.Learning checklist
- I can make a list.
- I can add and remove values.
- I can read every item with
For each. - I can make a record.
- I can read a record field.
- I understand that JSON output is optional.
Next step
Continue to Functions and modules to reuse work and separate a larger program into clear files.