chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] unbound variable: or


From: Jinsong Liang
Subject: Re: [Chicken-users] unbound variable: or
Date: Wed, 27 May 2015 19:43:25 -0400

Hi,

Thanks a lot for all of your replies!

Then is there a straightforward way to get a list of booleans "or"ed? I tried "fold" with "or" but it does not work either. It seems writing a loop or a recursion for this is a little overkill.

Jinsong

On Wed, May 27, 2015 at 4:54 PM, Peter Bex <address@hidden> wrote:
On Wed, May 27, 2015 at 08:34:12PM +0000, Mario Domenech Goulart wrote:
> On Wed, 27 May 2015 16:25:33 -0400 Jinsong Liang <address@hidden> wrote:
> > In Chicken, (apply + '(1 2)) returns 3, which is expected. However, if
> > I try:
> >
> > (apply or '(#t #f))
> >
> > Error: unbound variable: or
> >
> > Why (apply or '(#t #f)) does not work?
>
> Welcome!
>
> `or' (*) is not a procedure, so you can't use it as argument to other
> procedures (like `apply').

Hello Jinsong,

As Mario and Daniel explained, this doesn't work for a reason,
but the reason itself wasn't really explained.

If you have (or 'ok (error "hello")), this should simply evaluate
to the symbol 'ok, and not emit an error.  If "or" were a simple
procedure, it would first evaluate all its arguments and then call
the procedure.

Macros and special forms operate on their input expressions and
therefore have the power to shortcut evaluation like this.  Unfortunately,
to be able to do this, they need to be passed the exact _expression_
in which they occur, as-is, so they can't be passed around as values.

If they could be passed around as values (to use them, for example,
as an argument for APPLY), every procedure call would have to be treated
as a potential target for macro expansion, and no optimisations of any
kind could be made.  You would also have to determine whether a procedure
call's arguments are used as-is, or as they occur in the call to that
procedure, and so on.

I hope this makes sense now.

Cheers,
Peter


reply via email to

[Prev in Thread] Current Thread [Next in Thread]