From eb0d8f8c793b40623f60e51c055f8a7cb7cae668 Mon Sep 17 00:00:00 2001 From: xchaos Date: Sun, 21 Sep 2008 21:38:06 +0000 Subject: [PATCH] some refining git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@90 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 8 ++++---- demos/repeat.c | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cll1.h b/cll1.h index 356d70d..ccef2ef 100644 --- a/cll1.h +++ b/cll1.h @@ -151,8 +151,8 @@ extern unsigned RANDOM_SEED; / 7. C<<1 builtin iterators and conditionals, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define loop while(TRUE) -#define repeat(N) _NEW(I,0) _NEW(J,N) while(_I++<_J) -#define for_range(VAR,FROM,TO) _NEW(I,FROM) _NEW(J,TO) for( VAR=_I ; _I<=_J?VAR<=_J:VAR>=_J ; _I<=_J?VAR++:VAR--) +#define repeat(N) _NEW(I,0) _NEW(J,(N)) while(_I++<_J) /* C99 version would be: for(int _i=0,_j=(N);_i++<_j;) */ +#define for_range(VAR,FROM,TO) _NEW(I,(FROM)) _NEW(J,(TO)) for( VAR=_I ; _I<=_J?VAR<=_J:VAR>=_J ; _I<=_J?VAR++:VAR--) #define for_each(NODE,HEAD) for(NODE=HEAD; NODE; NODE=NODE->__next) #define for_search(NODE,HEAD,EXPR) for_each(NODE,HEAD) if(EXPR) #define for_file_lines(STR,FNAME) /* _NEW(CTX,get_context()) file_read(FNAME) for(use_context(_CTX),STR=file_line(_F);release_context(_M),(*S && !feof(_F));STR=file_line(_F),end_context()) _CATCH */ @@ -200,9 +200,9 @@ extern unsigned RANDOM_SEED; '----------------------------------------------------------------------- */ /* later... #define _MALLOC void *_cll1_malloc(size_t size) { return malloc(size); } */ #define _CLL1_FPRINT(IOSTREAM) { int ofs=0; va_list ap; /* <-' */ for(va_start(ap,s);s!=NIL;s=va_arg(ap,char *)) { if(ofs)fputs(OFS,IOSTREAM);else ofs=1;/**/fputs(coalesce(s,NIL),IOSTREAM); } va_end(ap); fputs(EOL,IOSTREAM); } -#define _DECLARE_PRINT void _cll1_print(char *s,...) +#define _DECLARE_PRINT void _cll1_print(const char *s,...) #define _PRINT _DECLARE_PRINT _CLL1_FPRINT(stdout) -#define _DECLARE_FPRINT void _cll1_fprint(FILE *f,char *s,...) +#define _DECLARE_FPRINT void _cll1_fprint(FILE *f,const char *s,...) #define _FPRINT _DECLARE_FPRINT _CLL1_FPRINT(f) #define _CLL1_FECHO(IOSTREAM) { va_list ap; /* <-' */ for(va_start(ap,s);s!=NIL;s=va_arg(ap,char *)) fputs(coalesce(s,NIL),IOSTREAM); va_end(ap); } #define _ECHO void _cll1_echo(char *s,...) _CLL1_FECHO(stdout) diff --git a/demos/repeat.c b/demos/repeat.c index 53ddf6a..db3726a 100644 --- a/demos/repeat.c +++ b/demos/repeat.c @@ -9,7 +9,7 @@ program print("This is demonstration, that nesting of C<<1 repeat(N) { ... } flow-control macro is completely safe:"); repeat(i++) { - echo("Outer loop is supposed to be done twice: "); + echo("Outer loop is supposed to be repeated twice: "); repeat(i) { printf("[doing this %d times] ",i); @@ -28,5 +28,9 @@ program } print("... finished."); } - } + } + repeat(--i) + { + print("Last loop is not nested and it is supposed to be repeated again just twice."); + } } -- 2.30.2