[ALLY] Trouble with timers???
[1/9] from: tbrownell:yaho:o at: 24-Apr-2001 16:05
I see no reason why this script shouldn't work.. but alas, it don't.
REBOL [Title: "Timer"]
d: 0
blk: []
view layout [
y: text "00:00:00"
across
button "Start" [a: now/time]
button "Stop/Pause" [b: now/time c: b - a append blk c]
button "Finish" [foreach val blk [d: d + val] y/text: d show y]
button "Clear" [blk: [] d: 0 y/text: "00:00:00" show y ]
]
[2/9] from: tbrownell:y:ahoo at: 24-Apr-2001 16:34
If you click "Start" "Stop" "Finish" "Clear".. continuously, the sum grows and grows...
it seems the blk is not clearing?
TB
Andrew Martin <[Al--Bri--xtra--co--nz]> wrote:
Terry wrote:
> I see no reason why this script shouldn't work.. but alas, it don't.
It seems to work OK for me.
Perhaps you should put:
[b: now/time c: b - a append blk c]
into the action for Finish button?
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[3/9] from: tbrownell::yahoo at: 24-Apr-2001 19:43
Thank you, that was very helpful. But why then does this happen?
a: [42]
a: []
empty? a
== true
Andrew Martin <[Al--Bri--xtra--co--nz]> wrote:
Terry wrote:
> If you click "Start" "Stop" "Finish" "Clear".. continuously, the sum
grows and grows... it seems the blk is not clearing?
That's right. You're not 'clear-ing the block, merely assigning it to a
block. See:
button "Clear" [blk: [] d: 0 y/text: "00:00:00" show y ]
Note that the block! that 'blk is referring to, isn't 'clear-ed at all.
To remove all the values in 'blk, do:
clear blk
Note that in Rebol, the words:
blk: []
mean set the word 'blk to the value []. In otherwords, in your program,
here:
blk: [] d:
the block between "blk:" and " d: " is where the value of the block is.
The block is not "in" 'blk. It's literally in your script.
Rebol words act like pointers or references do in other languages.
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[4/9] from: allenk:powerup:au at: 25-Apr-2001 9:59
Doing this won't work if your desired effect is to clear blk
button "Clear" [blk: [] d: 0 y/text: "00:00:00" show y ]
I would use either of these to be safer.
button "Clear" [clear blk d: 0 y/text: copy "00:00:00" show y ]
or
button "Clear" [blk: copy [] d: 0 y/text: copy "00:00:00" show y ]
Cheers,
Allen K
[5/9] from: al:bri:xtra at: 25-Apr-2001 11:27
Terry wrote:
> I see no reason why this script shouldn't work.. but alas, it don't.
It seems to work OK for me.
Perhaps you should put:
[b: now/time c: b - a append blk c]
into the action for Finish button?
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[6/9] from: al:bri:xtra at: 25-Apr-2001 11:52
Terry wrote:
> If you click "Start" "Stop" "Finish" "Clear".. continuously, the sum
grows and grows... it seems the blk is not clearing?
That's right. You're not 'clear-ing the block, merely assigning it to a
block. See:
button "Clear" [blk: [] d: 0 y/text: "00:00:00" show y ]
Note that the block! that 'blk is referring to, isn't 'clear-ed at all.
To remove all the values in 'blk, do:
clear blk
Note that in Rebol, the words:
blk: []
mean set the word 'blk to the value []. In otherwords, in your program,
here:
blk: [] d:
the block between "blk:" and " d: " is where the value of the block is.
The block is not "in" 'blk. It's literally in your script.
Rebol words act like pointers or references do in other languages.
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[7/9] from: arolls:bigpond:au at: 25-Apr-2001 17:17
> Thank you, that was very helpful. But why then does this happen?
>
> a: [42]
> a: []
> empty? a
> == true
1)
First, you are setting 'a to a block with 42 in it.
Then, you are setting 'a to an empty block.
The old block (with 42 in it), is now not being
referenced by anything, so it will be garbage
collected.
2)
When you run a program, it gets loaded into memory,
then run.
The part of your program that assigns the block looks
like this in memory:-
blk: []
After adding some values to blk, the part of your
program that assigns the block now looks like this
in memory:-
blk: [1:01 3:41] ; for example, a couple of times were added.
So it's not making a new block anymore!
blk gets set to point to what it is pointing to already.
It is as if the empty block [] that you wrote in is
literally being added to in the source.
3)
When you modify a copy of a block, the original block
never gets changed, so you can continue to make copies
of it, safe in the knowledge that it is indeed empty.
Anton.
[8/9] from: carl::cybercraft::co::nz at: 25-Apr-2001 19:26
On 25-Apr-01, Terry Brownell wrote:
> Thank you, that was very helpful. But why then does this happen?
> a: [42]
> a: []
> empty? a
> == true
Because 'a is now pointing to a new block, while the original block
might still be in use, as the 'blk one was in your script. For
instance...
>> a: [42]
== [42]
>> z: a ; Both 'z and 'a now point to the block containing 42.
== [42]
>> a: [] ; This creates a new block for 'a to point to...
== []
>> z ; while 'z remains pointing to the original block...
== [42]
You /do/ eventually get the hang of this! (: It also eventually seems
a more natural way of doing things than having variable names
hard-wired to their data. Things exists, which we name, and in the
case of things like blocks with many parts, we may want to give them
many names.
> Andrew Martin <[Al--Bri--xtra--co--nz]> wrote:
> Terry wrote:
<<quoted lines omitted: 16>>
> ICQ: 26227169 http://members.nbci.com/AndrewMartin/
> -><-
--
Carl Read
[carl--cybercraft--co--nz]
[9/9] from: al:bri:xtra at: 25-Apr-2001 19:29
Terry wrote:
> Thank you, that was very helpful.
No problem.
> But why then does this happen?
>
> a: [42]
> a: []
> empty? a
> == true
You've not understood the simplicity of:
In your program, here:
blk: [] d:
the block between "blk:" and " d: " is where the value of the block is.
The block is not "in" 'blk. It's literally in your script.
In this line:
a: [42]
the value of block is literally (as it is written) in your script, just
after the "a: ".
In this line:
a: []
the value of the block is just after the "a: ".
The values in your script, lie literally in your script. The value isn't
stored anywhere else. They are not stored inside "a".
For example:
>> script: [a: [] append a 1]
== [a: [] append a 1]
>> do script
== [1]
>> probe script
[a: [1] append a 1]
== [a: [1] append a 1]
Note that the 'probe reveals that the second value in the block referred to
by the word 'script now has a "1" inside it. And if we do it again:
>> do script
== [1 1]
>> probe script
[a: [1 1] append a 1]
== [a: [1 1] append a 1]
See how the 'append is appending the "1" to the second value in the block?
There's no "magic" here. Going from left to right in the block refered to by
'script, the first value "a:" means set the word 'a to refer to the
following value which is the second value ("[]" or "[1]" or "[1 1]").
I hope that helps!
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted