Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
teaching:cc4101:tareas:2021-1:tarea1 [2021/04/20 13:22] etanterteaching:cc4101:tareas:2021-1:tarea1 [2021/05/10 14:34] (current) – P3, add '}' on first example bortiz
Line 76: Line 76:
 **Instrucciones importantes**: **Instrucciones importantes**:
   * Para implementar el lenguaje, tiene que [[https://users.dcc.uchile.cl/~etanter/play-interps/Functions_with_Environments.html|usar ambientes]], y no una función de substitución.   * Para implementar el lenguaje, tiene que [[https://users.dcc.uchile.cl/~etanter/play-interps/Functions_with_Environments.html|usar ambientes]], y no una función de substitución.
 +  * Tienen que verificar que los argumentos de los operadores booleanos sean booleanos (eso para alinear la verificación dinámica con la verificación estática que harán en la parte 2)
   * En caso de programas con errores dinámicos, su interprete tiene que reportarlos explícitamente. Por ejemplo:   * En caso de programas con errores dinámicos, su interprete tiene que reportarlos explícitamente. Por ejemplo:
  
Line 81: Line 82:
 debe caerse en tiempo de ejecución con un error (se levantan con ''(error msg)'', tal como lo hacemos en clase con los identificadores libres) debe caerse en tiempo de ejecución con un error (se levantan con ''(error msg)'', tal como lo hacemos en clase con los identificadores libres)
 <code scheme>"Runtime type error: expected Number found Boolean"</code> <code scheme>"Runtime type error: expected Number found Boolean"</code>
 +Recuerde que puede testear estos errores con ''test/exn''.
  
  
Line 118: Line 120:
  {id 5}}  {id 5}}
  
-{{define {add1 {x : Num}} {+ x 1}}+{{define {add2 {x : Num}} {+ x 2}}
  {with {{oops #f}}  {with {{oops #f}}
-   {add1 oops}}}+   {add2 oops}}}
 </code> </code>
  
Line 137: Line 139:
  
 Para los errores: Para los errores:
-  * Los errores de identificadores libres se tienen que detectar estáticamente, antes o durante la verificación de tipos.+  * Los errores de identificadores libres (o funciones no definidas) se tienen que detectar estáticamente, antes o durante la verificación de tipos.
   * Los mensajes de error de tipo detectados estáticamente tienen que seguir el siguiente patrón:    * Los mensajes de error de tipo detectados estáticamente tienen que seguir el siguiente patrón: 
 <code scheme>"Static type error: expected T1 found T2"</code> donde ''T1'' es el tipo esperado y ''T2'' el tipo encontrado. <code scheme>"Static type error: expected T1 found T2"</code> donde ''T1'' es el tipo esperado y ''T2'' el tipo encontrado.
Line 147: Line 149:
   > (typecheck '{{define {f {p : Bool}} {&& p {! p}}}   > (typecheck '{{define {f {p : Bool}} {&& p {! p}}}
                           {f {> 3 4}}})                           {f {> 3 4}}})
-  'Bool </code> <code scheme>   +  'Any </code> <code scheme>   
   > (typecheck '{{define {one {x : Num}} 1}   > (typecheck '{{define {one {x : Num}} 1}
                           {one #t}})                           {one #t}})
   "Static type error: expected Num found Bool" </code> <code scheme>   "Static type error: expected Num found Bool" </code> <code scheme>
-  > (typecheck '{> 10 #t})+  > (typecheck '{{> 10 #t}})
   "Static type error: expected Num found Bool"</code> <code scheme>   "Static type error: expected Num found Bool"</code> <code scheme>
-   > (typecheck '{if 73 #t #t})+   > (typecheck '{{if 73 #t #t}})
   "Static type error: expected Bool found Num"</code> <code scheme>   "Static type error: expected Bool found Num"</code> <code scheme>
-  > (typecheck '{with {{x 5} {y : Num #t} {z 42}} +  > (typecheck '{{with {{x 5} {y : Num #t} {z 42}} 
-                            z})+                            z}})
   "Static type error: expected Num found Bool"</code>   "Static type error: expected Num found Bool"</code>
  
Line 203: Line 205:
  {define {positive x} : Bool {> x 0}}  {define {positive x} : Bool {> x 0}}
  {define {percentage? x} : Bool {&& {lt100 x} {positive x}}}  {define {percentage? x} : Bool {&& {lt100 x} {positive x}}}
- {define {calc {x @ positive} {y @ percentage?}+ {define {calc {x @ positive} {y @ percentage?}}
            {/ {* y y} x}}            {/ {* y y} x}}
  {calc 25 3}}  {calc 25 3}}