cint

cint university / ced, the cint editor

cint for Python and NumPy programmers

This page is part of CU-000.2, checked against cint 0.2.0.

Read this before 201 if you know Python. It lists what carries over, what changes and the lesson that shows each change running.

what carries over

for i in 0..n counts from 0 to n - 1, as for i in range(n) does. / on integers rounds toward negative infinity and % takes the sign of the divisor, which is Python's rule for // and %. A string with {name} inside prints the value of name, much as an f-string does. Tests can live in the same file as the code, and cint test runs them.

what changes

In Python or NumPy In cint Shown in
int grows to any size. Every integer has a fixed width, from I8 to I1024. A result that does not fit stops the program with a fault that names the operation, the operands and the exact result. 201-01, 301-01
A NumPy int64 array wraps without a warning, and an int64 scalar warns and carries on with the wrapped value. Arrays and single values are checked the same way. Wrapping is written as an operator of its own, such as +%. 201-01, 201-03
astype(np.int16) keeps the low bits of a value that does not fit. as I16 faults when the value does not fit. as% I16 keeps the low bits when that is the intent. 201-02
A variable takes whatever type is assigned to it. Each variable is declared with its type, and no value changes type on its own. 201-02
round rounds ties to even, without saying so at the call. Each rounded division names its rule, such as div_round(a, b, half_even). 201-04
float is the default for fractions. There is no floating-point type. Every value in these courses is an integer.
Indentation marks a block. Braces mark a block, and every body needs them. 201-08
A deep recursion stops with RecursionError. At most 256 calls can be in progress at once, counting main, and one more faults with E_DEPTH. 201-09
A list grows and shrinks. An array has a fixed length, and every index is checked. 101-12
A function can change a list it is given. A function says what it may do with an array: in to read it, inout to change it. 201-09
The interpreter runs the source. cint compiles the program to C and runs it, or runs it in an interpreter for debugging. For every program in these courses, both print the same bytes. 201-00, 201-06

why the fixed widths

Python's integers never run out of room, so a sum or product of them is never cut short. A fixed width matches the data that sensors, files, images and network packets carry. In NumPy the price of a fixed width is a wrong answer when a value outgrows it, with a warning for a single value and none for an array. In cint the price is a fault at the exact operation, with the numbers that caused it. When a program needs more room, a wider type such as I128 or I1024 holds it. It needs an as wherever it meets a narrower value, as 301-04 shows with 100 factorial.

the same output on every compiler

A cint program prints the same bytes on every compiler cint supports, and a fault prints the same record on each of them. 201-05 builds a way of testing on this: save a program's output once and compare every run after it against the saved copy.

where to start

Start with 201-00. It sets up cint and shows its four commands.