# Ideas for Ethon Code

## Function Types

Functions are separated into normal functions, procedures, pure functions and total functions. The differences are usually more about the intent of the writer then specific semantics. Specifically, this is the only real difference between normal functions and procedures.

The usual function declaration is `fn`.

`proc` is often used for functions with an intent of side-effects

```# Ta and Tb are types

proc some_procedure(a Ta, b Tb)
c = other_callable()
return a + b + c

fn some_function(a Ta, b Tb)
return a + b

fn some_function(a Ta, b Tb) = a + b

# `cur` implies a recursive function, but does require it
cur recursive_function(a Ta, b Tb) = a + b

# `pure` must be pure. Recursion is automatically figured out.
pure some_function(a Ta, b Tb) = a + b

# `total` must be a total function. Whether it terminates and when is part of type.
# Only functions which can be proved to terminate and operates on only finitive
# datastructures is guarenteed to be supported.
total some_function(a Ta, b Tb) = a + b
```

skw:fn df:some_function t: "Documentation of `some_function`" skw:fn df:some_function ( dv:a tp:Ta , dv:b tp:Tb ) = v:a + v:b skw:fn df:some_function ( dv:a tp:Ta , dv:b tp:Tb, c tp:Tb ) = v:a * v:c + v:b * v:c

### Virtual members

`proc` is best for virtual functions, given they are usually arent' combined in a single subroutine

`fn` may be virtual. However restrictions may apply

`pure`and `total` aren't guarenteed to be supported

## Classes, Types, Structs

All types must be started with a uppercase letter

• `self` is implied in member functions
• All instance members must be referenced using `self`
```class Person
first_name as Str
last_name as Str

fn :init(first_name _, last_name)
self.first_name = first_name
self.last_name = last_name

fn format_fullname(1==)
return first_name + " " + last_name

class Person
first_name as Str
last_name as Str

# member initialization short-form
fn :init(self.first_name, self.last_name) {}

```

`:init` are an example of a ??, which implements a specific Concept procedure/function

### Properties

```class Person
...
get name()
return self.first_name + " " + self.last_name
set name(value)
self.first_name, self.last_name = p"{:NSWord**' '} {:NSWord}".parse(value)

# +++ Ideas +++
class Person
...
prop name <- m"{:NSWord**' '} {}" <- self.first_name + self.last_name
```

## Code

### Loops

```repeat
# Loop actions
continue
break

# Nested Loops
repeat
break continue # continues outer loop
```
```while condition
...
```
```for name, id in zip(names, ids)
...```
```for ids in
...```
```for key: value in someMap
...```
```suite
...
while condition
```
```
```

## Modules and More

```import collections

...

...
import collections as col - LinkedList
```
```export
ClassA ClassB ClassC
funcA funcB funcC
constantA constantB
```
...

# Other Ideas

```
=== Basic Syntax ===

def myfunc(a:Str, b:Int) -> Int
ret b * 2

def myfunc
a as Str
b as Int
->
c as Int
d as Int
body
log(a)
c = a * 2
d = a * 2

struct MyStruct
a as Str
b as Str

def :init()
self.a = "44"
self.b = "42"

def :print = f"MyStruct({self.a}, {self.b})"

def main()
a = MyStruct()
a.a *= 2
print(a)

import datamagic - sql, orm, DeclarativeBase

Base = DeclarativeBase()

class Person using Base
[columns]
id        as Int !primary_key
nick      as Text !notnull
email     as Text !notnull !unique
[end]

def Base.after_commit()
log("Changed", self)

def :print = f"Person({self.id}, {self.email})"

type MyType = Simple | Compound a:Str b:Str

instanceClass Empty
any.ordered
self:empty() => 0
self:len()  => 0

interface ISeq
pass

typeClass pass

###### Bigger Examples ############

mixin IntrusiveSeq Container, Item

class Person
nick as Text.sized.nonull.unchecked
email as Text.sized.nonull.unchecked

def :strlit(text) = p" *{nick} *<{email:([^ ]*|".*")@[^ ]*}> *"

concept People = [Person as person]
implements IntrusiveSeq.chunk(3)

def main
people = People()
people.append Person"Jack "
people.append Person"Joe "
people.append Person"Sarah "
people.append Person"Michelle "

for people
print person

```