WEBVTT

00:00:00.700 --> 00:00:06.055
This lesson turns a few pieces of information into a small, readable data model.

00:00:06.205 --> 00:00:11.453
We will keep a user record, count a visit, extend a list, and inspect a range.

00:00:11.603 --> 00:00:15.059
Before executing each example, predict the result.

00:00:15.209 --> 00:00:21.502
HHY chooses value types at runtime, but clear names and simple checks still matter.

00:00:21.652 --> 00:00:28.581
A record named user tells the reader more than a variable named data, especially once a script grows

00:00:28.581 --> 00:00:30.121
beyond a few lines.

00:00:32.270 --> 00:00:34.190
Let introduces a binding.

00:00:34.340 --> 00:00:39.140
Add mut when the binding needs reassignment, as our visit counter does.

00:00:39.290 --> 00:00:44.133
The update reads the old counter, adds one, and stores the new value.

00:00:44.283 --> 00:00:49.595
A plain let binding communicates that the name will keep its assigned value.

00:00:49.745 --> 00:00:53.606
Start with the simplest binding that matches your intention.

00:00:53.756 --> 00:01:01.484
Mutability of a binding and the behavior of collection operations are separate ideas; we will inspect

00:01:01.484 --> 00:01:05.831
collection results explicitly instead of assuming in place updates.

00:01:07.980 --> 00:01:11.991
Here are a Boolean, an integer, a floating point number, and null.

00:01:12.141 --> 00:01:17.538
Null represents absence; it is different from the text null and different from zero.

00:01:17.688 --> 00:01:24.024
The type function helps inspect a value, while is type checks a named type and returns a Boolean.

00:01:24.174 --> 00:01:28.419
These functions are useful when learning or handling external data.

00:01:28.569 --> 00:01:34.948
Prefer an explicit check when a later operation depends on a value being a particular kind.

00:01:37.100 --> 00:01:41.047
A list stores values in order and can be kept for reuse.

00:01:41.197 --> 00:01:46.061
Append returns an extended list, so assign that result to a name.

00:01:46.211 --> 00:01:53.339
Printing both names demonstrates the distinction: original still contains two entries, while extended has

00:01:53.339 --> 00:01:53.848
three.

00:01:53.998 --> 00:01:57.134
Length tells us how many entries are present.

00:01:57.284 --> 00:02:04.995
This is a helpful habit for unfamiliar APIs: keep the input, capture the output, and observe both before

00:02:04.995 --> 00:02:07.993
building more logic on top of them.

00:02:10.140 --> 00:02:12.636
A map associates keys with values.

00:02:12.786 --> 00:02:18.055
This example uses named fields so the source reads like a compact record.

00:02:18.205 --> 00:02:20.936
Dot access reads the known name field.

00:02:21.086 --> 00:02:26.377
Get is useful when the key is chosen as a string, and a missing key returns null.

00:02:26.527 --> 00:02:31.476
Put produces an updated map; capture that result as we did with append.

00:02:31.626 --> 00:02:36.405
Do not treat a missing key as proof that a numeric field contains zero.

00:02:36.555 --> 00:02:39.477
Decide how your application handles absence.

00:02:41.630 --> 00:02:46.963
A range describes a sequence of numbers without spelling each number in a list.

00:02:47.113 --> 00:02:54.717
Run this example and inspect its endpoint behavior: zero, one, and two are printed, while three is the

00:02:54.717 --> 00:02:55.561
exclusive end.

00:02:55.711 --> 00:02:58.783
This distinction prevents off by one mistakes.

00:02:58.933 --> 00:03:01.600
A for loop can visit the range directly.

00:03:01.750 --> 00:03:08.723
In a later lesson we will convert ranges into streams when we want the lazy transformation operators

00:03:08.723 --> 00:03:10.774
rather than an explicit loop.

00:03:12.920 --> 00:03:19.683
HHY also has literal forms for quantities such as duration, size, and percentage.

00:03:19.833 --> 00:03:23.822
They express intent more clearly than unexplained numbers.

00:03:23.972 --> 00:03:31.763
In the tested runtime, five seconds prints as five billion nanoseconds, and ten mebibytes prints as ten

00:03:31.763 --> 00:03:36.345
million four hundred eighty five thousand seven hundred sixty bytes.

00:03:36.495 --> 00:03:39.525
The displayed unit can differ from the source spelling.

00:03:39.675 --> 00:03:46.888
These literals will become useful for timeouts and size filters; do not replace them blindly with plain

00:03:46.888 --> 00:03:47.312
integers.

00:03:49.460 --> 00:03:55.540
This deliberately broken example reassigns a binding that was not declared mutable.

00:03:55.690 --> 00:04:01.493
Run the separate error file to see the diagnostic, then compare it with the working counter.

00:04:01.643 --> 00:04:07.957
The repair is to declare the counter with let mut when repeated updates are part of the design.

00:04:08.107 --> 00:04:12.651
Do not change every binding to mutable just to silence one error.

00:04:12.801 --> 00:04:19.820
Keep the lesson small: identify the name being reassigned and explain why that name needs to change.

00:04:21.970 --> 00:04:28.545
For practice, create another user, add a visit count, and print selected fields rather than depending on

00:04:28.545 --> 00:04:30.866
the display order of map keys.

00:04:31.016 --> 00:04:34.707
Then create a list of two user maps and check its length.

00:04:34.857 --> 00:04:42.040
You now have the basic shapes needed for real scripts: single values, stable and mutable bindings,

00:04:42.040 --> 00:04:44.734
ordered lists, keyed maps, and ranges.

00:04:44.884 --> 00:04:51.711
Next we will put decisions and repeated work around those values using functions and control flow.

