On this page:
Overview
Initial Git  Hub Tasks
Installing Racket
Reading
How to Write Code In This Class
Tasks
Submission Requirements
Submitting

Homework 0🔗

Last updated: Mon, 10 Feb 2025 13:15:49 -0500

Out: Tue Jan 28 2025, 11am EST

Due: Tue Feb 04 2025, 11am EST

Overview🔗

This is a quick assignment to make sure that everyone is set up to complete and submit assignments in this course.

After this homework, you should:
  • have a github.com account,

  • know how to execute basic git commands,

  • have told me your GitHub user name,

  • be a member of the CS450 Spring 2025 GitHub Organization,

  • have Racket installed,

  • know how to run basic Racket programs,

  • begin to understand basic functional programming (in Racket),

  • know how to submit homework to Gradescope, using the GitHub Submission Method, for this class.

This assignment is worth 10 points.

Initial GitHub Tasks🔗

Now you are almost ready to work!

Installing Racket🔗

Download Racket (for your platform) and install it.

The DrRacket IDE is easiest to use (especially for viewing images), but several other editors have Racket support as well.

Reading🔗

Read the Preface, Prologue, and Chapters 1.1-1.3 of How to Design Programs (2nd ed). Make sure to run the examples to get a feel for how to write and run programs in Racket.

NOTE: The textbook will refer to "Student Languages" (and a "Stepper" that only works with the Student Languages) which we will not use in this course . Instead, we will always use the full Racket language, which is invoked by putting #lang racket at the top of a file (see below).

How to Write Code In This Class🔗

Do the programming Tasks below. Before you do so, this section spells out some requirements and tips.

File Name and Contents

Put your code in a file named hw0.rkt, located in the repository root directory.

The first line of the file (and every file in this course, unless otherwise mentioned) should be #lang racket.

The hw0.rkt file must also export (using provide) the definitions needed for grading. The easiest way to ensure that your solution file can be graded is to put as the second line in the file:

(provide (all-defined-out))

You can see an example of what an initial hw0.rkt file looks at in hw0 starter code.

Commiting Files to GitHub

As you do the assignment, when you’ve reached an appropriate milestone (e.g., finished one exercise), you should commit and push your work to GitHub.

(Review Getting started with Git and Using Git if you need to.)

This will not only save a backup of your work in case of computer malfunction, it will also create a nice log in case you or someone else (me) needs to review it later, or if you need to revert to a previous state.

Make sure every commit has an appropriate commit message. See How to Write a Git Commit Message if you are unsure how to write a commit message.

Having a proper commit history, with good messages, will be part of the grade of each assignment.

Tasks🔗

Programming in a "functional" language like Racket is similar to writing mathematical functions, which compute via arithmetic.

For example, to implement the mathematical function f(x) = x + 1, you would write in Racket:

(define (f x)
  (+ x 1))

From the above, we can see that:
  • A function is defined using define.

  • A function has a header which consists of:
    • an open-paren after the define,

    • a function name, e.g., f,

    • a series of parameter names, this function only has one and it is named x,

    • a close-paren.

  • A function body which is an arithmetic expression that computes the result of the function, possibly using the input parameters. For function f, the body is (+ x 1). (Notice that there is no "return" statement!)

  • An open paren begins a function call, and the function name, e.g., +, always comes before the arguments.

IMPORTANT: All parens have meaning in Racket. For example, (+ 1 2) is not the same as ((+ 1 2)) (we leave it as an exercise to the reader to figure out what the result of the second expression is). Adding extraneous parens or forgetting one will likely make the program incorrect or invalid.

For this HW, write the following functions.

  1. The core of every large language model is a "perceptron", which is mostly just a function that computes a weighted sum f(\mathbf{x}) = \sum_{i=1}^n w_i x_i for some n and w_1,\ldots,w_n, where x is a vector consisting of n input components (x_1,\ldots,x_n).

    Write a Racket function called p that computes a weighted sum for n=9 and w_i=i. Note that for this function, each x_i should be a separate input parameter of the function.

    Your function should assume the inputs are always valid numbers and should not perform any "error checking".

  2. Of course, functions are not limited to operating on numbers. Another very common kind of data in programming is the string. The next function you will write will need to perform string "arithmetic".

    More specifically, different programming languages follow variable-naming conventions, e.g. camelCase or underscore_delimited. Racket Style calls for variables to be delimited by a hyphen, e.g., mk-racket-variable-name. Write a function with this name that takes in three strings and combines them into one variable name that follows the hyphen-delimited style and is all lower-case.

    The body of your function should be an "arithmetic" expression that is a combination of calls to the following functions only: string-append and string-downcase.

    Once again, your function should assume the inputs are valid strings and should not perform any "error checking".

  3. In high-level languages, arithmetic is the fundamental way to express computation, for any kind of value. Thus far, you’ve written functions that compute on numbers and strings. We can even "do arithmetic" on data structures.

    Specifically, write a function p/lst that is like p from problem 1, except n=5 and the input is a list of numbers. You might find the following functions for lists helpful: first, second, third, etc.

    Your function should assume the input is always a list of n=5 numbers and should not perform any "error checking".

Submission Requirements🔗

All code in this course will be evaluated not only for correctness, but also for readability, of which one component is style. In this course, all submitted code must follow the Racket Style Guide. For this assignment, you only need to worry about the things mentioned on this homework page. Other key style points will be emphasized in lecture and subsequent assignments.

Submitting🔗

When you are done, submit your work to Gradescope hw0. You must use the "GitHub" Submission Method and select your hw<X>-<LASTNAME>-<FIRSTNAME> repository.

Note that this is the only acceptable way to submit homework in this course. (Do not manually upload files and do not email files to the course staff. Homework submitted via any unapproved methods will be ignored and will not be graded.)