Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Computer Science: Abstraction, Syntax, Semantics, and Racket Programming, Summaries of Computer Science

An introductory overview of computer science, emphasizing the concepts of abstraction, syntax, and semantics. It introduces the racket programming language as a tool for exploring computation. Fundamental programming concepts such as values, expressions, definitions, evaluation rules, function application, and constant definitions. It also explores the concept of scope and the semantics of racket programs through substitution rules. Suitable for university students taking an introductory computer science course.

Typology: Summaries

2022/2023

Uploaded on 10/03/2024

fadekemi-1
fadekemi-1 ๐Ÿ‡จ๐Ÿ‡ฆ

1 document

1 / 59

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Module 01: Introduction
Introduction to Computer Science 1
University of Waterloo
Fall 2023
xkcd.com/297/
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b

Partial preview of the text

Download Introduction to Computer Science: Abstraction, Syntax, Semantics, and Racket Programming and more Summaries Computer Science in PDF only on Docsity!

Module 01: Introduction

Introduction to Computer Science 1

University of Waterloo

Fall 2023

xkcd.com/297/

Computer science is not programming โ€ฆBut we will use programming as a concrete medium in which to explore the nature of computation. "Computer science is no more about computers than astronomy is about telescopes." Edsger Dijkstra (?)

Racket

  • A^ pure functional^ programming language
  • Stripped-down syntax
  • Unfamiliar to most students taking the course
  • Really good for teaching and learning

The Language of Mathematics

The Language of Mathematics We all learned to write in a non-native language called Mathematics, whether we thought about it that way or not.

- Values:^ ,^ ,^ ,^ ,^ โ€ฆ - Expressions: , , , โ€ฆ - Definitions: , , โ€ฆ - Evaluation rules: 0 โˆ’ 37 3.14159 7 / 8 (6,4) 5 + 3 log 2 ( 2 โ‹… 8 ) 5 9 ( 90 โˆ’ 32 ) 2 100 โˆ’ 5 a = 13 ฯ€ = 3.14159โ€ฆ f ( x ) = x 2 โˆ’ x โˆ’ 1 f ( a โˆ’ 1 ) =?

The Language of Mathematics We all learned to write in a non-native language called Mathematics, whether we thought about it that way or not.

- Values:^ ,^ ,^ ,^ ,^ โ€ฆ - Expressions: , , , โ€ฆ - Definitions: , , โ€ฆ - Evaluation rules: 0 โˆ’ 37 3.14159 7 / 8 (6,4) 5 + 3 log 2 ( 2 โ‹… 8 ) 5 9 ( 90 โˆ’ 32 ) 2 100 โˆ’ 5 a = 13 ฯ€ = 3.14159โ€ฆ f ( x ) = x 2 โˆ’ x โˆ’ 1 f ( a โˆ’ 1 ) = 131

More Terminology

a = 13

f ( x ) = x

โˆ’ x โˆ’ 1

f ( a โˆ’ 1 )

Identifier

More Terminology

a = 13

f ( x ) = x

โˆ’ x โˆ’ 1

f ( a โˆ’ 1 )

Parameter

Argument

Body

Built-In Racket Functions

  • In Mathematics,^ denotes the absolute value function:^ , , etc.
  • Racket has a built-in function called^ abs; but how do we apply it? | โ‹… | | 4 | = 4 | โˆ’ 8 | = 8

Function Application Syntax Every Racket function application follows the same pattern:

  • An^ open parenthesis^ (
  • An^ identifier^ (the name of the function)
  • Some^ whitespace^ (spaces, tabs, newlines)
  • An^ argument^ (an expression producing a value passed to the function)
  • Any additional arguments, separated by more whitespace
  • A^ closing parenthesis^ )
  • In Mathematics, we use operator precedence (PEMDAS, BODMAS, etc.) and parentheses to resolve ambiguity 5 โ‹… 6 + 7 โ‰  5 โ‹… ( 6 + 7 ) 5 โ‹… 6 + 7 = ( 5 โ‹… 6 ) + 7
  • Racket's syntax is unambiguous by design. There are no precedence rules, and extra parentheses are never needed (in fact, they're illegal!) 5 โ‹… 6 + 7 (+ (* 5 6 ) 7 )

Useful Math Functions

  • add1,^ sub
  • quotient,^ remainder
  • abs
  • sqr,^ sqrt
  • expt See the Racket documentation for more!

Constants

  • Math contains a number of agreed-upon constants:^ ,^ , etc.
  • These are useful in programming, and therefore built in to Racket:^ pi,^ e.
  • Named constants:^ identifiers that are permanently bound to values
  • Of course, in math we can invent new constants as needed:
  • Can we do something similar in Racket? ฯ€ e G = 6.6743 ร— 10

Constant Definitions

  • We use the^ define^ special form^ to create new constants in Racket: (define cs115-grade 100 ) (define current-inflation-rate 7.6) (define avogadro 6.02214e23)
  • Once defined, these behave like any other named constants.