>  but I do not have a clue what the aBlock is

You say the method definition is...
> linksTowards: anAddress                                        do: aBlock

and then later indicate its called like this...
>  linksTowards: aPacket destinationAddress            do: [ :link | self
send: aPacket via: link ]

so in this case aBlock would be "[ :link | self send: aPacket via: link ]"
Or was that not your question?
Remember that "blocks are objects too".
In the same way that curly brackets create an instance of Array...
    { 1 . 2 . 3 } inspect
the square brackets create an instance of BlockClosure, or "block" for
short.

In Playground, compare evaluating the above inspect with evaluating the
following... (i.e. type "inspect" and evaluate the whole thing)
    [ :x | x + 1 ] inspect
then in bottom pane of that inspector, DoItAndGo evaluate the following...
   self value: 5
and you will see the result is 6 because #value: was sent to the block
object that you inspected.

HTH
cheers -ben



On Sun, 26 Apr 2020 at 00:48, Roelof Wobben via Pharo-users <
pharo-users@lists.pharo.org> wrote:

> Hello,
>
> Im doing the OOP book written by Ducassse and im now stuck at the
> network-simulator.
> Code so far can be found here :
> https://github.com/RoelofWobben/Network-simulator
>
> Im stuck at 2 places
>
> 1) What for datatype is loopback ?  Is it a string or something else.
>     The book is not telling that.
>
> 2)  I have to make this method/function
>
> linksTowards: anAddress do: aBlock
>     "Simple flood algorithm: route via all outgoing links.
>    However, just loopback if the receiver node is the routing destination."
>    (address destination == loopback)
>    ifTrue: [self send:  via: loopback ];
>    ifFalse: [self send: via: anAddress]
>
> but I do not have a clue what the aBlock is  and if im on the right path.
> I know the solutions can be found online but then I do not learn anything.
>
> This is what is stated in the book :
>
> This method has to rely on some routing algorithm to identify which links
> will transmit the packet
> closer to its destination. Since some routing algorithms select more than
> one link, we will implement routing as an iteration method, which
> evaluates the given block for each selected link.
> KANetworkNode >> send: aPacket
> "Send aPacket, leaving the responsibility of routing to the node."
> self
> linksTowards: aPacket destinationAddress
> do: [ :link | self send: aPacket via: link ]
> One of the simplest routing algorithm is flooding: just send the packet
> via every outgoing link. Obviously, this is a waste of bandwidth, but it
> works without any knowledge of the network topology
> beyond the list of outgoing links.
> However, there is one case where we know how to route the packet: if the
> destination address
> matches the one of the current node, we can select the loopback link. The
> logic of linksTowards:do:
> is then: compare the packet’s destination address with the one of the
> node, if it is the same, we
> execute the block using the loopback link, else we simply iterate on the
> outgoing links of the receiver.
> KANetworkNode >> linksTowards: anAddress do: aBlock
> "Simple flood algorithm: route via all outgoing links.
> However, just loopback if the receiver node is the routing destination."
> ... Your code ...
>
>
> I hope someone can help me on the way or let me see which steps I had to
> take to solve this on my own.
>
> Roelof
>
>
>

Reply via email to