Skip to content

Commit 74b81e0

Browse files
Document keyword arguments and default args
1 parent f0be5d6 commit 74b81e0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/reference/egglog-translation.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,35 @@ def my_foo() -> i64:
131131

132132
The static types on the decorator preserve the type of the underlying function, so that they can all be checked statically.
133133

134+
### Keyword arguments
135+
136+
All arguments for egg functions must be declared positional or keyword (the default argument type) currently. You can pass arguments variably or also as keyword arguments:
137+
138+
```{code-cell} python
139+
# egg: (function bar (i64 i64) i64)
140+
@egraph.function
141+
def bar(a: i64Like, b: i64Like) -> i64:
142+
pass
143+
144+
# egg: (bar 1 2)
145+
bar(1, 2)
146+
bar(b=2, a=1)
147+
```
148+
149+
### Default arguments
150+
151+
Default argument values are also supported. They are not translated to egglog definition, which has no notion of optional values. Instead, they are added to the args when the functions is called.
152+
153+
```{code-cell} python
154+
# egg: (function bar (i64 i64) i64)
155+
@egraph.function
156+
def baz(a: i64Like, b: i64Like=i64(0)) -> i64:
157+
pass
158+
159+
# egg: (baz 1 0)
160+
baz(1)
161+
```
162+
134163
### Datatype functions
135164

136165
In egglog, the `(datatype ...)` command can also be used to declare functions. All of the functions declared in this block return the type of the declared datatype. Similarily, in Python, we can use the `@egraph.class_` decorator on a class to define a number of functions associated with that class. These

0 commit comments

Comments
 (0)