Skip to content

Commit

Permalink
classes
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 25, 2023
1 parent c857553 commit 0bc46f7
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions paper.tex
Original file line number Diff line number Diff line change
Expand Up @@ -431,24 +431,24 @@ \subsection{Classes}
It can be mapped to the following EO code, where a class becomes a factory of objects:

\begin{ffcode}
[] > book
[i] > new
cage 0 > id
seq > @
id.write i
[]
[] > path
QQ.txt.sprintf > @
"/tmp/%s.txt"
id
[i] > move
id.write i > @
[i] > book
cage i > id
[] > ruby-init
QQ.txt.sprintf > @
"New book!"
[] > path
QQ.txt.sprintf > @
"/tmp/%s.txt"
id
[i] > move
id.write i > @
\end{ffcode}

Here, the constructor is represented by the object \ff{new}, which initializes the object \ff{cage} with the incoming parameter \ff{i} and then makes a new anonymous object with two attributes \ff{path} and \ff{move}. The making an ``instance'' of a book would look like this:
Here, the constructor is represented by the object \ff{ruby-init}, which initializes finishes the initization of the object. The making an ``instance'' of a book would look like this:

\begin{ffcode}
book.new 42 > b
book 42 > b
b.ruby-init
b.move 7
b.path
\end{ffcode}
Expand All @@ -474,15 +474,15 @@ \subsection{Destructors}

\begin{ffcode}
[] > foo
[] > new
seq > @
QQ.io.stdout "Alive"
[]
[] > destructor
QQ.io.stdout "Dead" > @
[] > constructor
QQ.io.stdout "Alive" > @
[] > destructor
QQ.io.stdout "Dead" > @
[] > main
foo.new > f
f.destructor > @
foo > f
seq > @
f.constructor
f.destructor
\end{ffcode}

There is no garbage collection in EO, that's why a destructor must be explicitly ``called'' when an object passes out of scope or is deleted.
Expand Down

0 comments on commit 0bc46f7

Please sign in to comment.