[plt-scheme] Re: GUI
It wont work for me, I get the error
define: expected only one expression for the function body, but found
one extra part
the #t is highlighted when I get this error, since I have only been
programming for about two or three months I actually do not
understand
this part:
(define (callback x)
(cond
[(string=? "hello" (text-contents a-text))
(display "Hello!\n")]
[else
(display "No hello?\n")] )
#t)
On Jan 10, 2:30 am, Jon Stenerson <jonstener... at comcast.net> wrote:
> How about this
>
> #lang scheme
> (require htdp/gui)
>
> (define a-text
> (make-text "Please input number of elements"))
>
> (define (callback x)
> (cond
> [(string=? "hello" (text-contents a-text))
> (display "Hello!\n")]
>
> [else
> (display "No hello?\n")] )
> #t)
>
> (define initial-window
> (create-window
> (list (list a-text)
> (list (make-button "GO" callback)) ) ) )
>
>
>
> On Fri, 2010-01-08 at 12:03 -0800, Avi wrote:
> > So, I tried to do this, but it did not work for me. Here is what my
> > sample so far.
>
> > (define a-text
> > (make-text "Please input number of elements"))
>
> > (define (test x)
> > (cond
> > [(string=? "hello" x)(+ 1 1)]))
>
> > (define initial-window
> > (create-window
> > (list (list a-text)(list (make-button "GO" test )))))
>
> > (define x (text-contents a-text))
>
> > On Jan 8, 9:07 am, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> > > (string=? "hello" x) where x is the value from the text field
>
> > > On Jan 7, 2010, at 2:14 PM, Avi wrote:
>
> > > > Could you give me a hint? I was using text-contents a-text-field to
> > > > use the products of a text field to work. What does text-contents
> > > > produce?
>
> > > > On Jan 7, 1:47 pm, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> > > >> On Jan 7, 2010, at 1:42 PM, Avi wrote:
>
> > > >>> Is there a way to compare what is entered into a text-field using a
> > > >>> conditional?
>
> > > >> Of course.
>
> > > >>> if x is equal to what is in text box a than run program b
>
> > > >> Yeap.
>
> > > >>> On Jan 6, 10:22 pm, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> > > >>>> (require htdp/gui)
>
> > > >>>> (define w
> > > >>>> (create-window
> > > >>>> (list
> > > >>>> (list
> > > >>>> (make-button "go"
> > > >>>> (lambda (e)
> > > >>>> (begin
> > > >>>> (hide-window w)
> > > >>>> (local ((define w
> > > >>>> (create-window
> > > >>>> (list (list (make-button
> > > >>>> "stop" (lambda (e) (hide-window w))))))))
> > > >>>> true))))))))
>
> > > >>>> On Jan 6, 2010, at 6:18 PM, Avi wrote:
>
> > > >>>>> Please disregard my last few statements, I have decided to
> > > >>>>> change my
> > > >>>>> code based on the revisions that matthias gave me, but I have run
> > > >>>>> into
> > > >>>>> a new problem, I want to have certain gui windows open other gui
> > > >>>>> windows, but they all open at once, also I would like to know
> > > >>>>> how to
> > > >>>>> make a function run when certain text is put into a text box.
> > > >>>>> -Thanks
>
> > > >>>>> On Jan 6, 3:37 pm, Matthias Felleisen <matth... at ccs.neu.edu>
> > > >>>>> wrote:
> > > >>>>>> After fixing numerous syntactic mistakes (in a nonsensical but
> > > >>>>>> grammatically correct way), the two windows pop up just fine:
>
> > > >>>>>> ;; Intermediate plus Lambda
>
> > > >>>>>> (require htdp/gui)
>
> > > >>>>>> (define a-text-choices
> > > >>>>>> (make-message "Please pick what you want to do."))
> > > >>>>>> (define options
> > > >>>>>> (list "Compound""Moles(experimental)"))
> > > >>>>>> (define choices (make-choice options))
>
> > > >>>>>> (define b-text-field
> > > >>>>>> (make-text "Please input number of elements"))
>
> > > >>>>>> (define (choose-prog x)
> > > >>>>>> (cond
> > > >>>>>> [(symbol=? 2 (text-contents b-text-field)) "Molecule2"]
> > > >>>>>> [(symbol=? 3 (text-contents b-text-field)) "Molecule3"]
> > > >>>>>> [(symbol=? 4 (text-contents b-text-field)) "Molecule4"]))
>
> > > >>>>>> (define Element-Window
> > > >>>>>> (create-window
> > > >>>>>> (list (list b-text-field)
> > > >>>>>> (list (make-button "Go" ; choose-prog
> > > >>>>>> (lambda(e) (hide-window Element-
> > > >>>>>> Window)))))))
>
> > > >>>>>> (define (choose x)
> > > >>>>>> (cond
> > > >>>>>> [(symbol=? 0 (choice-index choices))Element-Window]))
>
> > > >>>>>> (create-window (list (list a-text-choices)(list choices) (list
> > > >>>>>> (make-
> > > >>>>>> button "OK" choose))))
>
> > > >>>>>> ;; ---
>
> > > >>>>>> Since I don't know what you want to achieve, I can't help much
> > > >>>>>> more. I
> > > >>>>>> can tell you, though, that you should design individual functions
> > > >>>>>> with
> > > >>>>>> check-expect tests and examples and so on.
>
> > > >>>>>> Good luck -- Matthias
>
> > > >>>>>> On Jan 5, 2010, at 7:28 PM, Avi wrote:
>
> > > >>>>>>> I have a program which (perhaps I should add that I began
> > > >>>>>>> scheme 2
> > > >>>>>>> months ago) gives me the following error:
>
> > > >>>>>>> reference to an identifier before its definition: choose-prog
> > > >>>>>>> <----
> > > >>>>>>> This is a definition
>
> > > >>>>>>> I know how to fix this error, but when I move my GUI file above
> > > >>>>>>> this
> > > >>>>>>> definition, it will give me another error that tells me that I
> > > >>>>>>> can
> > > >>>>>>> not use a program before I define it. A runs B, but B takes data
> > > >>>>>>> from
> > > >>>>>>> A so B must come after A, but A also must go after B because of
> > > >>>>>>> the
> > > >>>>>>> manner in which the scheme compiler works. Please help me
> > > >>>>>>> resolve. If
> > > >>>>>>> I did not do a good enough job explaining, try it for yourself
> > > >>>>>>> with
> > > >>>>>>> this code (this is the code i'm having trouble with).
>
> > > >>>>>>> (define a-text-choices
> > > >>>>>>> (make-message "Please pick what you want to do."))
> > > >>>>>>> (define options
> > > >>>>>>> (list "Compound""Moles(experimental)"))
> > > >>>>>>> (define choices
> > > >>>>>>> (make-choice options)
> > > >>>>>>> (define b-text-field
> > > >>>>>>> (make-text "Please input number of elements"))
>
> > > >>>>>>> (define choose-prog
> > > >>>>>>> (cond
> > > >>>>>>> [(symbol=? 2 (text-contents b-text-field)) Molecule2]
> > > >>>>>>> [(symbol=? 3 (text-contents b-text-field)) Molecule3]
> > > >>>>>>> [(symbol=? 4 (text-contents b-text-field)) Molecule4]))
>
> > > >>>>>>> (define Element-Window
> > > >>>>>>> (create-window
> > > >>>>>>> (list (list b-text-field)(list (make-button "Go" choose-
> > > >>>>>>> prog
> > > >>>>>>> (lambda(e)(hide-window Element-Window)))))))
>
> > > >>>>>>> (define choose
> > > >>>>>>> (cond
> > > >>>>>>> [(symbol=? 0 (choice-index choices))Element-Window]))
>
> > > >>>>>>> (create-window
> > > >>>>>>> (list(list a-text-choices)(list choices)(make-button "OK"
> > > >>>>>>> choose)))
>
> > > >>>>>>> _________________________________________________
> > > >>>>>>> For list-related administrative tasks:
> > > >>>>>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> > > >>>>>> _________________________________________________
> > > >>>>>> For list-related administrative tasks:
> > > >>>>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> > > >>>>> _________________________________________________
> > > >>>>> For list-related administrative tasks:
> > > >>>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> > > >>>> _________________________________________________
> > > >>>> For list-related administrative tasks:
> > > >>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> > > >> _________________________________________________
> > > >> For list-related administrative tasks:
> > > >> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> > > > _________________________________________________
> > > > For list-related administrative tasks:
> > > > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> > > _________________________________________________
> > > For list-related administrative tasks:
> > > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> > _________________________________________________
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme