diff --git a/Gemfile.lock b/Gemfile.lock index b920e8339b..6559fc9a3d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,22 +54,22 @@ GEM ffi (1.17.0-x86_64-linux-gnu) ffi (1.17.0-x86_64-linux-musl) forwardable-extended (2.6.0) - google-protobuf (4.27.1) + google-protobuf (4.27.5) bigdecimal rake (>= 13) - google-protobuf (4.27.1-aarch64-linux) + google-protobuf (4.27.5-aarch64-linux) bigdecimal rake (>= 13) - google-protobuf (4.27.1-arm64-darwin) + google-protobuf (4.27.5-arm64-darwin) bigdecimal rake (>= 13) - google-protobuf (4.27.1-x86-linux) + google-protobuf (4.27.5-x86-linux) bigdecimal rake (>= 13) - google-protobuf (4.27.1-x86_64-darwin) + google-protobuf (4.27.5-x86_64-darwin) bigdecimal rake (>= 13) - google-protobuf (4.27.1-x86_64-linux) + google-protobuf (4.27.5-x86_64-linux) bigdecimal rake (>= 13) http_parser.rb (0.8.0) @@ -138,7 +138,7 @@ GEM rb-inotify (0.11.1) ffi (~> 1.0) regexp_parser (2.9.2) - rexml (3.3.2) + rexml (3.3.3) strscan rouge (4.3.0) rspec (3.13.0) diff --git a/cur/programming/1-introduction/3-drawing/1-exploring-motion.es.html b/cur/programming/1-introduction/3-drawing/1-exploring-motion.es.html index 249dd06b60..d3e088da58 100644 --- a/cur/programming/1-introduction/3-drawing/1-exploring-motion.es.html +++ b/cur/programming/1-introduction/3-drawing/1-exploring-motion.es.html @@ -147,25 +147,25 @@
fijar color de lápiz a
. Las computadoras pueden desplegar millones de colores, pero a menos que sea necesario hacer coincidir exáctamente con un color en específico, no hace falta complicarse por hacerlo coincidir a menos que tengas la combinación correcta. La biblioteca de colores fuciona como una caja de crayones, brinda una selección de los colores más utilizados y se encuentran clasificados en familias. De esta forma si deseas incluir una variedad de tonos marrones, selecciona un número entre 30 y 39.punta de lápiz plana
y obtener resultados interesantes como aparecen a continuación:
+ Jasmine: Me gusta la idea de dibujar líneas muy gruesas sin usar el bloque punta de lápiz plana
y obtener resultados interesantes como aparecen a continuación:
set pen to crayon
block. Computers can display billions of colors, but unless you have to match the paint on your wall very precisely, finding your way through all those colors may be more trouble than it's worth. The crayon library, just like a box of crayons, gives you a small set of vibrant colors, arranged in families. So if you want a lot of browns in your picture, you could pick a random number between 30 and 39.flat line ends
and get interesting results:
+ Jasmine: I bet we can use the idea of drawing really thick lines without using flat line ends
and get interesting results:
artículo de
dentro de un bucle para
y usar el índice del bucle para
como el primera entrada a elemento de
, así:para cada
al área de secuencias de comandos.para cada
al área de secuencias de comandos.item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:for each
into the scripting area.for each
into the scripting area.If Else
if else
the way I think we were supposed to, but we also found a way to do them with repeat until
and even a way without using any conditionals at all.
+ Omar: Hey, Jasmine! Morgan! Delia and I did the puzzles in problem 2 using if else
the way I think we were supposed to, but we also found a way to do them with repeat until
and even a way without using any conditionals at all.
If Else
if else
. Do you think there is a way?
+ Omar: But we couldn't find any way to do problem 3 without if else
. Do you think there is a way?
if else
with your method that uses no conditionals. What are the advantages/disadvantages of each method?repeat until
.if else
?
+ Answer Omar's last question. Do you think there is a way to do problem 3 without if else
?
ST-Suggested replacement:".....Why can't we just draw a letter on the screen by clicking on the corner points that define the letter?"
Again, I don't think it's realistic to click on the screen freehand. On the previous page they drew their A on graph paper first. --bh
point list
variable to an empty list.forever
block with one that will loop only until the user presses the space key.ST-Suggested replacement:".....Why can't we just draw a letter on the screen by clicking on the corner points that define the letter?"
Again, I don't think it's realistic to click on the screen freehand. On the previous page they drew their A on graph paper first. --bh
If Else
if else
the way I think we were supposed to, but we also found a way to do them with repeat until
and even a way without using any conditionals at all.
+ Omar: Hey, Jasmine! Morgan! Delia and I did the puzzles in problem 2 using if else
the way I think we were supposed to, but we also found a way to do them with repeat until
and even a way without using any conditionals at all.
If Else
if else
. Do you think there is a way?
+ Omar: But we couldn't find any way to do problem 3 without if else
. Do you think there is a way?
if else
with your method that uses no conditionals. What are the advantages/disadvantages of each method?repeat until
.if else
?
+ Answer Omar's last question. Do you think there is a way to do problem 3 without if else
?
If Else
if else
the way I think we were supposed to, but we also found a way to do them with repeat until
and even a way without using any conditionals at all.
+ Omar: Hey, Jasmine! Morgan! Delia and I did the puzzles in problem 2 using if else
the way I think we were supposed to, but we also found a way to do them with repeat until
and even a way without using any conditionals at all.
If Else
if else
. Do you think there is a way?
+ Omar: But we couldn't find any way to do problem 3 without if else
. Do you think there is a way?
if else
with your method that uses no conditionals. What are the advantages/disadvantages of each method?repeat until
.if else
?
+ Answer Omar's last question. Do you think there is a way to do problem 3 without if else
?
point
ADT, you won't have to think about how points are represented as lists.item 2 of
.item 2 of
, so what's the use? It won't make the program shorter.x coordinate
and y coordinate
instead of item of
as inputs to the go to
block.point
ADT, you won't have to think about how points are represented as lists.item 2 of
.item 2 of
, so what's the use? It won't make the program shorter.x coordinate
and y coordinate
instead of item of
as inputs to the go to
block.go to point
block (from "U2L2-DrawShape") by using selectors inside the go to point
block as Betsy and Gamal described.go to point
block (from "U2L2-DrawShape") by using selectors inside the go to point
block as Jasmine and Omar described.point
ADT, you won't have to think about how points are represented as lists.item 2 of
.item 2 of
, so what's the use? It won't make the program shorter.x coordinate
and y coordinate
instead of item of
as inputs to the go to
block.point
ADT, you won't have to think about how points are represented as lists.item 2 of
.item 2 of
, so what's the use? It won't make the program shorter.x coordinate
and y coordinate
instead of item of
as inputs to the go to
block.go to point
block (from "U2L2-DrawShape") by using selectors inside the go to point
block as Betsy and Gamal described.go to point
block (from "U2L2-DrawShape") by using selectors inside the go to point
block as Jasmine and Omar described.ST-Suggested replacement:".....Why can't we just draw a letter on the screen by clicking on the corner points that define the letter?"
Again, I don't think it's realistic to click on the screen freehand. On the previous page they drew their A on graph paper first. --bh
ST-Suggested replacement:".....Why can't we just draw a letter on the screen by clicking on the corner points that define the letter?"
Again, I don't think it's realistic to click on the screen freehand. On the previous page they drew their A on graph paper first. --bh
polygon
block store each vertex as a point
while it draws the polygon. We listed points as we clicked on them. This is the same, but with the program generating the points.polygon
block store each vertex as a point
while it draws the polygon. We listed points as we clicked on them. This is the same, but with the program generating the points.polygon
block.polygon
block.add
here. --MF, 3/25/19 Maybe it's a reminder that they're using lists? -bhpolygon
and in the script that draws the design, so I'd make it global so multiple scripts can access it.polygon
and in the script that draws the design, so I'd make it global so multiple scripts can access it.Yes, but isn't this referring to the line segments inside, which are diagonals? --MF, 5/31/19
for each
to connect just that one to each other vertex. After that, it's easy! We can use that block on each vertex.for each
to connect just that one to each other vertex. After that, it's easy! We can use that block on each vertex.
- Alphie and Betsy are building a program that will take a list of points as input and connect the dots. They sketched the letter A on graph paper and listed the vertices.
+ Morgan and Jasmine are building a program that will take a list of points as input and connect the dots. They sketched the letter A on graph paper and listed the vertices.
point
constructor to use in the draw shape()
block that takes a list of points as input. (show images of it taking a list and also taking a variable and of that variable being set as a list--perhaps all behind a click.)
Alphie and Betsy are building a program that will take a list of points (each of which is a list of x and y coordinates) as input and connect the dots. They figure they can use it to draw pictures or graphs of data:
+Morgan and Jasmine are building a program that will take a list of points (each of which is a list of x and y coordinates) as input and connect the dots. They figure they can use it to draw pictures or graphs of data:
To make a set of starting data, they sketched the letter A on graph paper. They chose a scale that they figured would make their picture a good size on the stage.
code
tags for Make a variable. Should we? --MF, 12/19/18 Betsy clicks Make a variable
, names it A
, and builds .
Jasmine clicks Make a variable
, names it A
, and builds .
Then she clicks that set
block to run it.
go to point
. It'll work like this . We'll use or inside it, but we'll have to process the input, , to supply x:
and y:
separately. Hmmm... go to point
block show that it expects a list as input....go to point
. It'll work like this . We'll use or inside it, but we'll have to process the input, , to supply x:
and y:
separately. Hmmm... go to point
block show that it expects a list as input....Brian now agrees with having a page break here. --MF, 12/19/18 OTOH we should decide if we want to take advantage of Snap!'s ability to take lists in GO TO.
go to point
block for each of the points in our list.go to point
block for each of the points in our list.Alphie and Betsy design this new script to automate the process of going to each point.
+Morgan and Jasmine design this new script to automate the process of going to each point.
Then they test it out.
for each
does exactly what we want. But we have a couple of bugs to fix.for each
does exactly what we want. But we have a couple of bugs to fix.
- Alphie and Betsy are building a program that will take a list of points as input and connect the dots. They sketched the letter A on graph paper and listed the vertices.
+ Morgan and Jasmine are building a program that will take a list of points as input and connect the dots. They sketched the letter A on graph paper and listed the vertices.
point
constructor to use in the draw shape()
block that takes a list of points as input. (show images of it taking a list and also taking a variable and of that variable being set as a list--perhaps all behind a click.)
Alphie and Betsy are building a program that will take a list of points (each of which is a list of x and y coordinates) as input and connect the dots. They figure they can use it to draw pictures or graphs of data:
+Morgan and Jasmine are building a program that will take a list of points (each of which is a list of x and y coordinates) as input and connect the dots. They figure they can use it to draw pictures or graphs of data:
To make a set of starting data, they sketched the letter A on graph paper. They chose a scale that they figured would make their picture a good size on the stage.
code
tags for Make a variable. Should we? --MF, 12/19/18 Betsy clicks Make a variable
, names it A
, and builds .
Jasmine clicks Make a variable
, names it A
, and builds .
Then she clicks that set
block to run it.
go to point
. It'll work like this . We'll use or inside it, but we'll have to process the input, , to supply x:
and y:
separately. Hmmm... go to point
block show that it expects a list as input....go to point
. It'll work like this . We'll use or inside it, but we'll have to process the input, , to supply x:
and y:
separately. Hmmm... go to point
block show that it expects a list as input....Brian now agrees with having a page break here. --MF, 12/19/18 OTOH we should decide if we want to take advantage of Snap!'s ability to take lists in GO TO.
go to point
block for each of the points in our list.go to point
block for each of the points in our list.Alphie and Betsy design this new script to automate the process of going to each point.
+Morgan and Jasmine design this new script to automate the process of going to each point.
Then they test it out.
for each
does exactly what we want. But we have a couple of bugs to fix.for each
does exactly what we want. But we have a couple of bugs to fix.polygon
block store each vertex as a point
while it draws the polygon. We listed points as we clicked on them. This is the same, but with the program generating the points.polygon
block store each vertex as a point
while it draws the polygon. We listed points as we clicked on them. This is the same, but with the program generating the points.polygon
block.polygon
block.add
here. --MF, 3/25/19 Maybe it's a reminder that they're using lists? -bhpolygon
and in the script that draws the design, so I'd make it global so multiple scripts can access it.polygon
and in the script that draws the design, so I'd make it global so multiple scripts can access it.Yes, but isn't this referring to the line segments inside, which are diagonals? --MF, 5/31/19
for each
to connect just that one to each other vertex. After that, it's easy! We can use that block on each vertex.for each
to connect just that one to each other vertex. After that, it's easy! We can use that block on each vertex.polygon
block store each vertex as a point
while it draws the polygon. We listed points as we clicked on them. This is the same, but with the program generating the points.polygon
block store each vertex as a point
while it draws the polygon. We listed points as we clicked on them. This is the same, but with the program generating the points.polygon
block.polygon
block.add
here. --MF, 3/25/19 Maybe it's a reminder that they're using lists? -bhpolygon
and in the script that draws the design, so I'd make it global so multiple scripts can access it.polygon
and in the script that draws the design, so I'd make it global so multiple scripts can access it.Yes, but isn't this referring to the line segments inside, which are diagonals? --MF, 5/31/19
for each
to connect just that one to each other vertex. After that, it's easy! We can use that block on each vertex.for each
to connect just that one to each other vertex. After that, it's easy! We can use that block on each vertex.elemento de prueba
tipo de dato abstracto para almacenar las preguntas y respuestas en una lista de elementos de prueba. Aquí, podemos crear un tipo de dato abstracto contacto
para almacenar los datos de cada contacto en nuestra lista de contactos.contacto
y luego selectores para acceder al nombre
, dirección
y número de teléfono
para cualquier contacto dado.elemento de prueba
tipo de dato abstracto para almacenar las preguntas y respuestas en una lista de elementos de prueba. Aquí, podemos crear un tipo de dato abstracto contacto
para almacenar los datos de cada contacto en nuestra lista de contactos.contacto
y luego selectores para acceder al nombre
, dirección
y número de teléfono
para cualquier contacto dado.contacto
constructor que acepte tres datos como entrada: el nombre del contacto, el número de teléfono y la dirección.nombre del contacto
, dirección del contacto
o teléfono del contacto
. nombre
, dirección
o teléfono
de un contacto de tu lista.quiz item
abstract data type to store the questions and answers in a list of quiz items. Here, we can make a contact
abstract data type to store the data for each contact in our list of contacts.contact
constructor and then selectors to access the name
, address
, and phone number
for any given contact.quiz item
abstract data type to store the questions and answers in a list of quiz items. Here, we can make a contact
abstract data type to store the data for each contact in our list of contacts.contact
constructor and then selectors to access the name
, address
, and phone number
for any given contact.name
, address
, or phone
from a contact in your list- En esta actividad, refinarás el manejo de nombres de personas. Cuando buscas a una persona en particular, necesitar ver su nombre igual que lo has hecho en esta página, primero el nombre: "Alphie Preston". Pero supongamos que quieres ordenar tus contactos. Por lo general, eso lo hace el apellido, por lo que la lista sería algo así como + En esta actividad, refinarás el manejo de nombres de personas. Cuando buscas a una persona en particular, necesitar ver su nombre igual que lo has hecho en esta página, primero el nombre: "Morgan Preston". Pero supongamos que quieres ordenar tus contactos. Por lo general, eso lo hace el apellido, por lo que la lista sería algo así como
contacto con nombre
. Este es un tipo de dato abstracto (nombre) dentro de otro tipo de dato abstracto (contacto).nombre de contacto
ahora reportará una lista, tal y como debería. Pero algunas otras partes del programa, como la parte que muestra un contacto al usuario, necesitan mostrar el nombre como una cadena de texto: "Betsy Anderson". La parte que ordena la lista de contactos también quiere una cadena: "Anderson, Betsy". Escribe dos bloques y que unan las dos partes del nombre con un espacio y/o una coma según sea necesario.nombre de contacto
ahora reportará una lista, tal y como debería. Pero algunas otras partes del programa, como la parte que muestra un contacto al usuario, necesitan mostrar el nombre como una cadena de texto: "Jasmine Anderson". La parte que ordena la lista de contactos también quiere una cadena: "Anderson, Jasmine". Escribe dos bloques y que unan las dos partes del nombre con un espacio y/o una coma según sea necesario.Guarda tu trabajo. En la página 4, encontrarás un contacto al permitir que el usuario ingrese cualquier parte del nombre y muestre el contacto completo. Usa la abstracción de nombre que acabas de crear cuando hagas eso.
diff --git a/cur/programming/3-lists/2-contact-list/2-adding-contact.html b/cur/programming/3-lists/2-contact-list/2-adding-contact.html index a191a5840b..af49e544d2 100644 --- a/cur/programming/3-lists/2-contact-list/2-adding-contact.html +++ b/cur/programming/3-lists/2-contact-list/2-adding-contact.html @@ -75,17 +75,17 @@- In this activity, you're going to refine the handling of people's names. When you look up a particular person, you want to see their name as you've been seeing it on this page, first name first: "Alphie Preston." But suppose you want to sort your contacts. Typically that's done by last name, so the list would look something like + In this activity, you're going to refine the handling of people's names. When you look up a particular person, you want to see their name as you've been seeing it on this page, first name first: "Morgan Preston." But suppose you want to sort your contacts. Typically that's done by last name, so the list would look something like
contact with name
block. This is an abstract data type (name) inside another abstract data type (contact).name from contact
block will now report a list, as it should. But some other parts of the program, such as the part that displays a contact to the user, want to display the name as a text string: "Betsy Anderson." The part that sorts the contact list also wants a string: "Anderson, Betsy." Write two blocks and that join the two parts of the name with a space and/or a comma as needed.name from contact
block will now report a list, as it should. But some other parts of the program, such as the part that displays a contact to the user, want to display the name as a text string: "Jasmine Anderson." The part that sorts the contact list also wants a string: "Anderson, Jasmine." Write two blocks and that join the two parts of the name with a space and/or a comma as needed.Save your work. On page 4 you're going to find a contact by letting the user enter any part of the name, and display the entire contact. Use the name abstraction you've just created when you do that.
diff --git a/cur/programming/3-lists/2-contact-list/4-looking-up-data.es.html b/cur/programming/3-lists/2-contact-list/4-looking-up-data.es.html index afb965e8dc..2dbedaacdf 100644 --- a/cur/programming/3-lists/2-contact-list/4-looking-up-data.es.html +++ b/cur/programming/3-lists/2-contact-list/4-looking-up-data.es.html @@ -96,7 +96,7 @@nombre
) debe saber si es un nombre de pila, como Betsy Anderson, o un apellido, como como Sun Yat-Sen. Redefine tu tipo de dato abstracto de nombre para convertirlo en una lista de tres elementos. El primero será el texto 'nombre de pila primero' o 'apellido primero'. Este primer elemento se denomina etiqueta de tipo . El segundo elemento será el nombre (o nombres) de pila y el tercero será el apellido (o apellidos).
+ Esta es la parte complicada: para que todo funcione correctamente, un nombre (según lo define el tipo de dato abstracto de nombre
) debe saber si es un nombre de pila, como Jasmine Anderson, o un apellido, como como Sun Yat-Sen. Redefine tu tipo de dato abstracto de nombre para convertirlo en una lista de tres elementos. El primero será el texto 'nombre de pila primero' o 'apellido primero'. Este primer elemento se denomina etiqueta de tipo . El segundo elemento será el nombre (o nombres) de pila y el tercero será el apellido (o apellidos).
name
ADT) has to know whether it's a given-first name such as Betsy Anderson or a family-first name such as Sun Yat-Sen. Redefine your Name ADT to make it a list of three items. The first will be either the text 'given-first' or 'family-first'. This first item is called a type tag. The second item will be the given name (or names), and the third will be the family name (or names).
+ Here's the tricky part: To make this all work correctly, a name (as defined by the name
ADT) has to know whether it's a given-first name such as Jasmine Anderson or a family-first name such as Sun Yat-Sen. Redefine your Name ADT to make it a list of three items. The first will be either the text 'given-first' or 'family-first'. This first item is called a type tag. The second item will be the given name (or names), and the third will be the family name (or names).
iniciales del nombre
que acepta un contacto como entrada y reporta las iniciales de esa persona.iniciales del nombre
que acepta un contacto como entrada y reporta las iniciales de esa persona.letra (1) de (elemento (3) de (lista de nombres))
. letra (1) de
cada elemento en la lista de nombres. Eso suena como si lo que necesitáramos fuera una función de orden superior. Las funciones de orden superior son buenas para hacer cosas con elementos individuales de una lista.letra (1) de (elemento (3) de (lista de nombres))
. letra (1) de
cada elemento en la lista de nombres. Eso suena como si lo que necesitáramos fuera una función de orden superior. Las funciones de orden superior son buenas para hacer cosas con elementos individuales de una lista.Una función de orden superior (higher-order function) es una función que toma una función como entrada (o reporta una función como salida).
Primero, crea una expresión para reportar una lista de los nombres de todos tus contactos.
- →
+ →
initials from name
block that accepts one contact as input and reports that person's initials.initials from name
block that accepts one contact as input and reports that person's initials.letter (1) of (item (3) of (list of names))
. letter (1) of
each item in the list of names. That sounds as if what we need is a higher-order function. Higher-order functions are good at doing things with individual items in a list.letter (1) of (item (3) of (list of names))
. letter (1) of
each item in the list of names. That sounds as if what we need is a higher-order function. Higher-order functions are good at doing things with individual items in a list.A higher-order function is a function that takes a function as input (or reports a function as output).
for
.for
.countdown (5)
to report the list {5, 4, 3, 2, 1}. But countdown (4)
is {4, 3, 2, 1}, so all you have to do is stick a 5 in front:countdown (5)
to report the list {5, 4, 3, 2, 1}. But countdown (4)
is {4, 3, 2, 1}, so all you have to do is stick a 5 in front:if
in his code. What would happen if he left that part out? Why?if
in his code. What would happen if he left that part out? Why?name
ADT and two new selectors: one to report the name they way it appears for the user: first-name last-name; and one to report the name so we can sort it: last-name comma first-name.name
ADT and two new selectors: one to report the name they way it appears for the user: first-name last-name; and one to report the name so we can sort it: last-name comma first-name.sorting form of name
block together with their contact
constructor. They were expecting their code to report "Anderson, Betsy", but it didn't work.sorting form of name
block together with their contact
constructor. They were expecting their code to report "Anderson, Jasmine", but it didn't work.name
types, with different constructors and selectors?name
type, but it'll have variants, and we'll include a type tag along with the given and family parts to indicate given-first (as in the US) or family-first (as in China). Gamal can add more variants later if he wants.name
types, with different constructors and selectors?name
type, but it'll have variants, and we'll include a type tag along with the given and family parts to indicate given-first (as in the US) or family-first (as in China). Omar can add more variants later if he wants.type from name
. We're going to need the same type selector for other ADTs also, so call it type tag
.type from name
. We're going to need the same type selector for other ADTs also, so call it type tag
.i
is 1, the sprite glides to (item 1 of item 1, item 2 of item 1). Then when i
is 2, the sprite glides to (item 1 of item 2, item 2 of item 2. And then it goes to the third and fouth points too.for each
instead of for
...for each
instead of for
...for each
.for each
.Unlike, for example, a video game or an art project, a contact list app is all about data. In this lab as a whole, you'll create a contact
abstract data type, with components such as name
, address
, phone
, birthday
, and so on, much as in Unit 2 Lab 2: Checking Each Quiz Answer where you created a quiz item
ADT. But in this case, each component of a contact
will itself be an ADT. On this page you'll start with names.
name
has to be an ADT, but I don't see why. Isn't a name just a text string? "Alphie North." "Betsy
- Davies." "Sir James Paul McCartney."name
has to be an ADT, but I don't see why. Isn't a name just a text string? "Morgan Preston." "Jasmine
+ Williams." "Sir James Paul McCartney."name
data type made out of a
+ Morgan: So are you saying we should have a name
data type made out of a
first name
and a last name
? Then it'd look just like what we did for point
:name
types, with different constructors and selectors?name
type, but it'll have variants, and we'll include a type tag in with the given and family parts to indicate given-first (as in the US) or family-first (as in China). Gamal can add more variants later if he wants.name
types, with different constructors and selectors?name
type, but it'll have variants, and we'll include a type tag in with the given and family parts to indicate given-first (as in the US) or family-first (as in China). Omar can add more variants later if he wants.name type
. We're going to need the same type selector for other ADTs also, so call it type tag
.name type
. We're going to need the same type selector for other ADTs also, so call it type tag
.Unlike, for example, a video game or an art project, a contact list app is all about data. In this lab as a whole, you'll create a contact
abstract data type, with components such as name
, address
, phone
, birthday
, and so on, much as in Unit 2 Lab 2: Checking Each Quiz Answer where you created a quiz item
ADT. But in this case, each component of a contact
will itself be an ADT. On this page you'll start with names.
name
has to be an ADT, but I don't see why. Isn't a name just a text string? "Alphie North." "Betsy
- Davies." "Sir James Paul McCartney."name
has to be an ADT, but I don't see why. Isn't a name just a text string? "Morgan Preston." "Jasmine
+ Williams." "Sir James Paul McCartney."name
data type made out of a
+ Morgan: So are you saying we should have a name
data type made out of a
first name
and a last name
? Then it'd look just like what we did for point
:name
types, with different constructors and selectors?name
type, but it'll have variants, and we'll include a type tag in with the given and family parts to indicate given-first (as in the US) or family-first (as in China). Gamal can add more variants later if he wants.name
types, with different constructors and selectors?name
type, but it'll have variants, and we'll include a type tag in with the given and family parts to indicate given-first (as in the US) or family-first (as in China). Omar can add more variants later if he wants.name type
. We're going to need the same type selector for other ADTs also, so call it type tag
.name type
. We're going to need the same type selector for other ADTs also, so call it type tag
.Map
for Algebraic Functionsmap
to compute some function of every item of a list:map
to compute some function of every item of a list:plural
with words. But let's try to put the function f in there. First I need to build f. Here you go:plural
with words. But let's try to put the function f in there. First I need to build f. Here you go:Map
for Algebraic Functionsjoin
.true
or false
.Alphie and Betty discuss using keep
:
Morgan and Betty discuss using keep
:
keep
works. Which states do we want to keep?keep
works. Which states do we want to keep?states
. And letter 1 of the word needs to be the same as the last letter of the word.states
. And letter 1 of the word needs to be the same as the last letter of the word.states
goes in the empty spaces. So, let's try an example. I'll pick a state... "new york". Letter 1 of "new york" is "n".states
goes in the empty spaces. So, let's try an example. I'll pick a state... "new york". Letter 1 of "new york" is "n".length of
"new york" is 8, and letter 8 of
"new york" is "k". The condition is false because "n" doesn't equal "k". So "new york" doesn't show up in the list. We'll keep only the states that have the same first and last letter.map
block applies some function to each item of a list.map
block applies some function to each item of a list.keep
block lets you choose some items from a list and not others.combine with
takes an operation (like +
) and a list. It combines all the items of the list into a single output using the operation. So, with +
, it would give the sum of all the numebrs in the list.combine with
takes an operation (like +
) and a list. It combines all the items of the list into a single output using the operation. So, with +
, it would give the sum of all the numebrs in the list.keep
the ones that were greater than 50, use map
to add 10 to all of them, and then use combine with
to add those new numbers up.keep
the ones that were greater than 50, use map
to add 10 to all of them, and then use combine with
to add those new numbers up.keep
the numbers over 50.map
. And the list we're mapping over is everything over 50 that we kept, so let's just drag everything in our keep
expression in there.map
. And the list we're mapping over is everything over 50 that we kept, so let's just drag everything in our keep
expression in there.combine with
and addition, and our list is everything in the map
expression.combine with
and map
, too. combine with
and map
, too. for each
loop. For each item in the list, we compare it to... what? for each
loop. For each item in the list, we compare it to... what? increasing?
is a convention for naming predicates (blocks that report either true-or-false).position in sorted list
and the number guesser algorithm should have the same overall structure.
+ position in sorted list
and the number guesser algorithm should have the same overall structure.
Una prueba por contradicción (proof by contradition) es una prueba de dos pasos para saber si algo es falso que se realiza: @@ -59,11 +59,11 @@
A proof by contradiction is a two-step proof that a statement is false, which is done by @@ -59,11 +59,11 @@
En esta página, considerarás un problema que no puede tener una respuesta.
En este punto del curso, has experimentado la frustración de depurar un programa. Sería genial si hubiera un programa de depuración de propósito general que pudiera leer cualquier código y determinar si había errores. Desafortunadamente, podemos usar prueba por contradicción (como hicieron Alphie, Betsy y Gamal en la página anterior) para demostrar que esto no se puede hacer.
+En este punto del curso, has experimentado la frustración de depurar un programa. Sería genial si hubiera un programa de depuración de propósito general que pudiera leer cualquier código y determinar si había errores. Desafortunadamente, podemos usar prueba por contradicción (como hicieron Morgan, Jasmine y Omar en la página anterior) para demostrar que esto no se puede hacer.
Primero, asumiremos que es posible escribir una función para determinar si hay bucles infinitos en un programa (situaciones en las que una función se ejecuta para siempre sin devolver un valor). Luego, utilizaremos esa función en un programa especialmente diseñado para crear una contradicción (una incompatibilidad lógica) para demostrar que la suposición es incorrecta—no puede existir un programa de depuración de uso general. "Este programa tiene errores" es un problema indecidible; nunca se puede construir un algoritmo que siempre lo resuelva correctamente para cada programa.
Un bucle infinito (infinite loop) es una secuencia de instrucciones de computadora que se repite para siempre.
@@ -98,7 +98,7 @@¿detener?
El bloque por siempre
en este script crea un bucle infinito. Si el código de prueba
termina en esta parte de la declaración si
, nunca reportara nada. Entonces, entonces si prueba
se detendrá el mismo depende de la salida del predicado ¿detener?
en la declaración si
dentro de él.
La expresion pregunta qué sucederá si llamamos a la función de entrada (reportar) con el mismo como su propia entrada. Esto es similar a cuando Betsy hizo una declaración sobre la declaración que estaba haciendo, cuando dijo: "La declaración que estoy haciendo en este momento es falsa".
+La expresion pregunta qué sucederá si llamamos a la función de entrada (reportar) con el mismo como su propia entrada. Esto es similar a cuando Jasmine hizo una declaración sobre la declaración que estaba haciendo, cuando dijo: "La declaración que estoy haciendo en este momento es falsa".
¿detener?
- Para hacer que la situación sea exactamente como lo que dijo Betsy ("La declaración que estoy haciendo en este momento es falsa"), llamaremos a prueba
dentro de sí mismo:
+ Para hacer que la situación sea exactamente como lo que dijo Jasmine ("La declaración que estoy haciendo en este momento es falsa"), llamaremos a prueba
dentro de sí mismo:
Ahora, la instrucción si
dentro del bloque prueba
preguntará si prueba
se detendrá (no se ejecutará para siempre) si se llama con prueba
como su entrada. El predicado en la instrucción si
se convertirá en ¿detener? (prueba) (prueba)
.
On this page, you will consider a problem that can't have an answer.
By this point in the course, you've experienced the frustration of debugging a program. It would be great if there were a general-purpose debugging program that could read any code and determine if there were bugs. Unfortunately, we can use proof by contradiction (as Alphie, Betsy, and Gamal did on the previous page) to prove that this can't be done.
+By this point in the course, you've experienced the frustration of debugging a program. It would be great if there were a general-purpose debugging program that could read any code and determine if there were bugs. Unfortunately, we can use proof by contradiction (as Morgan, Jasmine, and Omar did on the previous page) to prove that this can't be done.
First, we'll assume that it's possible to write a function to determine if there are infinite loops in a program (situations in which a function runs forever without reporting a value). Then, we'll use that function in a program especially designed to create a contradiction (a logical incompatibility) to prove that the assumption is wrong—no general-purpose debugging program can exist. "Does this program have bugs" is an undecidable problem; no algorithm can ever be constructed that always solves it correctly for every program.
An infinite loop is a sequence of computer instructions that repeats forever.
@@ -98,7 +98,7 @@Halts?
Won't
The forever
block in this script creates an infinite loop. If the tester
code ends up in this part of the if
statement, it will never report anything. So whether tester
itself will halt depends on the output of the halts?
predicate in the if
statement inside it.
The expression asks what will happen if we call the input function (reporter) with itself as its own input. This is similar to when Betsy made a statement about the statement she was making, when she said, "The statement I'm making right now is false."
+The expression asks what will happen if we call the input function (reporter) with itself as its own input. This is similar to when Jasmine made a statement about the statement she was making, when she said, "The statement I'm making right now is false."
Halts?
Won't
- To make the situation exactly like what Betsy said ("The statement I'm making right now is false."), we'll call tester
on itself:
+ To make the situation exactly like what Jasmine said ("The statement I'm making right now is false."), we'll call tester
on itself:
Now, the if
statement inside the tester
block will ask if tester
will halt (not run forever) if it's called with tester
as its input. The predicate in the if
statement will become halts? (tester) (tester)
.
repeat until
in it, and when it was finished, it'd give me some answer I wanted. Is there some way I could just analyze the code without actually running it, to determine if it would ever stop? repeat until
in it, and when it was finished, it'd give me some answer I wanted. Is there some way I could just analyze the code without actually running it, to determine if it would ever stop? combine
to add up the list.combine
to add up the list.for
loop to build the power of 2, then I subtracted 1 at the end:for
loop to build the power of 2, then I subtracted 1 at the end:report
block sends the final value. I put the last math operation there.tree
.tree
. We used recursion. We built a segment, turned, called tree
to build a smaller tree, turned again, and then called tree
again to build another, smaller tree.segments in tree
reporter recursively. But we can ignore all the moving and turning parts, right? Let me give this a shot. report
block sends the final value. I put the last math operation there.tree
.tree
. We used recursion. We built a segment, turned, called tree
to build a smaller tree, turned again, and then called tree
again to build another, smaller tree.segments in tree
reporter recursively. But we can ignore all the moving and turning parts, right? Let me give this a shot. You've built and worked with recursive command blocks. Recursion can also be used in reporters.
@@ -93,7 +93,7 @@Here's Betsy's code for the segments in tree
function:
Here's Jasmine's code for the segments in tree
function:
report
block only connects to the blocks above it. That's because report
returns the result of its input slot, immediately, as the output of the segments in tree
reporter block. No further code is executed in a reporter after a report
block.Pascal's Triangle is named (among Europeans and their cultural descendents) after the mathematician Blaise Pascal, who published a detailed study of the triangle in 1653, although the earliest surviving reference to the triangle comes from the Hindu mathematician Pingala, who lived some time around the 4th to 2nd century BCE.
Pascal's Triangle is named (among Europeans and their cultural descendents) after the mathematician Blaise Pascal, who published a detailed study of the triangle in 1653, although the earliest surviving reference to the triangle comes from the Hindu mathematician Pingala, who lived some time around the 4th to 2nd century BCE.
item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:for each
to traverse the list.
+ Jasmine: Yeah, we could, but that's a little hard to read with that index variable, i, to keep track of. And if we add more questions, we'll have to update that number 4 that tells us when to end the loop. I bet we can use for each
to traverse the list.
for each
into the scripting area.for each
into the scripting area.item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:for each
to traverse the list.
+ Jasmine: Yeah, we could, but that's a little hard to read with that index variable, i, to keep track of. And if we add more questions, we'll have to update that number 4 that tells us when to end the loop. I bet we can use for each
to traverse the list.
for each
into the scripting area.for each
into the scripting area.go to point
script. Only after the letter is mostly being drawn correctly should they tackle the two bugs, one at the beginning and one at the end of the drawing process.student record
constructor—a reporter block that, given a name (a text string) and grade (a number) as input, reports a student record (a list of that name and grade).name
and grade
that, given a student record as input, report the name or grade for that student record.for each
. Later in this unit, you'll see how to produce AA with a lot less trouble, using map
. list from
as one step, but note that the creation of a list is a linear-time function, so an algorithm that contains it can be (at best) linear time. The algorithm used by the list from
block is a simple recursion. If students dig into it, follow along, it will give a good preview to what will happen in Units 6 and 7.list from
as one step, but note that the creation of a list is a linear-time function, so an algorithm that contains it can be (at best) linear time. The algorithm used by the list from
block is a simple recursion. If students dig into it, follow along, it will give a good preview to what will happen in Units 6 and 7.