Super

Páginas: 2 (376 palabras) Publicado: 1 de junio de 2011
Mozart Clase 1

Pag. 46 A calculator
{Browse 9999*9999}

Ejecutar un programa desde teclado: (Control Punto b) Ctrl. . b Ejecuta el bufer.
Ctrl. . r Ejecuta la region.Ctrl. . l Ejecuta la línea.

Para pegar en el editor algo copiado: presionar el boton medio del mouse

Pag. 47 Variables

declare
V=5

{Browse V * V}[pic]

Pag. 47 Functions and recursion

declare
fun {Factorial N}
if N==0 then 1 else N*{Factorial N-1} end
end

{Browse {Factorial 3}}

Pag. 49 Combinations

declare
fun{Combinatorial N R}
{Factorial N} div ({Factorial R}*{Factorial N-R})
end

{Browse {Combinatorial 10 3}}

Pag. 49 Lists

A list is just a sequence of elements, bracketed at the left and right,
like [5 67 8]. For historical reasons, the empty list is written nil (and not []). Lists can be displayed just like numbers:

{Browse [5 6 7 8]} muestra [5 6 7 8]
{Browse [5 6 7 8].1} muestra 5 (Alponer .1 al final muestra la cabeza)
{Browse [5 6 7 8].2} muestra [6 7 8] (Al poner .2 al final muestra la cola)

Ejs:

declare
Cabeza=5
Cola=[6 7 8]
L=Cabeza|Cola
{Browse L}

declareLista=[5 6 7 8]
{Browse Lista.1}
{Browse Lista.2}

Pag. 51 Pattern matching
A more compact way to take apart a list is by using the case instruction, which
gets both head and tail in one step:declare
Lista=[5 6 7 8]
case L of Cabeza|Cola then {Browse Cabeza} {Browse Cola} end

This displays 5 and [6 7 8]

Pag. 52 Functions over lists

Now that we can calculate with lists, let usdefine a function, {Pascal N}, to
calculate the nth row of Pascal’s triangle.

[pic]

declare Pascal AddList ShiftLeft ShiftRight
fun {Pascal N}
if N==1 then [1]
else{AddList {ShiftLeft {Pascal N-1}}
{ShiftRight {Pascal N-1}}}
end
end

fun {ShiftLeft L}
case L of H|T then
H|{ShiftLeft T}
else [0] end...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Super Yo
  • Super
  • super
  • El Super Yo
  • Super
  • supoer yo
  • super yo
  • supeer

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS