From the course: Programming Foundations: Discrete Mathematics
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Use SML to create lists
From the course: Programming Foundations: Discrete Mathematics
Use SML to create lists
- [Voiceover] Another reason to use the SML programming language or the Standard Machine Language is to create list. List can be used to model sets. To create a list, you simply list all the values in brackets separated by commas. For example, I can have a list of integers. A list is similar to an array and it even must contain all values of the same type. Let's create another list. This list I'm gonna give a name. I'm gonna say val rainbow equals and I'm gonna give it all the colors of the rainbow. So I use my square bracket. And I have to put the names of the rainbow in double quotes since they're strings. So we'll start with Red and list all the values. Okay, now I have a list called rainbow. Once we create a list, we can perform operations on the list such as getting the first element. So let's go ahead and get the first element from our list called rainbow. We used the command hd. So I'm gonna say val first equals hd and in parentheses I'll give it the name of my list rainbow…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.