Skip to content

Commit

Permalink
uh
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSecondComing123 committed Mar 18, 2022
1 parent 977f167 commit 6e96103
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Elements:

## `i` Index
Get element at index
- Arity: 2

```
Overloads:
str a, int b: a[b]
int a, str b: b[a]
a, b (all: str|int): a[b]
```
## `s` Slice
Slice a string
- Arity: 3
Expand Down
12 changes: 12 additions & 0 deletions element_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,15 @@ def negate(a: int):

def index(a: str, b: int):
return a[b]


def slice(a: str, b: int, c: int):
return a[b:c]


def head(a: str, b: int):
return a[:b]


def tail(a: str, b: int):
return a[b:]
5 changes: 4 additions & 1 deletion elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ def __call__(self, *args, **kwargs):
"!": Element(arity=1, func=ExclamationMark),
"¡": Element(arity=1, func=InversExclamation),
"□": Element(arity=1, func=HollowSquare),
"i": Element(arity=2, func=Index)
"i": Element(arity=2, func=Index),
"s": Element(arity=3, func=Slice),
"h": Element(arity=2, func=Head),
"t": Element(arity=2, func=Tail)
}
15 changes: 15 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,18 @@ def HollowSquare(a, ctx=None):
def Index(a, b, ctx=None):
if typecheck(args=[a, b], types=[str, Rational]):
return index(a, b)


def Slice(a, b, c, ctx=None):
if typecheck(args=[a, b, c], types=[str, Rational, Rational]):
return slice(a, b, c)


def Head(a, b, ctx=None):
if typecheck(args=[a, b], types=[str, Rational]):
return head(a, b)


def Tail(a, b, ctx=None):
if typecheck(args=[a, b], types=[str, Rational]):
return tail(a, b)

0 comments on commit 6e96103

Please sign in to comment.