Skip to content

Commit

Permalink
Merge pull request #1576 from actonlang/docs-int
Browse files Browse the repository at this point in the history
Docs int
  • Loading branch information
plajjan authored Nov 10, 2023
2 parents eb05f2b + 558ab86 commit 81e16fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/acton-by-example/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Directory structure](projects/directory_structure.md)
- [Variable data types](primitives.md)
- [Scalars](primitives/scalars.md)
- [float](primitives/float.md)
- [Lists](primitives/lists.md)
- [Dictionaries](primitives/dicts.md)
- [Tuples](primitives/tuples.md)
Expand Down
20 changes: 15 additions & 5 deletions docs/acton-by-example/src/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

Acton supports a plethora of primitive data types.

- `int` integers, like `1`, `2`, `123512` or `-6542`
- `float` floats, like `1.3` or `-382.31`
- `int` integers, like `1`, `2`, `123512`, `-6542` or `1267650600228229401496703205376`
- `int` is arbitrary precision and can grow beyond machine word sizes
- `i16` is a fixed size signed 16 bit integer
- `i32` is a fixed size signed 32 bit integer
- `i64` is a fixed size signed 64 bit integer
- `u16` is a fixed size unsigned 16 bit integer
- `u32` is a fixed size unsigned 32 bit integer
- `u64` is a fixed size unsigned 64 bit integer
- `float` 64 bit float, like `1.3` or `-382.31`
- `bool` boolean, like `True` or `False`
- `str` strings, like `foo`
- strings support unicode characters
- strings support Unicode characters
- [lists](primitives/lists.md) like `[1, 2, 3]` or `["foo", "bar"]`
- [dictionaries](primitives/dicts.md) like `{"foo": 1, "bar": 3}`
- [tuples](primitives/tuples.md) like `(1, "foo")`
- [sets](primitives/sets.md) like `{"foo", "bar"}`

In Acton, mutable state can only be held by actors. You can define a global variable at the top level in your program, but it becomes constant. Assigning to the same name in an actor will overshadow the global variable.
In Acton, mutable state can only be held by actors. Global definitions in modules are constant. Assigning to the same name in an actor will shadow the global variable.

Source:
```python
Expand All @@ -25,14 +32,17 @@ actor main(env):
# this sets a local variable with the name foo, shadowing the global constant foo
foo = 4
print("local foo, shadowing the global foo:", foo)

printfoo()

a = u16(1234)
print("u16:", a)

env.exit(0)
```

Output:
```sh
local foo, shadowing the global foo: 4
global foo: 3
u16: 1234
```
20 changes: 20 additions & 0 deletions docs/acton-by-example/src/primitives/float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `float`

Source:
```python
from math import pi

actor main(env):
# round to 2 decimals
a = round(pi, 2)

# print 4 digits of pi
print("%.4f" % pi)

env.exit(0)
```

Output:
```sh
3.1416
```
2 changes: 1 addition & 1 deletion docs/run-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(source):
sf = open(sfn, "w")
sf.write(source)
sf.close()
subprocess.run(["../../dist/bin/actonc", sfn])
subprocess.run(["../dist/bin/actonc", sfn])
os.chmod(sfe, 0o755)
output = subprocess.check_output([sfe]).decode("utf-8")
except Exception as exc:
Expand Down

0 comments on commit 81e16fa

Please sign in to comment.