| |   |
| 27 | 27 | \sloppy |
| 28 | 28 | \fi |
| 29 | 29 | %================================================================= |
| 30 | | \chapter{Streams}\label{cha:streams} |
| 31 | | |
| 32 | | \clsindmain{Stream} |
| 33 | | Streams are used to iterate over sequences of elements such as sequenced |
| 34 | | collections, files, and network streams. |
| 35 | | Streams may be either readable, or writeable, or both. |
| 36 | | Reading or writing is always relative to the current position in the stream. |
| 37 | | Streams can easily be converted to collections, and vice versa. |
| 30 | \chapter{Fluxos}\label{cha:streams} |
| 31 | |
| 32 | \clsindmain{Fluxos} (\foreign{streams}) são usados para iterar em sequências de elementos como coleções sequenciadas, arquivos e fluxos de rede. |
| 33 | Fluxos podem ser de leitura, escrita, ou ambos. |
| 34 | A leitura ou escrita é sempre relativa a posição atual no fluxo. |
| 35 | Fluxos podem ser facilmente convertidos para coleções e vice-versa. |
| 38 | 36 | \lr{"Streams can easily be converted into collections." I wouldn't say it like this, because it is not true for all streams (infinite streams). According to Kent Beck we should only talk about conversion when the same protocol is supported. Collections and Streams do not support the same protocol. (p. 249)} |
| 39 | 37 | |
| 40 | 38 | %============================================================= |
| 41 | | \section{Two sequences of elements} |
| 42 | | A good metaphor to understand a stream is the following: A stream |
| 43 | | can be represented as two sequences of elements: a past element sequence |
| 44 | | and a future element sequence. The stream is positioned between the two |
| 45 | | sequences. Understanding this model is important since all stream |
| 46 | | operations in Smalltalk rely on it. |
| 47 | | For this reason, most of the \clsind{Stream} classes are subclasses of \clsind{PositionableStream}. |
| 48 | | \figref{_abcde} presents a stream which contains five characters. This stream is in its original position, \ie there is no element in the past. You can go back to this position using the message \mthind{PositionableStream}{reset}. |
| 39 | \section{Duas sequências de elementos} |
| 40 | Uma boa metáfora para entender um fluxo é a seguinte: Um fluxo pode ser representada como duas sequências de elementos: a sequência de elementos visitados e a sequência de elementos a visitar. O fluxo é posicionado entre as duas sequências. Entender este modelo é importante uma vez que todos as operações de fluxo em \st dependem dele. |
| 41 | Por esta razão, a maioria das classes de \clsind{Fluxo} são subclasses de \clsind{PositionableStream}. |
| 42 | \figref{_abcde} apresenta um fluxo que contém cinco caracteres. Este fluxo está na sua posição original, \ie não há elementos já visitados. Você pode voltar a esta posição usando a mensagem \mthind{PositionableStream}{reset}. |
| 49 | 43 | |
| 50 | 44 | \begin{figure}[ht] |
| 51 | 45 | \centerline{\includegraphics[scale=0.5]{_abcdeStef}} |
| 52 | | \caption{A stream positioned at its beginning.} |
| 46 | \caption{Um fluxo posicionado em seu início.} |
| 53 | 47 | \label{fig:_abcde} |
| 54 | 48 | \vspace{.2in} |
| 55 | 49 | \end{figure} |
| 56 | 50 | |
| 57 | | Reading an element conceptually means removing the first element of the future element sequence and putting it after the last element in the past |
| 58 | | element sequence. After having read one element using the message \ct{next}, the state of your stream is that shown in \figref{a_bcde}. |
| 51 | A leitura de um elemento conceitualmente significa remover o primeiro elemento da sequência de elementos a visitar e colocá-lo na sequência de elementos visitados. Após ter lido um elemento usando a mensagem \ct{next}, o estado do seu fluxo fica semelhante ao mostrado na \figref{a_bcde}. |
| 59 | 52 | |
| 60 | 53 | \begin{figure}[ht] |
| 61 | 54 | \centerline{\includegraphics[scale=0.5]{a_bcdeStef}} |
| 62 | | \caption{The same stream after the execution of the method \ct{next}: the character \ct{a} is ``in the past'' whereas \ct{b}, \ct{c}, \ct{d} and \ct{e} are ``in the future''.} |
| 55 | \caption{O mesmo fluxo após a execução do método \ct{next}: o caractere \ct{a} está ``no passado'' enquanto \ct{b}, \ct{c}, \ct{d} e \ct{e} estão ``no futuro''.} |
| 63 | 56 | \label{fig:a_bcde} |
| 64 | 57 | \vspace{.2in} |
| 65 | 58 | \end{figure} |
| 66 | 59 | |
| 67 | | Writing an element means replacing the first element of the future sequence by the new one and moving it to the past. \figref{ax_cde} shows the state of the same stream after having written an \ct{x} using the message \mthind{Stream}{nextPut:} \ct{anElement}. |
| 60 | A escrita de um elemento significa substituir o primeiro elemento da sequência de elementos a visitar por um novo e movê-lo para a lista de elementos já visitados. A \figref{ax_cde} mostra o estado do mesmo fluxo após ter sido escrito um \ct{x} usando a mensagem \mthind{Stream}{nextPut:} \ct{anElement}. |
| 68 | 61 | |
| 69 | 62 | \begin{figure}[h!t] |
| 70 | 63 | \centerline{\includegraphics[scale=0.5]{ax_cdeStef}} |
| 71 | | \caption{The same stream after having written an \ct{x}.} |
| 64 | \caption{O mesmo fluxo após ter escrito um \ct{x}.} |
| 72 | 65 | \label{fig:ax_cde} |
| 73 | 66 | \vspace{.2in} |
| 74 | 67 | \end{figure} |
| 75 | 68 | |
| 76 | 69 | %============================================================= |
| 77 | | \section{Streams vs. collections} |
| 78 | | |
| 79 | | The collection protocol supports the storage, removal and enumeration |
| 80 | | of the elements of a collection, but does not allow these operations |
| 81 | | to be intermingled. For example, if the elements of an |
| 82 | | \clsind{OrderedCollection} are processed by a \mthind{OrderedCollection}{do:} method, it is not |
| 83 | | possible to add or remove elements from inside the \ct{do:} block. |
| 84 | | Nor does the collection protocol offer ways to iterate over two |
| 85 | | collections at the same time, choosing which collection goes forward |
| 86 | | and which does not. Procedures like these require that a traversal index or |
| 87 | | position reference is maintained outside of the collection itself: |
| 88 | | this is exactly the role of \clsind{ReadStream}, \clsind{WriteStream} and |
| 70 | \section{Fluxos vs. coleções} |
| 71 | |
| 72 | O protocolo de coleções suporta armazenamento, remoção e enumeração de elementos de uma coleção, mas não permite que essas operações sejam misturadas. Por exemplo, se os elementos de um \clsind{OrderedCollection} são processados por um método \mthind{OrderedCollection}{do:}, não é possível adicionar ou remover elementos dentro desse bloco \ct{do:}. |
| 73 | Tampouco o protocolo de coleções fornece uma forma de se iterar em duas coleções ao mesmo tempo, escolhendo qual coleção avança e qual não avança. Procedimentos como este exigem que o índice transversal ou posição de referência seja mantido fora da própria coleção: é exatamente este o papel de \clsind{ReadStream}, \clsind{WriteStream} e \clsind{ReadWriteStream}. |
| 89 | 74 | \clsind{ReadWriteStream}. |
| 90 | 75 | |
| 91 | 76 | These three classes are defined to \emph{stream over} some collection. |
| toggle raw diff |
--- a/PortugueseBook/Streams/Streams.tex
+++ b/PortugueseBook/Streams/Streams.tex
@@ -27,65 +27,50 @@
\sloppy
\fi
%=================================================================
-\chapter{Streams}\label{cha:streams}
-
-\clsindmain{Stream}
-Streams are used to iterate over sequences of elements such as sequenced
-collections, files, and network streams.
-Streams may be either readable, or writeable, or both.
-Reading or writing is always relative to the current position in the stream.
-Streams can easily be converted to collections, and vice versa.
+\chapter{Fluxos}\label{cha:streams}
+
+\clsindmain{Fluxos} (\foreign{streams}) são usados para iterar em sequências de elementos como coleções sequenciadas, arquivos e fluxos de rede.
+Fluxos podem ser de leitura, escrita, ou ambos.
+A leitura ou escrita é sempre relativa a posição atual no fluxo.
+Fluxos podem ser facilmente convertidos para coleções e vice-versa.
\lr{"Streams can easily be converted into collections." I wouldn't say it like this, because it is not true for all streams (infinite streams). According to Kent Beck we should only talk about conversion when the same protocol is supported. Collections and Streams do not support the same protocol. (p. 249)}
%=============================================================
-\section{Two sequences of elements}
-A good metaphor to understand a stream is the following: A stream
-can be represented as two sequences of elements: a past element sequence
-and a future element sequence. The stream is positioned between the two
-sequences. Understanding this model is important since all stream
-operations in Smalltalk rely on it.
-For this reason, most of the \clsind{Stream} classes are subclasses of \clsind{PositionableStream}.
-\figref{_abcde} presents a stream which contains five characters. This stream is in its original position, \ie there is no element in the past. You can go back to this position using the message \mthind{PositionableStream}{reset}.
+\section{Duas sequências de elementos}
+Uma boa metáfora para entender um fluxo é a seguinte: Um fluxo pode ser representada como duas sequências de elementos: a sequência de elementos visitados e a sequência de elementos a visitar. O fluxo é posicionado entre as duas sequências. Entender este modelo é importante uma vez que todos as operações de fluxo em \st dependem dele.
+Por esta razão, a maioria das classes de \clsind{Fluxo} são subclasses de \clsind{PositionableStream}.
+\figref{_abcde} apresenta um fluxo que contém cinco caracteres. Este fluxo está na sua posição original, \ie não há elementos já visitados. Você pode voltar a esta posição usando a mensagem \mthind{PositionableStream}{reset}.
\begin{figure}[ht]
\centerline{\includegraphics[scale=0.5]{_abcdeStef}}
-\caption{A stream positioned at its beginning.}
+\caption{Um fluxo posicionado em seu início.}
\label{fig:_abcde}
\vspace{.2in}
\end{figure}
-Reading an element conceptually means removing the first element of the future element sequence and putting it after the last element in the past
-element sequence. After having read one element using the message \ct{next}, the state of your stream is that shown in \figref{a_bcde}.
+A leitura de um elemento conceitualmente significa remover o primeiro elemento da sequência de elementos a visitar e colocá-lo na sequência de elementos visitados. Após ter lido um elemento usando a mensagem \ct{next}, o estado do seu fluxo fica semelhante ao mostrado na \figref{a_bcde}.
\begin{figure}[ht]
\centerline{\includegraphics[scale=0.5]{a_bcdeStef}}
-\caption{The same stream after the execution of the method \ct{next}: the character \ct{a} is ``in the past'' whereas \ct{b}, \ct{c}, \ct{d} and \ct{e} are ``in the future''.}
+\caption{O mesmo fluxo após a execução do método \ct{next}: o caractere \ct{a} está ``no passado'' enquanto \ct{b}, \ct{c}, \ct{d} e \ct{e} estão ``no futuro''.}
\label{fig:a_bcde}
\vspace{.2in}
\end{figure}
-Writing an element means replacing the first element of the future sequence by the new one and moving it to the past. \figref{ax_cde} shows the state of the same stream after having written an \ct{x} using the message \mthind{Stream}{nextPut:} \ct{anElement}.
+A escrita de um elemento significa substituir o primeiro elemento da sequência de elementos a visitar por um novo e movê-lo para a lista de elementos já visitados. A \figref{ax_cde} mostra o estado do mesmo fluxo após ter sido escrito um \ct{x} usando a mensagem \mthind{Stream}{nextPut:} \ct{anElement}.
\begin{figure}[h!t]
\centerline{\includegraphics[scale=0.5]{ax_cdeStef}}
-\caption{The same stream after having written an \ct{x}.}
+\caption{O mesmo fluxo após ter escrito um \ct{x}.}
\label{fig:ax_cde}
\vspace{.2in}
\end{figure}
%=============================================================
-\section{Streams vs. collections}
-
-The collection protocol supports the storage, removal and enumeration
-of the elements of a collection, but does not allow these operations
-to be intermingled. For example, if the elements of an
-\clsind{OrderedCollection} are processed by a \mthind{OrderedCollection}{do:} method, it is not
-possible to add or remove elements from inside the \ct{do:} block.
-Nor does the collection protocol offer ways to iterate over two
-collections at the same time, choosing which collection goes forward
-and which does not. Procedures like these require that a traversal index or
-position reference is maintained outside of the collection itself:
-this is exactly the role of \clsind{ReadStream}, \clsind{WriteStream} and
+\section{Fluxos vs. coleções}
+
+O protocolo de coleções suporta armazenamento, remoção e enumeração de elementos de uma coleção, mas não permite que essas operações sejam misturadas. Por exemplo, se os elementos de um \clsind{OrderedCollection} são processados por um método \mthind{OrderedCollection}{do:}, não é possível adicionar ou remover elementos dentro desse bloco \ct{do:}.
+Tampouco o protocolo de coleções fornece uma forma de se iterar em duas coleções ao mesmo tempo, escolhendo qual coleção avança e qual não avança. Procedimentos como este exigem que o índice transversal ou posição de referência seja mantido fora da própria coleção: é exatamente este o papel de \clsind{ReadStream}, \clsind{WriteStream} e \clsind{ReadWriteStream}.
\clsind{ReadWriteStream}.
These three classes are defined to \emph{stream over} some collection. |