bugfix repeat,for_range + 2 new demos
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Tue, 8 Jan 2008 01:58:58 +0000 (01:58 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Tue, 8 Jan 2008 01:58:58 +0000 (01:58 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@6 4bb87942-c103-4e5a-b51c-0ebff58f8515

cll1.h
demos/for_range.c [new file with mode: 0644]
demos/stromecek.c [new file with mode: 0644]

diff --git a/cll1.h b/cll1.h
index 47e7024ad68dab47de88c825cf6575d69cc8f3b5..cb66f6fda918bfbc6616a772c6df17e1d58b6d63 100644 (file)
--- a/cll1.h
+++ b/cll1.h
@@ -58,8 +58,8 @@
 /* 3. C<<1 iterators - updated 2008-01-07 by xCh.                      */
 /* ------------------------------------------------------------------- */
 #define loop while(TRUE)
-#define repeat(N) _NEW_I for_range(_I,1,N)
-#define for_range(VAR,FROM,TO) for(VAR=FROM; FROM<=TO?VAR<=TO:VAR>=TO; FROM<=TO?VAR++:VAR--)
+#define repeat(N) if(N>0) _NEW_I for_range(_I,1,N)
+#define for_range(VAR,FROM,TO) for( VAR=FROM ; FROM<=TO?(VAR<=TO):(VAR>=TO) ; FROM<=TO?(VAR++):(VAR--))
 #define for_each(A,B) for(A=B; A; A=A->_next)
 #define for_search(A,B,C) for_each(A,B) if(C)
 /*to do: #define for_file_lines(STR,F) _NEW_F for() */
diff --git a/demos/for_range.c b/demos/for_range.c
new file mode 100644 (file)
index 0000000..6aedae7
--- /dev/null
@@ -0,0 +1,23 @@
+#include "cll1.h"
+
+program
+{
+ int i;
+
+ printf("for_range(i,0,1)");
+ for_range(i,0,1) printf(" [%d]",i);
+
+ printf("\nfor_range(i,1,0)");
+ for_range(i,1,0) printf(" [%d]",i);
+
+ printf("\nfor_range(i,1,1)");
+ for_range(i,1,1) printf(" [%d]",i);
+
+ printf("\nfor_range(i,1,5)");
+ for_range(i,1,5) printf(" [%d]",i);
+
+ printf("\nfor_range(i,5,1)");
+ for_range(i,5,1) printf(" [%d]",i);
+
+ printf("\n");
+}
diff --git a/demos/stromecek.c b/demos/stromecek.c
new file mode 100644 (file)
index 0000000..a2d867a
--- /dev/null
@@ -0,0 +1,18 @@
+#include "cll1.h"
+
+program
+{
+ const int kmen=28;
+ int jehlici=0,vetev=0,stromecek=2;
+
+ while(jehlici<=kmen)
+ {
+  repeat(kmen-jehlici) printf(" ");
+  printf("/");
+  repeat(jehlici<<1) if (jehlici<kmen && vetev<stromecek-1) then printf(" "); else printf("_");
+  printf("\\\n");
+  if(++vetev<stromecek) then jehlici++; else jehlici-=vetev>>1,vetev=0,stromecek++;
+ }
+ repeat(kmen) printf(" ");
+ printf("||\n");
+}
This page took 0.143325 seconds and 4 git commands to generate.