Merge: doc: fixed some typos and other misc. corrections
[nit.git] / examples / draw_operation.nit
index 8ad92fc..61f14eb 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Draws an arithmetic operation to the terminal
+# Sample program which draws an arithmetic operation to the terminal
+#
+# Output (and input) example:
+# ~~~nitish
+# Left operand: 23
+# Right operand: 15
+# Operator (+, -, *, /, %): +
+# Char to display: #
+# Size of text: 5
+# Space between digits: 1
+#       ##### #####
+#           #     #
+#       ##### #####
+#       #         #
+#       ##### #####
+#
+#         #   #####
+#   +    ##   #
+# +++++   #   #####
+#   +     #       #
+#       ##### #####
+#
+# __________________
+#
+#       ##### #####
+#           # #   #
+#       ##### #####
+#           # #   #
+#       ##### #####
+# ~~~
 module draw_operation
 
+`{
+       #include <math.h>
+`}
+
 redef enum Int
        fun n_chars: Int `{
                int c;
-               if ( abs(recv) >= 10 )
-                       c = 1+(int)log10f( (float)abs(recv) );
+               if ( abs(self) >= 10 )
+                       c = 1+(int)log10f( (float)abs(self) );
                else
                        c = 1;
-               if ( recv < 0 ) c ++;
+               if ( self < 0 ) c ++;
                return c;
        `}
 end
@@ -124,7 +157,7 @@ redef class String
                end
 
                var ci = 0
-               for c in self do
+               for c in self.chars do
                        var local_dispc
                        if c.override_dispc then
                                local_dispc = c
@@ -193,10 +226,10 @@ else
        b = gets.to_i
 
        printn "Operator (+, -, *, /, %): "
-       op_char = gets[0]
+       op_char = gets.chars[0]
 
        printn "Char to display: "
-       disp_char = gets[0]
+       disp_char = gets.chars[0]
 
        printn "Size of text: "
        disp_size = gets.to_i