Created
October 4, 2016 13:36
-
-
Save mrb/d9ffcfb363ee83e883f8a22e94d0fe4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; A computer program tells a computer what to do | |
;; A computer program is made up of "code" | |
;; "Code" is different instructions that you can give the computer | |
;; For example, if you want the computer to add two numbers together, | |
;; you can ask it like this: | |
(+ 10 10) | |
;; When you run some code by pressing the green arrow | |
;; It will tell you the answers in the box below. Like this: | |
(- 10 5) | |
;; The way you write code is by first telling the computer WHAT you want it to do | |
;; And the things you want it to do it with. You make a list, and the computer | |
;; knows what to do with the list. | |
;; The stuff between the "(" and the ")" is a list. Here's a list of the people | |
;; in our family: | |
'("opal" "asa" "mike" "maya") | |
;; You can also ask the computer things about a list of words. Like, | |
;; "what is the first name in the list?" | |
(first '("opal" "asa" "mike" "maya")) | |
;; You can also ask it "what is the last name in the list?" | |
(last '("opal" "asa" "mike" "maya")) | |
;; You can also ask it "How long is this list?" | |
(length '("opal" "asa" "mike" "maya")) | |
;; You can also store the list and give it a special name | |
;; Like this: | |
(define family '("opal" "asa" "mike" "maya")) | |
;; Now that I have given the list a name, I can use that name instead of typing | |
;; the list over and over again, like this: | |
family | |
;; I can also use 'family' the same way that I used it above, like this: | |
(first family) | |
;; Our computer programs are written in Racket. We have a helper named "Dr. Racket" | |
;; who runs our programs for us. We can ask Dr. Racket questions, like "is the list | |
;; '("opal" "asa" "mike" "maya") the same as 'family' | |
(equal? family '("opal" "asa" "mike" "maya")) | |
;; In Racket, #t means 'true' and #f means 'false' | |
(= 1 2) | |
(= 100 100) | |
;; What if we wanted to store more than the names of the people in our family? | |
;; How would we also store their ages? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment