question about lazy and/or - IGNORE MY PREVIOUS POST 
Author Message
 question about lazy and/or - IGNORE MY PREVIOUS POST

I just realized the cause of the bug in my program: the (and ...)
proceduer is lazy! It short circuits, i.e. as soon as one of its
parameters evaluates to false, it ignores the rest.

Are there and/or procedures in Scheme that do no short circuit, that
is, that evaluate all of their parameters?

Thanks,
Rob



Fri, 08 Apr 2005 12:23:36 GMT  
 question about lazy and/or - IGNORE MY PREVIOUS POST

Quote:

> I just realized the cause of the bug in my program: the (and ...)
> proceduer is lazy! It short circuits, i.e. as soon as one of its
> parameters evaluates to false, it ignores the rest.

> Are there and/or procedures in Scheme that do no short circuit, that
> is, that evaluate all of their parameters?

> Thanks,
> Rob

Most procedures in Scheme evaluate all their arguments before
using them.  (if, and, or) are exceptions.  You can define your
own version of and as a Scheme procedure which, not being a
special procedure (a macro) will evaluate its arguments first:

(define my-and
   (lambda args
     (if (null? args)
         '#t
         (if (car args)
             (apply my-and (cdr args))
             '#f))))

However, you're better off just writing your code differently.  For example:

(let* ((truth-one (..some expr...))
        (truth-two (..some expr...)))
   (and truth-one truth-two))

The let* is necessary to enforce the order of evaluations you
would expect from and, namely that truth-one is determined before
truth-two.  If you don't care, you can simply use let.

        Scott



Fri, 08 Apr 2005 12:52:40 GMT  
 question about lazy and/or - IGNORE MY PREVIOUS POST

Quote:


>> I just realized the cause of the bug in my program: the (and ...)
>> proceduer is lazy! It short circuits, i.e. as soon as one of its
>> parameters evaluates to false, it ignores the rest.

>> Are there and/or procedures in Scheme that do no short circuit, that
>> is, that evaluate all of their parameters?

>> Thanks,
>> Rob

> Most procedures in Scheme evaluate all their arguments before
> using them.  (if, and, or) are exceptions.

We owe to Rob to tell, that's the reason we refer
to and, or and if not as procedures, but as special forms.

Rob, try to evalute:

     (procedure? and)
     (procedure? or)
     (procedure? if)

--
Jens Axel S?gaard



Fri, 08 Apr 2005 22:44:19 GMT  
 question about lazy and/or - IGNORE MY PREVIOUS POST

Quote:


>> Most procedures in Scheme evaluate all their arguments before
>> using them.  (if, and, or) are exceptions.

> We owe to Rob to tell, that's the reason we refer
> to and, or and if not as procedures, but as special forms.

> Rob, try to evalute:

>     (procedure? and)
>     (procedure? or)
>     (procedure? if)

Excellent point.  I'd considered refering to them as syntactic forms,
but decided not to since it brought to much into the discussion.

        Scott



Sat, 09 Apr 2005 01:38:31 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. loop variants (Re: ^^^^^ignore the previous post)

2. installing mit scheme 7.3 - ignore previous post

3. Ignore previous post

4. Please Ignore Previous Posting

5. More info about previous post on exec and csh script question

6. Tclhttpd and Threads (Pls ignore previous one as it was from the wrong account)

7. Correction of my previous posting.

8. Sorry Happy.Exe previous posting

9. views,dynamic binding, addendum to my previous posting

10. Retraction of previous posting

11. omit previous post about intrument drivers

12. Correction to previous post, asterik should be replaced with apostrophe

 

 
Powered by phpBB® Forum Software