CSCI0200
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
--- tags: labs, spr22 --- # Lab 1 (CS0150): Working with Lists in Pyret Welcome to your first CS0200 lab! This lab will get you familiar working with Pyret datatypes, and manipulating lists using higher-order procedures (HOPs) and/or recursion (which will be very helpful for Homework 1!). ## Set-up (let's [get the party started](https://www.youtube.com/watch?v=mW1dbiD_zDk)) * Go to [code.pyret.org](https://code.pyret.org/); this requires logging in with any Google account (like your Brown account). * Make a new file in code.pyret.org. * Copy and paste this [stencil code](https://code.pyret.org/editor#share=1-b26xlHS3ANxeehePmtyISE3YYl3Dp8l&v=1904b2c) into your Pyret file. ### Documentation Once you have opened the editor, the Pyret documentation is accessible from the Pyret logo button in the top left corner of code.pyret.org. For this assignment, you will find the [list documentation](https://www.pyret.org/docs/latest/lists.html) useful. We recommend briefly browsing this page before working on these problems! ### Staff Assistance Your friendly lab TAs are here to help! Sign up on your lab's queue if you need help at any point in this lab. ### Pair Programming In CS0200's labs, you are expected to pair-program with different partners in each lab. Pair programming means that you're always working on the same piece of code, and one of you is typing while the other is telling them what to do and watching for mistakes, switching off coding and following in roughly 15 minute intervals (you can choose your stopping points). Mostly, just make sure everyone gets to code and also everyone gets to coach pretty equally. You should read our [Pair Programming Guide](https://hackmd.io/388rC8byRXq0bTRsFY1-WQ)! ## [Chasing Pyret](https://www.youtube.com/watch?v=uTxythHY09k) **Task**: Translate the following interface/inheritance and containment/association diagrams into Pyret data structures. Write the data definition(s) into your code file. [Here's](https://docs.google.com/document/d/1LZV1M75gozJuU7jouTmusjw2B4fjLPOCSh9feQ3sDXM/edit#heading=h.n64vzvb7650b) the i/i and c/a diagram guide for reference. ![](https://i.imgur.com/aOXMuYh.png) **Task**: Create two empty lists, `all-students` (which stores instances of `Student`) and`all-courses`(which stores instances of `Activity`). We're going to use these empty lists for the next set of tasks. ## [Shop 'til you drop](https://www.youtube.com/watch?v=QK8mJJJvaes) It's shopping period and everyone wants to know who's in their class! **Task**: Use your Pyret datatype from above to create the following 6 `course` objects. Add all the courses into the `all-courses` list. | # | dept | num | prof | credits | -------- | -------- | -------- | -------- | -------- | | 1 | VISA | 2320 | Alex Ryan | 1 | 2 | COLT | 10 | Ricky Chau | 0.5 | 3 | ENGL | 9000 | Brendan Ho | 1 | 4 | CSCI | 200 | Kathi Fisler | 1 | 5 | VISA | 100 | Daniel Stupar | 1 | 6 | ENGL | 100 | Brendan Ho | 1 **Task**: Use your Pyret datatype from above to create the following 3 `indepStudy` objects to represent independent studies (ISPs): | # | advisor | credits | -------- | -------- | -------- | | 1 | Austin Miles | 1 | 2 | Daniel Segel | 2 | 3 | Truman Cunningham | 2 **Task**: You want to make a schedule for two of your best friends + Alyssa! Luckily you already made course datatypes. Use your Pyret datatype from above to create these three students with the following `Activity` objects. Add all the students into the `all-students` list. | # | name | taking | | -------- | -------- | -------- | | 1 | Raphael | VISA2320, VISA100, Daniel's ISP, Austin's ISP | | 2 | Alyssa | COLT10, CSCI200, VISA2320 | | 3 | Cindy | VISA100, ENGL9000, ENGL100, Truman's ISP | You and your friends are competing to get into VISA0100. You want to figure out how to take in a list and return only the students taking VISA0100. **Checkpoint 1:** Call over a TA and make sure you've instantiated all of the data correctly! **Task:** Write a function `get-visa-students` that takes in a `Student` list and returns a list of all students taking VISA0100. ::: spoiler *Hint:* How do I handle variants with different fields within one datatype? It might seem tricky to work with the `Activity` datatype because it has two variants which each have different fields. If your function needs to check a field that isn't present in all variants, you can use case-matching. For example: ``` data Animal: | goldfish(name :: String, age :: Number) | puppy(weight :: Number) end fun get-name(pet :: Animal) -> String: cases (Animal) pet: | goldfish(n, _) => n | puppy(_) => "Give the puppy a name!" end end ``` The `_` means it's a field we're not going to use. You can read the [full Pyret documentation here](https://www.pyret.org/docs/latest/Pyret_Style_Guide.html#%28part._.Cases%29). ::: \ **Task:** Oops! The C@B searchbar crashed again. Write a function `find-course` that takes in an `Activity` list, a department code string, a course number, and returns a list containing the matching `course` object. **Task:** You hear the professors doing independent studies have easier classes. Write a function `get-isp-profs` that takes in an `Activity` list and returns a list of strings of all the professors supervising ISPs this semester. **Task:** Hmm...some of these courses should be worth more credits. Write a function `increase-credits` that takes in an `Activity` list and returns a new list in which all courses numbered 2000 and above are now worth 1.5 credits. **Task:** Brendan's going on sabbatical! Write a function `replace-prof` that takes in an `Activity` list and returns a new copy of the list of all courses, except that all courses taught by "Brendan Ho" are now taught by "Qinan Yu". **Checkpoint 2:** Call over a TA and check if your functions are correct! ## Recursion Practice In Monday's lecture, Milda introduced the practice of writing a sequence of related examples in a `check` block. This can be an extremely useful practice for figuring out how to write a program that builds up an answer while traversing a data structure (whether by iteration or recursion). Let's practice that skill. :::spoiler Screenshot from class if you need a reminder This was for a function that doubles all values in a list ![screenshot of related-example sequence](https://i.imgur.com/56sF5PN.png) ::: **NOTE:** For the next three questions, you are only writing `check` blocks, you are **NOT** writing the functions. **Task:** Develop a sequence of related examples in a `check` block for a function `concat-all` that takes a list of strings and returns the string resulting from concatenating (gluing) all of those strings together (e.g., `concat-all[list: "a", "b"]` produces `"ab"`). In Pyret, `+` concatenates strings. **Task:** Develop a sequence of related examples in a `check` block for a function `below-5` that takes a list of numbers and returns a list of those numbers that are smaller than 5. **Checkpoint 3:** Call over a TA and check whether your sequences have been done properly Work on the following tasks as time permits in lab (we know some students won't get this far) **Task:** Implement `concat-all` (for which you developed examples) **Task:** Implement `below-5` (for which you developed examples) **Task:** Develop a sequence of related examples in a `check` block for a function `all-profs` that takes a list of `Activity` and returns the list of names of professors who are teaching those activities (duplicates are fine). If you have time, write the code using recursion (rather than `map` -- the goal here is to practice recursion on small examples before we get to larger ones next week). <!-- ## TAs Work on things before this point -- Kathi will finish rest later Kathi still has to deveop these - Tracing recursion - Recursion Practice - total credits that a student is taking this semester - average credits taken by all students -students taking fewer than 2 courses --> <!-- Kathi may not put these in #| Program Planning: Which of map, filter, neither can you use to solve these. Discuss with partner - sorting courses by dept and number - finding profs teaching more than 3 credits - returning courses that students are taking concurrently with CSCI 200 - finding professors teaching in more than one department |# --> ______________________________ *Please let us know if you find any mistakes, inconsistencies, or confusing language in this or any other CSCI0200 document by filling out the [anonymous feedback form](https://docs.google.com/forms/d/e/1FAIpQLSdFzM6mpDD_1tj-vS0SMYAohPAtBZ-oZZH0-TbMKv-_Bw5HeA/viewform?usp=sf_link).*

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully