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 <[email protected]> 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 <[email protected]> > 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 >
_______________________________________________ Chicken-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-users
