Trying to understand some SCHEME

Alphathree33

Platinum Member
Dec 1, 2000
2,419
0
0
(define (respond s1)
(cond
[(not (symbol=? (square-val s1) 'blank)) "Invalid move"]
[else
(begin
(set-square-val! s1 turn))]))


What would be a psuedo-code equivalent that would help me understand what's going on here? (I haven't really done much scheme.)

My take:

function respond(s1)
{
if( ! square-val(s1) == "blank" ) return "Invalid Move"
else
{
set-squal-val!(s1, turn);
}
}

The most confusing expression for me is this: (symbol=? (square-val s1) 'blank))

Can someone parse that out in english for me?
 
Last edited by a moderator:

Pia

Golden Member
Feb 28, 2008
1,563
0
0
symbol=? isn't standard Scheme. You are probably using PLTScheme/Racket, which appears to define symbol=? as a synonym for the standard equal?.

In short, your pseudocode is correct. Just don't confuse the symbol 'blank with the string "blank". Assuming you are coming from a C or Java background, you can think of all the symbols in your Scheme code as labels of a single enum called symbol.