REScala conversion functions

Moderatoren: pmueller, SE - Design and Construction

haymanot
Neuling
Neuling
Beiträge: 7
Registriert: 20. Apr 2018 15:24

REScala conversion functions

Beitrag von haymanot » 13. Jul 2018 12:44

can anyone explain how the output is like 10,20,30,40.......?
val SPEED = 10
val time = Var(0)
val space = Signal{ SPEED * time() }
while (true) {
Thread sleep 20
time() = time.now + 1
}
space.changed += ((x: Int) => println(x))

-- output --
10
20
30
40

thanks

pmueller
Moderator
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

Re: REScala conversion functions

Beitrag von pmueller » 13. Jul 2018 12:59

Hi,

the output comes from the .changed event created on the signal space.
This in turn depends on the constant SPEED and the Signal time.
You increment the value of time by one every 20 ms.
Since space depends on time, it is updated and the corresponding change event triggers and the current value of time multiplied by SPEED is printed.
Does this answer your question?

Best,
Patrick

Eternum
Neuling
Neuling
Beiträge: 6
Registriert: 27. Jun 2013 17:49

Re: REScala conversion functions

Beitrag von Eternum » 13. Jul 2018 13:11

I hope I'm not missing something super simple but... How does the handler ever get added to space after the infinite while(true) loop?

pmueller
Moderator
Moderator
Beiträge: 87
Registriert: 25. Jan 2018 11:14

Re: REScala conversion functions

Beitrag von pmueller » 13. Jul 2018 13:24

Hi,

It won't. I just assumed this was a copy/paste error.

Best,
Patrick

haymanot
Neuling
Neuling
Beiträge: 7
Registriert: 20. Apr 2018 15:24

Re: REScala conversion functions

Beitrag von haymanot » 13. Jul 2018 13:38

yes, thanks.

Antworten

Zurück zu „Software Engineering - Design and Construction“