I am not sure why this happens, but once I've heard that TOP LEVEL execution is different from normal execution, inside a lambda expression for example.
Try compiling this (let ((A #t) (B 'undefined)) (if A (set! B 'good) (set! B 'bad)) (print B)) It runs as expected. Your problem is probably related to how top level evaluations are executed. If I recall correctly, continuations, at top level, behave differently too. On Fri, Aug 12, 2011 at 11:56 AM, Paul Colby <paulcco...@earthlink.net> wrote: > Hi, > I tried the following file as a prelude to doing conditional compilation and > ran into the following snag, > > ----------------------------- example.scm ----------------------- > (define A #t) > (define B 'undefined) > (if A > (set! B 'good) > (set! B 'bad)) > (print B) > ------------------------------ end ---------------------------------- > > running csi prints out the expected message 'good' > compiling using 'csc example.scm' and running the > executable results in 'undefined' being printed. the > code generated by 'csc -t example.scm' is given below. > > BTW I would dearly like to get objc egg to compile. > > Regards > Paul Colby > > ----------------------------- example.c --------------------------- > /* Generated from example.scm by the CHICKEN compiler > http://www.call-with-current-continuation.org > 2011-08-12 07:53 > Version 4.7.0 > macosx-unix-gnu-x86-64 [ 64bit manyargs dload ptables ] > compiled 2011-07-28 on Paul-Colbys-iMac.local (Darwin) > command line: example.scm -output-file example.c > used units: library eval > */ > > #include "chicken.h" > > static C_PTABLE_ENTRY *create_ptable(void); > C_noret_decl(C_library_toplevel) > C_externimport void C_ccall C_library_toplevel(C_word c,C_word d,C_word k) > C_noret; > C_noret_decl(C_eval_toplevel) > C_externimport void C_ccall C_eval_toplevel(C_word c,C_word d,C_word k) > C_noret; > > static C_TLS C_word lf[6]; > static double C_possibly_force_alignment; > static C_char C_TLS li0[] > C_aligned={C_lihdr(0,0,10),40,116,111,112,108,101,118,101,108,41,0,0,0,0,0,0}; > > > C_noret_decl(C_toplevel) > C_externexport void C_ccall C_toplevel(C_word c,C_word t0,C_word t1) C_noret; > C_noret_decl(f_14) > static void C_ccall f_14(C_word c,C_word t0,C_word t1) C_noret; > C_noret_decl(f_17) > static void C_ccall f_17(C_word c,C_word t0,C_word t1) C_noret; > C_noret_decl(f_22) > static void C_fcall f_22(C_word t0,C_word t1) C_noret; > C_noret_decl(f_25) > static void C_ccall f_25(C_word c,C_word t0,C_word t1) C_noret; > C_noret_decl(f_31) > static void C_ccall f_31(C_word c,C_word t0,C_word t1) C_noret; > C_noret_decl(f_28) > static void C_ccall f_28(C_word c,C_word t0,C_word t1) C_noret; > > C_noret_decl(trf_22) > static void C_fcall trf_22(void *dummy) C_regparm C_noret; > C_regparm static void C_fcall trf_22(void *dummy){ > C_word t1=C_pick(0); > C_word t0=C_pick(1); > C_adjust_stack(-2); > f_22(t0,t1);} > > C_noret_decl(tr2) > static void C_fcall tr2(C_proc2 k) C_regparm C_noret; > C_regparm static void C_fcall tr2(C_proc2 k){ > C_word t1=C_pick(0); > C_word t0=C_pick(1); > C_adjust_stack(-2); > (k)(2,t0,t1);} > > /* toplevel */ > static C_TLS int toplevel_initialized=0; > C_main_entry_point > C_noret_decl(toplevel_trampoline) > static void C_fcall toplevel_trampoline(void *dummy) C_regparm C_noret; > C_regparm static void C_fcall toplevel_trampoline(void *dummy){ > C_toplevel(2,C_SCHEME_UNDEFINED,C_restore);} > > void C_ccall C_toplevel(C_word c,C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word t3; > C_word *a; > if(toplevel_initialized) C_kontinue(t1,C_SCHEME_UNDEFINED); > else C_toplevel_entry(C_text("toplevel")); > C_resize_stack(262144); > C_check_nursery_minimum(3); > if(!C_demand(3)){ > C_save(t1); > C_reclaim((void*)toplevel_trampoline,NULL);} > toplevel_initialized=1; > if(!C_demand_2(60)){ > C_save(t1); > C_rereclaim2(60*sizeof(C_word), 1); > t1=C_restore;} > a=C_alloc(3); > C_initialize_lf(lf,6); > lf[0]=C_h_intern(&lf[0],1,"A"); > lf[1]=C_h_intern(&lf[1],1,"B"); > lf[2]=C_h_intern(&lf[2],9,"undefined"); > lf[3]=C_h_intern(&lf[3],25,"\003sysimplicit-exit-handler"); > lf[4]=C_h_intern(&lf[4],5,"print"); > lf[5]=C_h_intern(&lf[5],3,"bad"); > C_register_lf2(lf,6,create_ptable()); > t2=(*a=C_CLOSURE_TYPE|2,a[1]=(C_word)f_14,a[2]=t1,tmp=(C_word)a,a+=3,tmp); > C_library_toplevel(2,C_SCHEME_UNDEFINED,t2);} > > /* k12 */ > static void C_ccall f_14(C_word c,C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word t3; > C_word ab[3],*a=ab; > C_check_for_interrupt; > if(!C_stack_probe(&a)){ > C_save_and_reclaim((void*)tr2,(void*)f_14,2,t0,t1);} > t2=(*a=C_CLOSURE_TYPE|2,a[1]=(C_word)f_17,a[2]=((C_word*)t0)[2],tmp=(C_word)a,a+=3,tmp); > C_eval_toplevel(2,C_SCHEME_UNDEFINED,t2);} > > /* k15 in k12 */ > static void C_ccall f_17(C_word c,C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word t3; > C_word t4; > C_word t5; > C_word t6; > C_word ab[3],*a=ab; > C_check_for_interrupt; > if(!C_stack_probe(&a)){ > C_save_and_reclaim((void*)tr2,(void*)f_17,2,t0,t1);} > t2=C_set_block_item(lf[0] /* A */,0,C_SCHEME_TRUE); > t3=C_mutate((C_word*)lf[1]+1 /* (set! B ...) */,lf[2]); > t4=(*a=C_CLOSURE_TYPE|2,a[1]=(C_word)f_22,a[2]=((C_word*)t0)[2],tmp=(C_word)a,a+=3,tmp); > if(C_truep(C_fast_retrieve(lf[0]))){ > t5=t4; > f_22(t5,C_SCHEME_UNDEFINED);} > else{ > t5=C_mutate((C_word*)lf[1]+1 /* (set! B ...) */,lf[5]); > t6=t4; > f_22(t6,t5);}} > > /* k20 in k15 in k12 */ > static void C_fcall f_22(C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word t3; > C_word ab[3],*a=ab; > C_check_for_interrupt; > if(!C_stack_probe(&a)){ > C_save_and_reclaim((void*)trf_22,NULL,2,t0,t1);} > t2=(*a=C_CLOSURE_TYPE|2,a[1]=(C_word)f_25,a[2]=((C_word*)t0)[2],tmp=(C_word)a,a+=3,tmp); > C_trace("example.scm:6: print"); > ((C_proc3)C_fast_retrieve_proc(*((C_word*)lf[4]+1)))(3,*((C_word*)lf[4]+1),t2,C_fast_retrieve(lf[1]));} > > /* k23 in k20 in k15 in k12 */ > static void C_ccall f_25(C_word c,C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word t3; > C_word t4; > C_word ab[6],*a=ab; > C_check_for_interrupt; > if(!C_stack_probe(&a)){ > C_save_and_reclaim((void*)tr2,(void*)f_25,2,t0,t1);} > t2=(*a=C_CLOSURE_TYPE|2,a[1]=(C_word)f_28,a[2]=((C_word*)t0)[2],tmp=(C_word)a,a+=3,tmp); > t3=(*a=C_CLOSURE_TYPE|2,a[1]=(C_word)f_31,a[2]=t2,tmp=(C_word)a,a+=3,tmp); > C_trace("##sys#implicit-exit-handler"); > ((C_proc2)C_fast_retrieve_symbol_proc(lf[3]))(2,*((C_word*)lf[3]+1),t3);} > > /* k29 in k23 in k20 in k15 in k12 */ > static void C_ccall f_31(C_word c,C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word *a; > t2=t1; > ((C_proc2)C_fast_retrieve_proc(t2))(2,t2,((C_word*)t0)[2]);} > > /* k26 in k23 in k20 in k15 in k12 */ > static void C_ccall f_28(C_word c,C_word t0,C_word t1){ > C_word tmp; > C_word t2; > C_word *a; > t2=((C_word*)t0)[2]; > ((C_proc2)(void*)(*((C_word*)t2+1)))(2,t2,C_SCHEME_UNDEFINED);} > > #ifdef C_ENABLE_PTABLES > static C_PTABLE_ENTRY ptable[8] = { > {"toplevel:example_2escm",(void*)C_toplevel}, > {"f_14:example_2escm",(void*)f_14}, > {"f_17:example_2escm",(void*)f_17}, > {"f_22:example_2escm",(void*)f_22}, > {"f_25:example_2escm",(void*)f_25}, > {"f_31:example_2escm",(void*)f_31}, > {"f_28:example_2escm",(void*)f_28}, > {NULL,NULL}}; > #endif > > static C_PTABLE_ENTRY *create_ptable(void){ > #ifdef C_ENABLE_PTABLES > return ptable; > #else > return NULL; > #endif > } > /* end of file */ > > > _______________________________________________ > Chicken-users mailing list > Chicken-users@nongnu.org > https://lists.nongnu.org/mailman/listinfo/chicken-users > _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users