**Understanding Pharo built-in data types**
# TL;DR
# Pseudo variables
# Booleans
# Numbers
# Characters, Strings and Symbols
# Literal and dynamic arrays
# Blocks
We provide an overview of the built-in data types with dediacted syntax provided by Pharo, namely booleans, characters, strings, symbols, arrays and blocks.
Smalltalk has just six reserved keywords, each of which represents a particular object value.
`nil` represents the default value of an uninitialized variables, and is the unique instance of the class {{gtClass:name=UndefinedObject}}. You can test if a variable is nil bey sending it `#isNil`:
Esto ayuda a identeificar si el contenido esta en lo correcto o nocon relacion con los booleanos
`true` and `false` are booleans, described next.
`self` and `super` are used in methods, and both represent the receiver. The difference is the way in which methods are looked up when they are sent messages. For details, see [[Understanding self and super]].
`thisContext` represents the reification of the run-time stack. For details, see [[Understanding reflection]].
In Smalltalk, everything is an object, even booleans.
`true` and `false` are the unique instances, respectively, of the classes {{gtClass:name=True}} and {{gtClass:name=False}}, both subclasses of {{gtClass:name=Boolean}}:
GtMondrianDomainExamples new classHierarchyFor: Boolean withAllSubclasses
¿ Como se hace esa representacion grafica del clases (False, True y Boolen)?
{{gtClass:name=Boolean}} consists mostly of abstract methods that are differently implemented by each of its subclasses, and generic methods that are the same for both.
Have a look at the different `&` method implementations of `true` and `false` (click on the grey triangles):
¿ Porque se mantiene el mismo resultado si cambiaron de posicion los literales?
Numbers are also organized as a hierarchy, with {{gtClass:name=Number}} as the abstract root of the hierarchy:
GtMondrianDomainExamples new classHierarchyFor: Number withAllSubclasses
¿ Como por medio de una villeta o apartados se puede guarda datos?
Smalltalk provides dedicated syntax for several kinds of numbers. Integers can be expressed either in plain decimal or radix syntax. Here we see decimal as well as binary and hexidecimal notations:
The maximum size of a {{gtClass:name=SmallInteger}} is:
However, if you increment this value, Pharo automatically converts it to a {{gtClass:name=LargeInteger}}:
Intersante de como se puede sumar nuevas variantes para un mejor resultado
Decrementing this value will, of course, result in a SmallInteger again.
Smalltalk can happily deal with very large integers:
Floats can be expressed either using plain floating point or scientific notation:
There is no dedicated syntax for fractions. Instead the factory method `/` is used as a conmvenient way to create them:
Characters are prefeixed by a dollar sign (`$`), while strings are dekimited by single quotes (`'`):
Identifica los simbolos moneterios
Untypeable characters can be created by sending dedicated instance creation methods to the {{gtClass:name=Character}} class:
¿Cual es el codigo para generar la tabla paa los datos?
Note that we can concatenate strings by sending the binary `#,` message, while characters can be converted to strings by sending the `#asString` message.
We can compare the *values* of two objects with the `#=` message, and their *identity* with the `#==` message. Two strings can have the same value but be two separate objects:
*Symbols* are similar to strings, but start with a hash (#). They have the added property that they are globally unique.
Arrays are a very basic form of Sequenceable Collection, as seen in this extract of the {{gtClass:name=Collection}} hierarchy:
GtMondrianDomainExamples new classHierarchyFor: { Collection. SequenceableCollection. ArrayedCollection. Array. String. ByteString. Symbol. OrderedCollection. }
If you need a list of objects, you will normally work with a growable {{gtClass:name=OrderedCollection}}, but fixed-size Arrays are also convenient as Pharo provides dedicated syntax for both *literal* and *dynamic* arrays.
**Literal arrays** are computed at parse time. They are expressed as a hash (`#`) followed by a list of literal values enclosed in parentheses:
¿ No entiendo el porque se genero ese resultado en la linea 4?
Note that, although we can have nested literal arrays, no expressions are dynamically evaluated, so `3`, `/`, and `4` are treated as three separate literals.
**Dynamic arrays** are evaluated at run time. They consist of a sequence of expressions delimited by curly braces and separated by periods:
It is common to use array syntax to build a list, and then send it `#asOrderedCollection` to convert it:
Blocks are Smalltalks anonymous functions, or *lambdas*. They are expressed as a sequence of statements enclosed in square brackets.
A block is evaluated by sending it the message `#value`:
Blocks may also declare a number of formal parameters, as well as local temporary variables:
To evaluate a block with one argument, send it `#value:`. To evaluate one with two arguments, send it `#value:value:`, and so on.
A block is a *closure*, i.e., it may capture any variables in its lexical environment. Even if the value of the block is passed out to other environments, it continues to hold references to any of the captuired variables:
*Caveat:* Although the return operator (`^`) may be used within a block, its effect is not to return from the block, but to return from the enclosing method.