[racket] Symbol Syntax

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Jan 5 08:12:18 EST 2011

2011/1/5 Sayth Renshaw <flebber.crue at gmail.com>:
>
> 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?

Spaces are not allowed in symbols.
In HtDP camel case is used e.g.  'TooSmall .
In the guessing game use the symbols mentioned in the exercise (with the exact
same spelling). The TeachPack expects a certain spelling (and
capitalization), so if you use
a different one, you'll never the fanfare when you correctly guess the number.

-- 
Jens Axel Søgaard



>
> (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
>



-- 
--
Jens Axel Søgaard


Posted on the users mailing list.