Hello.

Racket is a language in which there are procedures and special forms
(syntax). When a procedure is called, arguments to it are evaluated, and
the result of that evaluation is then used in the procedure. Consider it
like this:

> (+ (* 2 3) (/ 2 3)) ; evaluate argument
; (+ 6 (/ 2 3)) ; evaluate argument
; (+ 6 2/3) ; apply +
20/3

"and" is a special form. It does not evaluate its arguments completely
before being applied. For instance, we don't want to divide by zero, so we
might write:

> (and (not (zero? denominator)) (/ numerator denominator))

If "and" were a normal procedure it would reduce like this in the case of a
0 denominator:
; (and #f (/ numerator denominator))
error: division by 0

But the whole point is to avoid division by zero. So "and" can't be a
procedure, it has to be syntax. Unfortunately this means it cannot be used
like procedures in compositions like map, foldr, etc. There are other forms
you can use:

> (andmap values '(#t #f))
or
> (for/and ((v '(#t #f)))
    v)
#f

Deren


On Sun, Aug 6, 2017 at 12:12 AM, <arhrun.z...@gmail.com> wrote:

> new to racket‎.
>
> > (foldr + 0 '(1 2 3))
> 6
>
> but
>
> > (foldr and #t '(#t #f))
> and: bad syntax      and
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to