Up | Next | Prev | PrevTail | Tail |
EXPR PROCEDURE APPLY(FN, ARGS); |
BEGIN SCALAR DEFN; |
IF CODEP FN THEN RETURN |
Spread the actual parameters in ARGS following the conventions: for calling functions, transfer to the entry point of the function, and return the value returned by the function. ; |
IF | IDP FN THEN RETURN |
IF | NULL(DEFN := GETD FN) THEN |
ERROR(000, LIST(FN, "is an undefined function")) |
ELSE IF CAR DEFN EQ ’EXPR THEN |
APPLY(CDR DEFN, ARGS) |
ELSE ERROR(000, |
LIST(FN, "cannot be evaluated by APPLY")); |
IF OR(ATOM FN, NOT(CAR FN EQ ’LAMBDA)) THEN |
ERROR(000, |
LIST(FN, "cannot be evaluated by APPLY")); |
RETURN |
Bind the actual parameters in ARGS to the formal parameters of the lambda expression. If the two lists are not of equal length then ERROR(000, "Number of parameters do not match"); The value returned is EVAL CADDR FN. |
END; |
EXPR PROCEDURE EVAL(U); |
BEGIN SCALAR FN; |
IF CONSTANTP U THEN RETURN U; |
IF IDP U THEN RETURN |
U is an id. Return the value most currently bound to U or if there is no such binding: ERROR(000, LIST("Unbound:", U)); |
IF | PAIRP CAR U THEN RETURN |
IF CAAR U EQ ’LAMBDA THEN APPLY(CAR U, EVLIS CDR U) |
ELSE ERROR( | 000, LIST(CAR U, |
"improperly formed LAMBDA expression")) |
ELSE IF CODEP CAR U THEN |
RETURN APPLY(CAR U, EVLIS CDR U); |
FN := GETD CAR U; |
IF NULL FN THEN |
ERROR(000, LIST(CAR U, "is an undefined function")) |
ELSE IF CAR FN EQ ’EXPR THEN |
RETURN APPLY(CDR FN, EVLIS CDR U) |
ELSE IF CAR FN EQ ’FEXPR THEN |
RETURN APPLY(CDR FN, LIST CDR U) |
ELSE IF CAR FN EQ ’MACRO THEN |
RETURN EVAL APPLY(CDR FN, LIST U) |
END; |
EXPR PROCEDURE EVLIS(U); |
IF NULL U THEN NIL |
ELSE EVAL CAR U . EVLIS CDR U; |
(FN L0 (FN L1 …(FN Ln-1 Ln) …))
where n is the number of elements in L, Li is the ith element of L.
EXPR PROCEDURE EXPAND(L,FN); |
IF NULL CDR L THEN CAR L |
ELSE LIST(FN, CAR L, EXPAND(CDR L, FN)); |
FEXPR PROCEDURE QUOTE(U); |
CAR U; |
Up | Next | Prev | PrevTail | Front |