Help understanding Scheme's syntax, procedures and calls
franbarlow at mail.com
Thu Aug 12 22:15:44 CEST 2004
eddie at holyrood.ed.ac.uk (Eddie Corns) wrote in message news:<cffit6$shd$1 at scotsman.ed.ac.uk>...
> franbarlow at mail.com (Fran) writes:
> >I'm trying to understand a functional language code fragment so I can
> >explain its syntax and workings to my non English-speaking background
> >neighbour, who is doing her finals.
> >What in heaven's name is this code fragment intending? (In English
> >prose if possible).
> >It looks like a fragment from a language called "scheme"
> >(define (this n)
> > (if (=n 0)
> > 0
> > (= n (this (- n 1)))))
> As given this is almost certainly wrong. The first problem is possibly just a
> transcription error in that (=n 0) should probably be (= n 0). The second one
> is the that the last line doesn't make sense. It looks like someone is
> confused about how if statements work. Since this looks suspiciously like
> homework I'm only giving a hint. If statements work like
> (if expr1
> (expr to return if exp1 is true)
> (expr to return if exp1 is false))
> Since each arm is an expression to evaluate it means you evaluate '=' as a
> function in the last line hence it returns a boolean, which is going to cause
> you grief after a short while.
> >(define (f1 a b)
> > (if >b a)
> > 0
> > (+ b (f1 a (+ b 1)))))
> This is wrong syntactically (hint: the first expression for the if statement)
> The questions wouldn't make sense until you fixed the functions.
> There is a comp.lang.scheme incidentally.
Thanks for the help. It's not homework but from an old exam paper, but
the girl's English isn't absolutely fluent and I'm looking for a
simple way to explain the expressions and functions.
More information about the Python-list