NIL, OFS, EOL, coalesce()
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Fri, 25 Jan 2008 14:41:11 +0000 (14:41 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Fri, 25 Jan 2008 14:41:11 +0000 (14:41 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@39 4bb87942-c103-4e5a-b51c-0ebff58f8515

cll1.h
demos/advanced-hello-world.c

diff --git a/cll1.h b/cll1.h
index e3911e1621c8703836381af18d6c266a4875ec55..be5797bc6993c5473fa00010a1d0c19a15b7c4be 100644 (file)
--- a/cll1.h
+++ b/cll1.h
 #define not !
 #define and &&
 #define or ||
+#define boolean int
+#define bool_str(VALUE) (VALUE?"TRUE":"FALSE")
 #define TRUE 1
 #define FALSE 0
-#define MAYBE (int)((_srtime?random():(_srtime=time(NULL),srandom(_srtime),random()))%2)
+#define MAYBE (int)((RANDOM_SEED?random():(RANDOM_SEED=time(NULL),srandom(RANDOM_SEED),random()))%2)
 #define WHOKNOWS (int)(srandom(time(NULL)),random()%2)
-#define bool_str(I) (I?"TRUE":"FALSE")
-#define boolean int
+#define _GLOBALS time_t RANDOM_SEED=0; char *EOL="\n", *OFS=" ", *IFS=" \t\n", *NIL="NULL";
+#define coalesce(VALUE,NOTNULL) ((VALUE)?(VALUE):(NOTNULL))
 #define mem struct
 #define construct struct
 /* ------------------------------------------------------------------- */
 /* ------------------------------------------------------------------- */
 /* 6. C<<1 va_list based library functions, updated 2008-01-22 by xCh. */
 /* ------------------------------------------------------------------- */
-#define _ECHO void _cll1_print(int p,char *s, ... ) { int p2=0; va_list ap; for(va_start(ap,s);s!=(void *)&_cll1_print;s=va_arg(ap,char *)) { if(p) {if(p2) putchar(' '); else p2=1;} fputs(s?s:"",stdout); } va_end(ap); if(p) putchar('\n');}
+#define _ECHO void _cll1_print(int p,char *s, ... ) { int p2=0; va_list ap; for(va_start(ap,s);s!=(void *)&_cll1_print;s=va_arg(ap,char *)) { if(p) {if(p2) putchar(*OFS); else p2=1;} fputs(coalesce(s,NIL),stdout); } va_end(ap); if(p) putchar(*EOL);}
 #define print(...) _cll1_print(1,__VA_ARGS__,(void *)&_cll1_print)
 #define echo(...) _cll1_print(0,__VA_ARGS__,(void *)&_cll1_print)
 /* ------------------------------------------------------------------- */
@@ -190,7 +192,7 @@ obsolete
 #define _ISTACK struct _IStack { int I; int _23; list(_IStack); } *_Iatom,*_Istack=NULL;
 #define _SSTACK struct _SStack { char *S; int _23; list(_SSTACK); } *_Satom,*_Sstack=NULL;
 #define _FSTACK struct _FStack { FILE *F; int _23; list(_FSTACK); } *_Fatom,*_Fstack=NULL;
-#define _SRTIME time_t _srtime=0;
+
 
 #define _NEW_(ATOM,STACK,TYPE) (create(ATOM,TYPE),ATOM->_23=1,push(ATOM,STACK);ATOM->_23||pop(ATOM,STACK)&&0;ATOM->_23--)
 #define _NEW_I for _NEW_(_Iatom,_Istack,_IStack)
@@ -262,7 +264,7 @@ obsolete
 /* ------------------------------------------------------------------- */
 /* Voila - here we go !                                                */
 /* ------------------------------------------------------------------- */
-#define define_cll1_globals _SRTIME _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK //_QSTACK
+#define define_cll1_globals _GLOBALS _ISTACK _SSTACK _FSTACK _MSTACK _RSTACK //_QSTACK
 #define implement_cll1_functions _ECHO // _GET_STR _GET_MEM
 #define define_cll1_interfaces //_CAKE
 #define implement_cll1_library define_cll1_globals implement_cll1_functions define_cll1_interfaces
index e855e5e9d2894a8a29bf38d287dc9fe800ea7ebb..7117279b1ba688498733f03a5041103066b38655 100644 (file)
@@ -2,9 +2,19 @@
 
 program
 {
- echo("Hello ",NULL," ","world","  ! ");
- print("Hello", "world",NULL,"!");
+ print("* echo()");
+ echo("Hello"," ","world","  !\n");
+ print("* print()");
+ print("Hello","world","!");
+ print("* MAYBE ?");
  repeat(4) print((MAYBE ? "Hello" : "Hi"), (MAYBE ? "world" : "friend"), (MAYBE ? "!" : "?"));
+ print("* WHOKNOWS ?");
  repeat(4) print((WHOKNOWS ? "Hello" : "Hi"), (WHOKNOWS ? "world" : "friend"), (WHOKNOWS ? "!" : "?"));
+ print("* NIL");
+ print("We can print",NULL,"safely.");
+ print("* coalesce():"); 
+ print("We can",coalesce("print","anything"),coalesce(NULL,"anything"),"safely."); 
+ print("* OFS");
+ OFS=":";
+ print("We","can","customize","print");
 }
This page took 0.174415 seconds and 4 git commands to generate.