Overview
Basic Usage
Delta can be written in Python, and has .dt extension.
Type annotations are required when declaring new identifiers.
Example:
- valid:
x: int = 0 print(x) x = 1 print(x)
x = 0 print(x) x = 1 print(x)
Type Annotations
Delta requires type annotations when declaring new identifiers
Variables
Basic
number: int = 0 number: int #This is also vaild
Subscripts
list_var: list[int] dict_var: dict[str, int] #str as key, int as value set_var: set[float] tuple_var: tuple[int, float, str] #datatypes of elements must be specified mixed_var: list[tuple[str, dict[int, str]]]
Functions
Basic
def print_person(name: str, age: int) -> None:
print(name, age)
Keyword arguments
def calc_vel(target: float, base: float = 0) -> float:
return target - base
Example:
def print_person(name: str, age: int) -> None:
print(f"{name} is {age} years old")
def print_people(people: list[tuple[str, int]]) -> None:
for person in people:
print_person(person[0], person[1])
people: list[tuple[str, int]] = []
while True:
name: str = input("Enter name: ")
if name == "":
break
age: int = int(input("Enter age: "))
people.append((name, age))
print_people(people)
Supported Features
Delta is currently in pre-release phase, and doesn't support all the features of Python yet.
Supported keywords:
-
if -
elif -
else -
for -
while -
from ... import ... -
pass -
break -
continue -
return -
assert -
del
Supported special syntaxes:
- f-strings
Supported built-in functions:
-
print(object, end="\n") -> None -
input("prompt") -> str -
len(iterable) -> int -
int(str) -> int -
float(str) -> float -
str(object) -> str -
list(str) -> list[str] -
min(str|list|set) -> elem dtype -
max(str|list|set) -> elem dtype -
sum(str|list|set) -> elem dtype -
sorted(str|list|set) -> list[elem dtype] -
round(float) -> float -
abs(int|float) -> int|float -
cpp(str)
built-in:
special functions:
Additional Features
cpp(str)
injects C++ code into the program
Example:
x: int = cpp("time(nullptr)")
from cpp[ext] import ..
adds #include statement at the top of the compiled C++ file
Examples:
from cpp import cmath to
#include <cmath>
from cpph import time to
#include <time.h>
from cpphpp import opencv to
#include <opencv.hpp>
Example uses can be found here