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 <jinsongli...@gmail.com> > 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
signature.asc
Description: Digital signature
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users