The
callbacks:
If you click the button, you'll notice that we just get a error
message. I automatically tries to call a function called it'sname
dash callback. in this case we called our button "button-of-doom"
so our callback name is "button-of-doom-callback".
Now we can write a callback with that name.
(define (button-of-doom-callback decoy ...)
(display "Doom Doom Doom!"))
the callback gets passed a bunch of stuff. "decoy ..." is there
to take all the stuff and throw it away, otherwize we'd get a "arity
error".
now place this definition
before
the window definition, then click run, and finally click "this is a
button".
It should print out "Doom Doom Doom" when you hit the button.
Taking your GUI out of "main":
Now obviously we don't want to have all our gui windows hanging around
at the top level, or they'd all show up at the begining of the
program. we want to be able to display windows when *we* want
them to display.
Try entering the following:
(define (display-window)
(display "gonna do it!")
(display "really, i'm gonna do it!")
(display "see, I did it!"))
then click run. You should get a error message. The problem
is that the guibuilder window defines some things, but R5RS dosn't
allow defines in the middle of a non-top-level body of code. This
is just a general property of scheme. Luckily they are allwed at
the begining of non-top-level bodies of code. for example, try
wrapping the window in a let:
(define (display-window)
(display "gonna do it!")
(display "really, i'm gonna do it!")
(let ((spork-overdose #t))
(display "see, I did it!")))
clicking run should run happily, and typing (display-window)
should pop up your window just as expected. Also, If we didn't
need to display those things first, we don't need to wrap it in the
let. try:
(define (display-window)
(display "see, I did it!"))
should also display the window on (display-window), because the frame
is at the begining of the define. for more details on this issue,
consult
R5RS.