Skip to content
Triple003 edited this page Jun 6, 2019 · 1 revision

Types

int_type() # Integer
float_type() # Float
bool_type() # Boolean
str_type() # String
array_type(a_type) # Array
empty() # Nothing

Types are usually used when defining a variable.
An integer is a number that does not have a ..
A float is a number that does have a ..
A boolean is either True or False.
A string is some text.
An array is list that holds the type a_type
empty() is bitter nothingness.

Type specifiers

int_(value)
float_(value)
bool_(value)
str_(value)

Type specifiers convert value to the actual value of a specific language. For example, the boolean "True" is True in Python, but "True" is true is C#.

Casting

to_int(value)
to_float(value)
to_bool(value)
to_str(value)

Casting converts value to another type.
to_int(value) converts value to an integer.
to_float(value) converts value to a float.
to_bool(value) converts value to a boolean.
to_str(value) converts value to a string.

An Example

from pythonOne import *

program = Program("py")
program.set_current_program()

with start():
    new_var("one_str", str_type(), str_("1")) # "one_str" is a string
    new_var("pi", float_type(), float_(3.14))
    # Convert to "one_str" to an int
    new_var("one", int_type(), to_int("one_str")) # "one" is an int

program.build()

First, we import pythonOne and create a program:

from pythonOne import *

program = Program("py")
program.set_current_program()

Then, we define some variables:

new_var("one_str", str_type(), str_("1")) # "one_str" is a string
new_var("pi", float_type(), float_(3.14))

"one_str" is a str_type() with a value of str_("1") because it's text.
"pi" is a float_type() with a value of float_(3.14) because it has a ..
Here is another example where type specifiers come into play: "3.14" is 3.14 in Python, but "3.14" is 3.14f. The str_(value) functions doesn't really do anything other than adding quotes, but we just want to be consistent.
Next, we cast one_str, a string, to an integer, and store it in one:

# Convert to "one_str" to an int
new_var("one", int_type(), to_int("one_str")) # "one" is an int

Finally, we build the program to send its output to output.py:

program.build()

Clone this wiki locally