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: Peter Bex
Subject: Re: [Chicken-users] unbound variable: or
Date: Wed, 27 May 2015 22:54:40 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

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

Attachment: signature.asc
Description: Digital signature


reply via email to

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