Skip to content

Commit d06f9f1

Browse files
authored
First draft of representations.md doc (#3570)
1 parent 59c98a0 commit d06f9f1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Representations
2+
3+
The [Python representer][representer] processes and normalizes student solutions into a more "generic" form:
4+
5+
- Code is converted to an AST using the [Python AST module][python-ast].
6+
- Final AST tree is converted to a string without whitespace or indentation, and output as `representation.txt`.
7+
- For troubleshooting purposes, `representation.out` includes starting AST, edited AST, and a code representation with normalizations applied.
8+
9+
- Removals:
10+
- typehints
11+
- `print()` statements
12+
- `if __name__ == __main__` blocks
13+
- comments
14+
- docstrings
15+
16+
- Replacements:
17+
- user-defined names are replaced with placeholders (_including function names, parameters, and variables in lambdas_)
18+
19+
- Normalizations:
20+
- stringquotes `'` are changed to `"` (_doublequotes_), unless escapes are needed, then they remain unchanged.
21+
- number literals have any underscores removed and scientific notation is calculated by place:
22+
- **66_777_888_433** --> 66777888433
23+
- **1_999_878_473.66** --> 1999878473.66
24+
- **77_555_998_125.445_779** --> 77555998125.44579
25+
- **44_573_123.445_312+123_674.889_12j** --> 44573123.445312 + 123674.88912j
26+
- **1e6** --> 1000000.0 #1000000
27+
- **1e2+.23** --> 100.0 + 0.23 #100.23
28+
- **1e2+1_23e0+4.4e-1** --> 100.0 + 123.0 + 0.44 #223.44
29+
- **7e6+7e5+5e4+9.98e2+4.45_779e-1** -->7000000.0 + 700000.0 + 50000.0 + 998.0 + 0.445779 #7750998.445779
30+
- **(7e6+7e5+5e4+9.98e1+4.457_79e-1)+(1e2+1.23e1+4.444_23e-1)*1*j** --> (7000000.0 + 700000.0 + 50000.0 + 99.8 + 0.445779 + (100.0 + 12.3 + 0.444423) * 1j) #7750100.245779+112.744423j
31+
32+
[representer]: https://github.com/exercism/python-representer/tree/main/representer
33+
[python-ast]: https://docs.python.org/3/library/ast.html#module-ast
34+

0 commit comments

Comments
 (0)