[racket] Symbol Syntax
On Thu, Jan 6, 2011 at 1:06 AM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:
>
> Start reading HtDP/2e @ http://www.ccs.neu.edu/home/matthias/HtDP2e/
>
> It uses strings, which may be more familiar to you and which accommodate a
> bit more variety.
>
> Then switch back to HtDP/1e.
>
>
> On Jan 5, 2011, at 7:18 AM, Sayth Renshaw wrote:
>
> >
> > Can someone expand on the syntax for symbols? I can develop the
> check-guess game simply without symbols but cannot with symbols.
> > Trying many versions of the symbol syntax but with no success.
> >
> > This the example for symbols, but how can I test conditions with a
> symbol?
> > (define (reply s)
> > (cond
> > [(symbol=? s 'GoodMorning) 'Hi]
> >
> > [(
> > symbol=? s 'HowAreYou?) 'Fine]
> >
> > [(
> > symbol=? s 'GoodAfternoon) 'INeedANap]
> >
> > [(
> > symbol=? s 'GoodEvening) 'BoyAmITired]))
> >
> > ;function check-guess
> > ;given number evaluate to one of three answers
> > ;number -> number -> string
> >
> > tested without symbols and got it working so was trying to emulate this
> with symbols
> >
> > (define (check-guess guess target)
> > (cond
> > [(< guess target) "Too Small"]
> > [(= guess target) "Perfect"]
> > [(> guess target) "Too large"]
> >
> >
> >
> > ;(define (check-guess guess target)
> > ; (cond
> > ; [(symbol=? 'guess (< guess target) 'Too small)]
> > ; [(symbol=? 'guess (= guess target) 'Perfect)]
> > ; [(symbol=? 'guess (> guess target) 'Too Large)]))
> >
> > ;(define (check-guess guess target)
> > ; (cond
> > ; [(symbol=? (< guess target) 'True 'Too Small)]
> > ; [(symbol=? (= guess target) 'True 'Perfect)]
> > ; [(symbol=? (> guess target) 'True 'Too Large)]))
> >
> > ;(define (check-guess guess target)
> > ; (= s( < guess target))
> > ; (= s( = guess target))
> > ; (= s( > guess target))
> > ; (cond
> > ; [(symbol= s 'true 'Too Small)]
> > ; [(symbol= s 'true 'Perfect)]
> > ; [(symbol= s 'true 'Too Large)]))
> >
> > ;(define (check-guess guess target)
> > ; [(symbol=? guess (< target guess) "Too small")]
> >
> >
> > _________________________________________________
> > For list-related administrative tasks:
> > http://lists.racket-lang.org/listinfo/users
>
>
Thanks getting some coffee into a checking it out now. Thanks for the tips.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110106/6d4d5ae8/attachment.html>