Marc:
I like keyword arguments, and would like to use them more, but they are relatively slow for small functions. So I have a question.
Shouldn't it be possible with (declare (block)) to process keyword arguments at compile time rather than by calling ___GET_KEY at run time? Consider the following example:
(declare (block))
(define (foo #!key bar) bar)
(set! a (foo))
(set! b (foo bar: 2))
This expands to:
[lindv2:~] lucier% gsc -c -expansion test.scm Expansion:
(define foo (lambda (#!key (bar '#f)) bar))
(set! a ((lambda (#!key (bar '#f)) bar)))
(set! b ((lambda (#!key (bar '#f)) bar) bar: 2))
and compiles to:
#undef ___PH_PROC #define ___PH_PROC ___H__20_test #undef ___PH_LBL0 #define ___PH_LBL0 1 #undef ___PD_ALL #define ___PD_ALL ___D_FP ___D_R0 ___D_R1 ___D_R2 #undef ___PR_ALL #define ___PR_ALL ___R_FP ___R_R0 ___R_R1 ___R_R2 #undef ___PW_ALL #define ___PW_ALL ___W_FP ___W_R0 ___W_R1 ___W_R2 ___BEGIN_P_COD ___BEGIN_P_HLBL ___DEF_P_HLBL_INTRO ___DEF_P_HLBL(___L0__20_test) ___DEF_P_HLBL(___L1__20_test) ___DEF_P_HLBL(___L2__20_test) ___DEF_P_HLBL(___L3__20_test) ___DEF_P_HLBL(___L4__20_test) ___DEF_P_HLBL(___L5__20_test) ___END_P_HLBL ___BEGIN_P_SW ___DEF_SLBL(0,___L0__20_test) ___IF_NARGS_EQ(0,___NOTHING) ___WRONG_NARGS(0,0,0,0) ___DEF_GLBL(___L__20_test) ___SET_STK(1,___R0) ___SET_R0(___LBL(2)) ___ADJFP(4) ___POLL(1) ___DEF_SLBL(1,___L1__20_test) ___SET_NARGS(0) ___GOTO(___L3__20_test) ___DEF_SLBL(2,___L2__20_test) ___SET_GLO(1,___G_a,___R1) ___SET_R2(___FIX(2L)) ___SET_R1(___KEY(0,___K_bar)) ___SET_R0(___LBL(4)) ___SET_NARGS(2) ___GOTO(___L3__20_test) ___DEF_SLBL(3,___L3__20_test) ___IF_NARGS_EQ(0,___SET_R1(___FAL)) ___GET_KEY(3,0,0,1,___SUB(0)) ___JUMPPRM(___NOTHING,___R0) ___DEF_SLBL(4,___L4__20_test) ___SET_GLO(2,___G_b,___R1) ___SET_R1(___VOID) ___POLL(5) ___DEF_SLBL(5,___L5__20_test) ___ADJFP(-4) ___JUMPPRM(___NOTHING,___STK(1)) ___END_P_SW ___END_P_COD
Couldn't it just be
Expansion:
(define foo (lambda (#!key (bar '#f)) bar))
(set! a #f)
(set! b 2)
Brad
Afficher les réponses par date