Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
. b add:1; yourself. b at:1 put:2; yourself. a at:1 put:'hola'; yourself. a at:5. a at:1. b add:5; add:3; add:5; add:1;add:2; yourself. b reverseDo: [:x| Transcript show: (x asString)]. a at:1 put:3; add:5;yourself. b removeAll:a; yourself. b remove:2; yourself. b at:1 put:3; add:5; add:2; add:9; add:5;yourself. b remove:6 ifAbsent:['Error, el elemento no existe']. b includes:5. b includes:6. b occurrencesOf:5. b isEmpty. b last. b first. b indexOf:5. b indexOf:8 ifAbsent:['No se encuentra el valor']. b removeAll:a;yourself. Concatenacion de colecciones c:=(a,b). c yourself. (a,#(1 2 3)) yourself. c add:4 after:3; yourself. c add:2 before:3; yourself. c removeLast; yourself. c removeFirst; yourself. c findFirst:[:x| x odd]. c findLast:[:x| x even]. c addFirst:0; yourself. c size. Otras instrucciones do:1:, reverseDo:1, collect:, select:, reject:, detect:, detect:ifNone:, inject:inTo: ,reverse:1
1
Referencia a... b
Comentario
(1 )
Error. Fuera de lmites de la coleccion (1 ) (2 ) (hola ) 'hola' OrderedCollection(2 5 3 5 1 2) En la ventana Transcript se obtiene: 215352. 'Transcript show' recibe un string (3 5 ) (2 5 1 2) (5 1 2) (3 1 2 5 2 9 5 ) OrderedCollection(3 5 ) OrderedCollection(2 5 1 2) OrderedCollection(5 1 2 ) OrderedCollection(3 1 2 5 2 9 5 ) 'Error, el elemento no existe' true false 2 false 5 3 4 (1 2 2 9 5 ) (3 5 1 2 2 9 5 ) (3 4 5 1 2 2 9 5 ) (2 3 4 5 1 2 2 9 5 ) (2 3 4 5 1 2 2 9 ) (3 4 5 1 2 2 9 ) 'No se encuentra el valor' OrderedCollection(1 2 2 9 5 ) OrderedCollection(3 5 1 2 2 9 5 ) Error. Las colecciones deben ser de la misma clase OrderedCollection(3 4 5 1 2 2 9 5 ) OrderedCollection(2 3 4 5 1 2 2 9 5 ) OrderedCollection(2 3 4 5 1 2 2 9 ) OrderedCollection(3 4 5 1 2 2 9 ) 1 6 OrderedCollection(0 3 4 5 1 2 2 9 ) 8 Da error si al menos un objeto de a no existe en b Borra la primera ocurrencia OrderedCollection(1 ) OrderedCollection(2 ) OrderedCollection('hola' ) Error. Fuera de lmites. a tiene slo 1 elemento. (2 5 3 5 1 2)
Indice del elemento que se pasa como argumento. Si no existe el argumento, da error
Es el ndice del primer elemento que devuelve true . Odd=impar Es el ndice del ltimo elemento que devuelve true. Even=par
(0 3 4 5 1 2 2 9 )
SMALLTALK Cartilla de instrucciones usuales Array Ins truccin |a b| a:= Array new. a:= Array new:5. a add:4. a at:2 put:5; at:5 put:3. a at:7 put:2. a indexOf:5. a indexOf:12 ifAbsent:['No se encuentra el valor']. a last. a first. #(nil nil nil) isEmpty. b:= Array new:5. b isEmpty. b:= Array new isEmpty. a includes:3. a occurrencesOf:nil. b:=(#(1 2 3),a) yourself. a size. Referencia a... a (nil nil nil nil nil) (nil 5 nil nil 3) b Devuelve Comentario
Crea un array de tamao cero. No sirve a los fines prcticos (nil nil nil nil nil) Error. No se puede hacer add: 3 2 'No se encuentra el valor' 3 nil false false true true 3 (1 2 3 nil 5 nil nil 3) 5 Error. No se puede insertar fuera de rango Devuelve el indice del argumento
removeFirst. removeLast No funcionan para Array. Tampoco findFirst ni findLast Dictionary Instruccin |a b temp| a:=Dictionary new. a at:4 put:'Cuatro'; yourself. a at:4 put:'cuatro'; yourself. a at:2 put:'dos'; at:10 put:'diez'; at:5 put:'hola'; yourself. b:=Association key:3 value:tres a add:b. a keyAtValue:'hola'. a keyAtValue:'ala' ifAbsent:['No se encuentra el valor']. a includesKey:1 a removeKey:4; yourself. temp:=OrderedCollection new. a keysDo:[:x| temp add:(a at:x)]. temp yourself. a keys yourself. a values. a size. includesAssociation: y removeAssociation: no funcionan en SmallTalk V. 2 ('tres' 'hola' 'diez' 'dos' ) ('hola' 'tres' 'diez' 'dos' ) ('tres' 'hola' 'cuatro' 'diez' 'dos' ) Referencia a... b Devuelve Comentario Asociaciones: 4 Cuatro Asociaciones: 4 cuatro Asociaciones: 4 cuatro 2 dos 10 diez 5 hola Asociaciones: 3 tres 4 cuatro 2 dos 10 diez 5 hola
Temp
Dictionary('Cuatro' ) Dictionary('Cuatro' ) Dictionary('hola' 'cuatro' 'diez' 'dos' ) 3 ==> 'tres' 3 ==> 'tres' 3 ==> 'tres' 5 'No se encuentra el valor' false Dictionary('hola' 'tres' 'diez' 'dos' ) OrderedCollection() OrderedCollection('hola' 'tres' 'diez' 'dos' ) Set(5 2 3 10 ) Bag('hola' 'dos' 'tres' 'diez' ) 4
SMALLTALK Cartilla de instrucciones usuales Bag Instruccin |a| a:=Bag new. a add:7;add:2;add:2;add:5;yourself. a remove:2;yourself. a size. a Devuelve String Instruccin |abc| a:='HoLa'. b:='cAcHo'. c:='asUpperCase'. (a,' ',b) yourself. a asUpperCase. b asLowerCase. a asSymbol. b perform: (c asSymbol). a size. a at:2. a:=a at:2 put:$z; yourself. Character Instruccin Character value:65. $a isDigit. $a isLetter. $a isUpperCase. $A asciiValue. $A asLowerCase. Magnitude Instruccin |a b| a:=3. b:=7. a max:b. a min:b. 7 \\ 3 . 4.5 \\ 2. 4.5 \\ 7 7 // 3. 4.5 // 2. 2 raisedTo:3. -6 abs. 16 sqrt. 5.5 truncated. 2.3 rounded. Referencia a... a b 3 7 Devuelve 3 7 7 3 1 0 4 2 2 8.0 6 4.0 5 2 Comentario Integer Instruccin 3 factorial. 16 gcd: 12. 3 lcm:5. 4 asFloat. 65 asCharacter. 5 radix:2. Fraction (7/3) asFloat. (7/3) denominator. (7/3) numerator. 2.33333333 3 7 Devuelve 6 4 15 4.0 $A '2r101' Comentario $A false true false 65 $a Devuelve a 'HoLa' 'cAcHo' 'asUpperCase' Referencia a... b c Devuelve 'HoLa' 'cAcHo' 'asUpperCase' 'HoLa cAcHo' 'HOLA' 'cacho' HoLa 'CACHO' 4 $o 'HzLa'
Comentario
'HzLa'
Mximo Mnimo Resto (mdulo) Resto (mdulo). 4.5 es Float Resto (mdulo) Divisin entera Divisin entera Potencia Valor Absoluto Raz cuadrada Parte entera
SMALLTALK Cartilla de instrucciones usuales Object Instruccin |a b| 3 class. 'hola' isKindOf:Collection. 'hola' isMemberOf:Collection. 'hola' isKindOf:String. 'hola' isMemberOf:String. #(1 4) respondsTo:#at: a:='hola'. b:=a. b at:2 put:$O. a yourself. b:=a shallowCopy. b at:1 put:$H. a yourself. b:=a deepCopy. b at:4 put:$A. a yourself. b=a. b==a b~=a b~~a. b:=a copy. b at:1 put:$Z. a yourself. hOla hOla Zola Referencia a... a b SmallInteger true false true true true hola $O hOla hOla $H hOla $A hOla true false true true true con cualquiera de las copias true (not igualdad) true (not equivalencia) Devuelve Comentario
Para verificar si un objeto responde a un mensaje. Dos variables apuntando al mismo objeto (equivalencia)
hOla
$Z hOla
Otras instrucciones Transcript show:String Prompter prompt: Mensaje default: valor Visualiza en la ventana Transcript el texto que se ingresa en String. Abre una ventana con la leyenda Mensaje y solicita informacin por teclado. Si no se ingresa nada (presionar Enter), se toma como objeto devuelto el especificado en valor.. Prompter prompt:default: devuelve un String. El selector default es obligatorio. Puede especificarse: para que devuelva la cadena vaca por default. Devuelve un objeto de la clase Date conteniendo la fecha actual. A tal objeto puede aplicrsele el mensaje asString para convertirlo a String. Devuelve un objeto de la clase Time conteniendo hh:mm:ss. Puede transformarse al tipo String (idem Date).