├── .coveragerc ├── .gitignore ├── .pylintrc ├── LICENSE ├── Procfile ├── README.md ├── big-pyth.bp ├── big-pyth.py ├── data.py ├── docs ├── Makefile ├── _build │ ├── doctrees │ │ ├── details.doctree │ │ ├── environment.pickle │ │ ├── getting-started.doctree │ │ ├── index.doctree │ │ ├── simple-programs.doctree │ │ ├── simple-programs2.doctree │ │ ├── spec_comp.doctree │ │ ├── spec_control.doctree │ │ ├── spec_math.doctree │ │ ├── spec_seq.doctree │ │ └── spec_vars.doctree │ └── html │ │ ├── .buildinfo │ │ ├── .doctrees │ │ ├── details.doctree │ │ ├── environment.pickle │ │ ├── getting-started.doctree │ │ ├── index.doctree │ │ ├── simple-programs.doctree │ │ ├── simple-programs2.doctree │ │ ├── spec_comp.doctree │ │ ├── spec_control.doctree │ │ ├── spec_func.doctree │ │ ├── spec_math.doctree │ │ ├── spec_seq.doctree │ │ ├── spec_var.doctree │ │ └── spec_vars.doctree │ │ ├── _sources │ │ ├── details.txt │ │ ├── getting-started.txt │ │ ├── index.txt │ │ ├── simple-programs.txt │ │ ├── simple-programs2.txt │ │ ├── spec_comp.txt │ │ ├── spec_control.txt │ │ ├── spec_func.txt │ │ ├── spec_math.txt │ │ ├── spec_seq.txt │ │ ├── spec_var.txt │ │ └── spec_vars.txt │ │ ├── _static │ │ ├── ajax-loader.gif │ │ ├── basic.css │ │ ├── comment-bright.png │ │ ├── comment-close.png │ │ ├── comment.png │ │ ├── css │ │ │ ├── badge_only.css │ │ │ └── theme.css │ │ ├── default.css │ │ ├── doctools.js │ │ ├── down-pressed.png │ │ ├── down.png │ │ ├── file.png │ │ ├── fonts │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ └── fontawesome-webfont.woff │ │ ├── jquery.js │ │ ├── js │ │ │ └── theme.js │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── sidebar.js │ │ ├── underscore.js │ │ ├── up-pressed.png │ │ ├── up.png │ │ └── websupport.js │ │ ├── details.html │ │ ├── genindex.html │ │ ├── getting-started.html │ │ ├── index.html │ │ ├── objects.inv │ │ ├── search.html │ │ ├── searchindex.js │ │ ├── simple-programs.html │ │ ├── simple-programs2.html │ │ ├── spec_comp.html │ │ ├── spec_control.html │ │ ├── spec_func.html │ │ ├── spec_math.html │ │ ├── spec_seq.html │ │ ├── spec_var.html │ │ └── spec_vars.html ├── adding.rst ├── conf.py ├── details.rst ├── docs.rst ├── getting-started.rst ├── index.rst ├── make.bat ├── simple-programs.rst ├── simple-programs2.rst ├── spec_comp.rst ├── spec_control.rst ├── spec_func.rst ├── spec_math.rst ├── spec_seq.rst └── spec_vars.rst ├── extra_parse.py ├── favicon2.ico ├── how-to-use-pyth.txt ├── index.html ├── lexer.py ├── macros.py ├── packed-pyth.py ├── pyth.py ├── requirements.txt ├── rev-doc.txt ├── runtime.txt ├── server.py ├── test.py └── tree.py /.coveragerc: -------------------------------------------------------------------------------- 1 | [report] 2 | exclude_lines = 3 | raise 4 | class .*(Exception) 5 | if __name__ 6 | def preprocess 7 | except 8 | [run] 9 | omit = 10 | *PIL* 11 | *sympy* 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | *.pyth 4 | venv/ 5 | tags 6 | *.gv* 7 | .coverage 8 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MESSAGES CONTROL] 2 | 3 | disable=missing-docstring, invalid-name, line-too-long, too-many-locals, too-many-return-statements, too-many-branches, too-many-statements, 4 | global-statement, eval-used, broad-except, exec-used, arguments-differ, too-many-lines, super-init-not-called, too-few-public-methods, 5 | too-many-boolean-expressions, redefined-variable-type 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 isaacg1 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn server:app 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pyth 2 | ==== 3 | 4 | Pyth, an extremely concise language. 5 | 6 | [Try it here.](https://pyth.herokuapp.com/) 7 | 8 | [Tutorial here.](https://pyth.readthedocs.org/en/latest/) 9 | 10 | ---- 11 | 12 | ## Recent changes: 13 | 14 | ### 11/26/17 15 | 16 | * `=` and `~` now allow an implicit `Q` if they are not followed by any variables for the rest of the program. 17 | * For instance, in the program `mQ=h`, the `=` assigns the result of `h`, which expands to `hQ` to `Q`. Thus, with an input of `2`, the output is `[3, 3, 3]`. 18 | 19 | ### 8/20/17 20 | 21 | * `J` and `K` now define assignment expressions until an assignment expression is complete, since the associated variables are not defined until that point. 22 | * For instance, in the program `J+J4*J3J`, the first `J` defines an assignment expression. `+` is part of that expression, `J` is part of that expression and defines another assignment expression. That inner assignment gives `J` the value `4`. Now, J is defined, and so it is treated as a variable in the expression `*J3`. Then, the final `J` is an expression of its own, and prints out `J`'s new value at this point, 16. 23 | -------------------------------------------------------------------------------- /big-pyth.bp: -------------------------------------------------------------------------------- 1 | not 2 | index-in func-filter 3 | end sorted filter-var 4 | group-by 5 | sum group-by-var 6 | subsets 7 | reverse 8 | sorted 9 | times 10 | end implicit-input 11 | implicit-input 12 | 13 | -------------------------------------------------------------------------------- /big-pyth.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | pyth_shrinker = { 4 | 'println': '\n' 5 | , 'sep': ' ' 6 | , 'no-print': ' ' 7 | , 'not': '!' 8 | , 'until-break': '#' 9 | , 'until-error': '#' 10 | , 'forever': '#' 11 | , 'func-filter': '#' 12 | , 'py-literal': '$' 13 | , 'mod': '%' 14 | , 'mod-slice': '%' 15 | , 'format': '%' 16 | , 'and': '&' 17 | , 'open-file': "'" 18 | , 'open-image': "'" 19 | , 'open-website': "'" 20 | , 'tuple': '(' 21 | , 'end-args': ')' 22 | , 'end-block': ')' 23 | , 'times': '*' 24 | , 'repeat': '*' 25 | , 'cartesian-product': '*' 26 | , 'plus': '+' 27 | , 'concatenate': '+' 28 | , 'append': '+' 29 | , 'prepend': '+' 30 | , 'union': '+' 31 | , 'add-to-set': '+' 32 | , 'pair': ',' 33 | , 'minus': '-' 34 | , 'remove': '-' 35 | , 'remove-from-singleton': '-' 36 | , 'integer-division': '/' 37 | , 'count': '/' 38 | , 'slice': ':' 39 | , 'step-range': ':' 40 | , 'assign-at-indices': ':' 41 | , 'sub': ':' 42 | , 'regex-sub': ':' 43 | , 'regex-search': ':' 44 | , 'regex-sub-group': ':' 45 | , 'regex-split': ':' 46 | , 'regex-matches-and-groups': ':' 47 | , 'end-everything': ';' 48 | , 'innermost-var': ';' 49 | , 'implicit-innermost-var': '' 50 | , 'less-than': '<' 51 | , 'less-than-lexi': '<' 52 | , 'prefix': '<' 53 | , 'all-but-suffix': '<' 54 | , 'less-than-abs': '<' 55 | , 'is-proper-subset': '<' 56 | , 'assign': '=' 57 | , 'augmented-assign': '=' 58 | , 'greater-than': '>' 59 | , 'suffix': '>' 60 | , 'all-but-prefix': '>' 61 | , 'greater-than-abs': '>' 62 | , 'is-proper-superset': '>' 63 | , 'ternary': '?' 64 | , 'if-then-else': '?' 65 | , 'lookup': '@' 66 | , 'intersection': '@' 67 | , 'root': '@' 68 | , 'assign-pair': 'A' 69 | , 'break': 'B' 70 | , 'bifurcate': 'B' 71 | , 'char': 'C' 72 | , 'conjugate': 'C' 73 | , 'transpose': 'C' 74 | , 'def': 'D' 75 | , 'func-order-by': 'D' 76 | , 'take-input': 'E' 77 | , 'func-apply-repeatedly': 'F' 78 | , 'func-fold': 'F' 79 | , 'apply': 'F' 80 | , 'for': 'F' 81 | , 'alphabet': 'G' 82 | , 'hash-table': 'H' 83 | , 'if': 'I' 84 | , 'func-invariant': 'I' 85 | , 'set-var1': 'J' 86 | , 'var1': 'J' 87 | , 'set-var2': 'J' 88 | , 'var2': 'J' 89 | , 'def-func1': 'L' 90 | , 'func1': 'y' 91 | , 'func1-var': 'b' 92 | , 'func-left-map': 'L' 93 | , 'func-map': 'M' 94 | , 'func-apply-map': 'M' 95 | , 'def-func2': 'M' 96 | , 'func2': 'g' 97 | , 'func2-var1': 'G' 98 | , 'func2-var2': 'H' 99 | , 'quote': 'N' 100 | , 'rand-int-below': 'O' 101 | , 'rand-seed': 'O' 102 | , 'rand-0-1': 'O' 103 | , 'rand-float': 'O' 104 | , 'rand-choice': 'O' 105 | , 'prime-factors': 'P' 106 | , 'is-prime': 'P' 107 | , 'phase': 'P' 108 | , 'remove-last': 'P' 109 | , 'input': 'Q' 110 | , 'implicit-input': '' 111 | , 'return': 'R' 112 | , 'func-right-map': 'R' 113 | , 'sort': 'S' 114 | , 'sorted': 'S' 115 | , 'unary-1-range': 'S' 116 | , 'ten': 'T' 117 | , 'unary-range': 'U' 118 | , 'up-to-0': 'U' 119 | , 'short-for': 'V' 120 | , 'short-for-var': 'N' 121 | , 'short-for-var1': 'N' 122 | , 'short-for-var2': 'H' 123 | , 'short-for-var3': 'b' 124 | , 'vectorize': 'V' 125 | , 'while': 'W' 126 | , 'conditional-apply': 'W' 127 | , 'assign-at': 'X' 128 | , 'replace-at': 'X' 129 | , 'translate': 'X' 130 | , 'translate-flip': 'X' 131 | , 'add-at': 'X' 132 | , 'insert-at': 'X' 133 | , 'empty-list': 'Y' 134 | , 'zero': 'Z' 135 | , 'list': '[' 136 | , 'literal-char': '\\' 137 | , 'singleton-list': ']' 138 | , 'power': '^' 139 | , 'repeated-cartesian-product': '^' 140 | , 'negate': '_' 141 | , 'reverse': '_' 142 | , 'swap-keys-vals': '_' 143 | , 'string-of': '`' 144 | , 'append-mutate': 'a' 145 | , 'add-mutate': 'a' 146 | , 'absolute-difference': 'a' 147 | , 'newline': 'b' 148 | , 'divide': 'c' 149 | , 'split': 'c' 150 | , 'split-whitespace': 'c' 151 | , 'chop-into-size-n': 'c' 152 | , 'chop-into-n-pieces': 'c' 153 | , 'chop-at-indixes': 'c' 154 | , 'space': 'd' 155 | , 'end': 'e' 156 | , 'end-digit': 'e' 157 | , 'filter': 'f' 158 | , 'filter-var': 'T' 159 | , 'filter-var1': 'T' 160 | , 'filter-var2': 'Y' 161 | , 'filter-var3': 'Z' 162 | , 'filter-above': 'f' 163 | , 'filter-above-1': 'f' 164 | , 'greater-than-or-equal-to': 'g' 165 | , 'is-superset': 'g' 166 | , 'inclusive-slice': 'g' 167 | , 'head': 'h' 168 | , 'increment': 'h' 169 | , 'from-base': 'i' 170 | , 'gcd': 'i' 171 | , 'to-base': 'j' 172 | , 'join': 'j' 173 | , 'join-on-newline': 'j' 174 | , 'empty-string': 'k' 175 | , 'length': 'l' 176 | , 'log-base-2': 'l' 177 | , 'map': 'm' 178 | , 'map-var': 'd' 179 | , 'map-var1': 'd' 180 | , 'map-var2': 'k' 181 | , 'map-var3': 'b' 182 | , 'not-equal': 'n' 183 | , 'order-by': 'o' 184 | , 'order-by-var': 'N' 185 | , 'order-by-var1': 'N' 186 | , 'order-by-var2': 'Y' 187 | , 'print': 'p' 188 | , 'equal': 'q' 189 | , 'lower': 'r' 190 | , 'upper': 'r' 191 | , 'swapcase': 'r' 192 | , 'title': 'r' 193 | , 'capitalize': 'r' 194 | , 'capitalize-words': 'r' 195 | , 'strip-whitespace': 'r' 196 | , 'split-eval': 'r' 197 | , 'rle': 'r' 198 | , 'run-len-encode': 'r' 199 | , 'run-len-string-decode': 'r' 200 | , 'run-len-pair-decode': 'r' 201 | , 'range': 'r' 202 | , 'string-range': 'r' 203 | , 'sum-strings': 's' 204 | , 'sum': 's' 205 | , 'flatten-once': 's' 206 | , 'int': 's' 207 | , 'decrement': 't' 208 | , 'tail': 't' 209 | , 'reduce': 'u' 210 | , 'apply-repeatedly': 'u' 211 | , 'fixed-point': 'u' 212 | , 'reduce-var1': 'G' 213 | , 'reduce-var2': 'H' 214 | , 'reduce-var11': 'G' 215 | , 'reduce-var12': 'H' 216 | , 'reduce-var21': 'N' 217 | , 'reduce-var22': 'T' 218 | , 'eval': 'v' 219 | , 'take-str-input': 'w' 220 | , 'bitwise-xor': 'x' 221 | , 'index-in': 'x' 222 | , 'index-all-occurences': 'x' 223 | , 'powerset': 'y' 224 | , 'subsets': 'y' 225 | , 'double': 'y' 226 | , 'str-input': 'z' 227 | , 'deduplicate': '{' 228 | , 'or': '|' 229 | , 'in': '}' 230 | , 'inclusive-range': '}' 231 | , 'post-assign': '~' 232 | , 'augmented-post-assign': '~' 233 | , 'factorial': '.!' 234 | , 'gamma': '.!' 235 | , 'packed-str': '.' 236 | , 'bit-and': '.&' 237 | , 'pop-at': '.(' 238 | , 'pop': '.)' 239 | , 'splat': '.*' 240 | , 'deltas': '.+' 241 | , 'bag-minus': '.-' 242 | , 'partition': './' 243 | , 'int-partition': './' 244 | , 'substrings-of-len': '.:' 245 | , 'substrings-of-fraction': '.:' 246 | , 'substrings': '.:' 247 | , 'all-substrings': '.:' 248 | , 'rotate-left': '.<' 249 | , 'shift-left': '.<' 250 | , 'rotate-right': '.>' 251 | , 'shift-right': '.>' 252 | , 'else': '.?' 253 | , 'all': '.A' 254 | , 'bin': '.B' 255 | , 'combinations-with-replacement': '.C' 256 | , 'divmod': '.D' 257 | , 'delete': '.D' 258 | , 'delete-all': '.D' 259 | , 'any': '.E' 260 | , 'ceil': '.E' 261 | , 'format': '.F' 262 | , 'hex': '.H' 263 | , 'invert': '.I' 264 | , 'maxima': '.M' 265 | , 'maxima-var': 'Z' 266 | , 'def-func3': '.N' 267 | , 'func3': ':' 268 | , 'func3-var1': 'N' 269 | , 'func3-var2': 'T' 270 | , 'func3-var3': 'Y' 271 | , 'oct': '.O' 272 | , 'average': '.O' 273 | , 'permutations-of-len': '.P' 274 | , 'nth-permutation': '.P' 275 | , 'number-of-permutations': '.P' 276 | , 'all-evaluated-input': '.Q' 277 | , 'round-to-places': '.R' 278 | , 'round-like': '.R' 279 | , 'shuffle': '.S' 280 | , 'transpose-justified': '.T' 281 | , 'reduce-no-start': '.U' 282 | , 'infinite-for': '.V' 283 | , 'for-counting-up': '.V' 284 | , 'infinite-for-var': 'b' 285 | , 'functional-while': '.W' 286 | , 'decompress': '.Z' 287 | , 'compress': '.Z' 288 | , 'left-pad': '.[' 289 | , 'sides-pad': '.[' 290 | , 'right-pad': '.[' 291 | , 'mod-exp': '.^' 292 | , 'prefixes': '._' 293 | , 'sign': '._' 294 | , 'abs': '.a' 295 | , 'l2-norm': '.a' 296 | , 'ls-norm-diff': '.a' 297 | , 'zip-map': '.b' 298 | , 'zip-map-var1': 'N' 299 | , 'zip-map-var2': 'Y' 300 | , 'combinations': '.c' 301 | , 'number-of-combinations': '.c' 302 | , 'system-time': '.d' 303 | , 'process-time': '.d' 304 | , 'detailed-time': '.d' 305 | , 'year': '.d' 306 | , 'month': '.d' 307 | , 'day': '.d' 308 | , 'hour': '.d' 309 | , 'second': '.d' 310 | , 'weekday': '.d' 311 | , 'sleep': '.d' 312 | , 'dict': '.d' 313 | , 'enumerate-map': '.e' 314 | , 'enumerate-map-element': 'b' 315 | , 'enumerate-map-index': 'k' 316 | , 'filter-first-n': '.f' 317 | , 'filter-first-n-var': 'Z' 318 | , 'group-by': '.g' 319 | , 'group-by-var': 'k' 320 | , 'interleave': '.i' 321 | , 'complex': '.j' 322 | , 'log-base': '.l' 323 | , 'natural-log': '.l' 324 | , 'minima': '.m' 325 | , 'minima-var': 'b' 326 | , 'flatten': '.n' 327 | , 'pi': '.n' 328 | , 'e': '.n' 329 | , 'sqrt-2': '.n' 330 | , 'phi': '.n' 331 | , 'infinity': '.n' 332 | , 'neg-infinity': '.n' 333 | , 'NaN': '.n' 334 | , 'all-permutations': '.p' 335 | , 'exit': '.q' 336 | , 'rotary-translate': '.r' 337 | , 'strip': '.s' 338 | , 'transpose-and-fill': '.t' 339 | , 'transpose-and-fill-with-spaces': '.t' 340 | , 'sin': '.t' 341 | , 'cos': '.t' 342 | , 'tan': '.t' 343 | , 'arcsin': '.t' 344 | , 'arccos': '.t' 345 | , 'arctan': '.t' 346 | , 'rad-to-deg': '.t' 347 | , 'deg-to-rad': '.t' 348 | , 'sinh': '.t' 349 | , 'cosh': '.t' 350 | , 'tanh': '.t' 351 | , 'arcsinh': '.t' 352 | , 'arccosh': '.t' 353 | , 'arctanh': '.t' 354 | , 'cumulative-reduce': '.u' 355 | , 'cumulative-fixed-point': '.u' 356 | , 'cumulative-reduce-var1': 'N' 357 | , 'cumulative-reduce-var2': 'Y' 358 | , 'eval-pyth': '.v' 359 | , 'write-file': '.w' 360 | , 'append-file': '.w' 361 | , 'write-image': '.w' 362 | , 'http-request': '.w' 363 | , 'try-catch': '.x' 364 | , 'all-input': '.z' 365 | , 'set': '.{' 366 | , 'bit-or': '.|' 367 | , 'set-union': '.|' 368 | 369 | } 370 | 371 | 372 | def translate(big_pyth): 373 | pyth = [] 374 | for token in big_pyth.split(): 375 | if token[0].isalpha() and token not in pyth_shrinker: 376 | raise NameError("{} is not a recognized token.".format(token)) 377 | pyth.append(pyth_shrinker.get(token, token)) 378 | return ''.join(pyth) 379 | 380 | if __name__ == '__main__': 381 | big_pyth = ''.join(sys.stdin.readlines()) 382 | print(translate(big_pyth)) 383 | -------------------------------------------------------------------------------- /data.py: -------------------------------------------------------------------------------- 1 | lambda_f = ('f', 'm', 'o', 'u', '.b', '.e', '.f', '.g', '.I', 2 | '.m', '.M', '.u', '.U') 3 | end_statement = ('B', 'R', '.*') 4 | variables = 'bdGHkNQTYzZ' 5 | 6 | # Variables cheat sheet: 7 | # b = "\n" 8 | # d is for map, d=' ' 9 | # G is for reduce, G=string.ascii_lowercase (abc..xyz) 10 | # H is for reduce, H = {} 11 | # k = '' 12 | # J - Autoinitializer - copies, no stringing. 13 | # K - Autoinitializer - can be strung (KJw), no copy. 14 | # N = None, second option variable for map,filter,reduce 15 | # T is for filter, second variable option for reduce, T=10 16 | # Y = [] 17 | # Z = 0 18 | 19 | c_to_s = { 20 | 'D': ('@memoized\ndef {0}:{1}', 1), 21 | 'D without memoization': ('def {0}:{1}', 1), 22 | 'F': ('for {0} in num_to_range({1}):{2}', 2), 23 | 'I': ('if {0}:{1}', 1), 24 | 'W': ('while {0}:{1}', 1), 25 | '#': ('while True:\n try:{0}\n except Exception:\n break', 0, 1), 26 | '.V': ('for b in infinite_iterator({0}):{1}', 1), 27 | 'else': ('else:{0}', 0), 28 | } 29 | 30 | # Arbitrary format operators - use for assignment, infix, etc. 31 | # All surrounding strings, arity 32 | c_to_i = { 33 | '=': ('assign(\'{0}\',{1})', 2), 34 | '~': ('post_assign(\'{0}\',{1})', 2), 35 | '&': ('({0} and {1})', 2), 36 | '|': ('({0} or {1})', 2), 37 | '?': ('({1} if {0} else {2})', 3), 38 | ',': ('[{0},{1}]', 2), 39 | 'B': ('break', 0), 40 | 'J': ('assign("J",{0})', 1), 41 | 'K': ('assign("K",{0})', 1), 42 | 'R': ('return {0}', 1), 43 | '.W': ('apply_while(lambda H:{0}, lambda Z:{1}, {2})', 3), 44 | '.x': ('Pexcept(lambda:{0}, lambda:{1})', 2), 45 | '.*': ('*({0})', 1), 46 | '.)': ('{0}.pop()', 1), 47 | '.(': ('{0}.pop({1})', 2), 48 | } 49 | 50 | # Simple functions only. 51 | # Extensible is allowed, nothing else complicated is. 52 | # name,arity 53 | c_to_f = { 54 | '`': ('repr', 1), 55 | '!': ('Pnot', 1), 56 | '@': ('lookup', 2), 57 | '%': ('mod', 2), 58 | '^': ('Ppow', 2), 59 | '*': ('times', 2), 60 | '(': ('Ptuple', float("inf")), 61 | '-': ('minus', 2), 62 | '_': ('neg', 1), 63 | '+': ('plus', 2), 64 | '[': ('Plist', float("inf")), 65 | ']': ('singleton', 1), 66 | '{': ('uniquify', 1), 67 | '}': ('Pin', 2), 68 | "'": ('read_file', 1), 69 | ':': ('at_slice', 3), 70 | '<': ('lt', 2), 71 | '>': ('gt', 2), 72 | '/': ('div', 2), 73 | ' ': ('', 1), 74 | '\n': ('imp_print', 1), 75 | 'a': ('append', 2), 76 | 'C': ('Pchr', 1), 77 | 'c': ('chop', 2), 78 | 'E': ('eval_input', 0), 79 | 'e': ('end', 1), 80 | 'f': ('Pfilter', 2), 81 | 'g': ('gte', 2), 82 | 'h': ('head', 1), 83 | 'i': ('base_10', 2), 84 | 'j': ('join', 2), 85 | 'l': ('Plen', 1), 86 | 'm': ('Pmap', 2), 87 | 'n': ('ne', 2), 88 | 'O': ('rchoice', 1), 89 | 'o': ('order', 2), 90 | 'P': ('primes_pop', 1), 91 | 'p': ('Pprint', 1), 92 | 'q': ('equal', 2), 93 | 'r': ('Prange', 2), 94 | 'S': ('Psorted', 1), 95 | 's': ('Psum', 1), 96 | 't': ('tail', 1), 97 | 'U': ('urange', 1), 98 | 'u': ('reduce', 3), 99 | 'v': ('Punsafe_eval', 1), 100 | 'w': ('input', 0), 101 | 'X': ('assign_at', 3), 102 | 'x': ('index', 2), 103 | 'y': ('subsets', 1), 104 | '.A': ('all', 1), 105 | '.a': ('Pabs', 1), 106 | '.B': ('Pbin', 1), 107 | '.b': ('binary_map', 3), 108 | '.c': ('combinations', 2), 109 | '.C': ('combinations_with_replacement', 2), 110 | '.d': ('dict_or_date', 1), 111 | '.D': ('divmod_or_delete', 2), 112 | '.E': ('Pany', 1), 113 | '.e': ('Penumerate', 2), 114 | '.f': ('first_n', 3), 115 | '.F': ('Pformat', 2), 116 | '.g': ('group_by', 2), 117 | '.H': ('Phex', 1), 118 | '.h': ('Phash', 1), 119 | '.i': ('interleave', 2), 120 | '.I': ('invert', 2), 121 | '.j': ('Pcomplex', 2), 122 | '.l': ('log', 2), 123 | '.m': ('minimal', 2), 124 | '.M': ('maximal', 2), 125 | '.n': ('Pnumbers', 1), 126 | '.O': ('Poct', 1), 127 | '.p': ('permutations', 1), 128 | '.P': ('permutations2', 2), 129 | '.q': ('Pexit', 0), 130 | '.Q': ('eval_all_input', 0), 131 | '.r': ('rotate', 2), 132 | '.R': ('Pround', 2), 133 | '.S': ('shuffle', 1), 134 | '.s': ('Pstrip', 2), 135 | '.t': ('trig', 2), 136 | '.T': ('transpose', 1), 137 | '.U': ('reduce2', 2), 138 | '.u': ('cu_reduce', 3), 139 | '.v': ('pyth_eval', 1), 140 | '.w': ('Pwrite', 2), 141 | '.y': ('all_subset_orders', 1), 142 | '.z': ('all_input', 0), 143 | '.Z': ('compress', 1), 144 | '."': ('packed_str', 1), 145 | '.^': ('pow', 3), 146 | '.&': ('bitand', 2), 147 | '.|': ('bitor', 2), 148 | '.<': ('leftshift', 2), 149 | '.>': ('rightshift', 2), 150 | './': ('partition', 1), 151 | '._': ('sign', 1), 152 | '.-': ('remove', 2), 153 | '.+': ('deltas', 1), 154 | '.:': ('substrings', 2), 155 | '.{': ('Pset', 1), 156 | '.!': ('factorial', 1), 157 | '.[': ('pad', 3), 158 | } 159 | 160 | optional_final_args = { 161 | ':': 1, 162 | 'c': 1, 163 | 'f': 1, 164 | 'j': 1, 165 | 'u': 1, 166 | 'X': 1, 167 | '.b': 1, 168 | '.f': 1, 169 | '.j': 2, 170 | '.l': 1, 171 | '.u': 1, 172 | '.w': 1, 173 | '.:': 1, 174 | '.{': 1, 175 | '.t': 1, 176 | } 177 | 178 | replacements = { 179 | 'V': [['F', 'N'], ['F', 'H'], ['F', 'b'], ], 180 | 'A': [['=', ',', 'G', 'H'], ], 181 | 'L': [['D', 'y', 'b', 'R'], ['D', "'", 'b', 'R'], ], 182 | 'M': [['D', 'g', 'G', 'H', 'R'], ['D', 'n', 'G', 'H', 'R'], ], 183 | '.N': [['D', ':', 'N', 'T', 'Y', 'R'], ['D', 'X', 'N', 'T', 'Y', 'R'], ], 184 | '.?': [[')', 'else'], ], 185 | } 186 | 187 | rotate_back_replacements = ('V',) 188 | 189 | 190 | # Gives next function header to use - for filter, map, reduce. 191 | 192 | lambda_vars = { 193 | 'f': ['T', 'Y', 'Z'], 194 | 'm': ['d', 'k', 'b'], 195 | 'o': ['N', 'Z'], 196 | 'u': ['G, H', 'N, T'], 197 | '.b': ['N, Y'], 198 | '.e': ['k, b', 'Y, Z'], 199 | '.f': ['Z'], 200 | '.g': ['k'], 201 | '.I': ['G'], 202 | '.m': ['b'], 203 | '.M': ['Z'], 204 | '.u': ['N, Y'], 205 | '.U': ['b, Z', 'k, Y'], 206 | } 207 | 208 | # For autoinitializers. One shot, not rotating. 209 | next_c_to_i = { 210 | 'J': (('J'), 0), 211 | 'K': (('K'), 0), 212 | } 213 | 214 | # Prependers. 215 | prepend = { 216 | 'Q': ["=", "Q", "E"], 217 | 'z': ["=", "z", "w"], 218 | } 219 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Pyth.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Pyth.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/Pyth" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Pyth" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/_build/doctrees/details.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/details.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/doctrees/getting-started.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/getting-started.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/simple-programs.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/simple-programs.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/simple-programs2.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/simple-programs2.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/spec_comp.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/spec_comp.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/spec_control.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/spec_control.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/spec_math.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/spec_math.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/spec_seq.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/spec_seq.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/spec_vars.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/doctrees/spec_vars.doctree -------------------------------------------------------------------------------- /docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: a2932649b184a2fdf2833e622231e278 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/details.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/details.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/getting-started.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/getting-started.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/simple-programs.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/simple-programs.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/simple-programs2.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/simple-programs2.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_comp.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_comp.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_control.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_control.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_func.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_func.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_math.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_math.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_seq.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_seq.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_var.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_var.doctree -------------------------------------------------------------------------------- /docs/_build/html/.doctrees/spec_vars.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/.doctrees/spec_vars.doctree -------------------------------------------------------------------------------- /docs/_build/html/_sources/details.txt: -------------------------------------------------------------------------------- 1 | 2. More Details About Pyth 2 | ************************** 3 | 4 | Since you now have the programming environment set up to program in, let's learn some more about the language. Let's try adding some numbers now. 5 | 6 | 2.1. Pyth Uses Prefix Notation 7 | ============================== 8 | 9 | Ok, ``2+2`` seems easy enough. Check and see what the interpreter makes of that. It'll be 4 right?:: 10 | 11 | 2 12 | Traceback (most recent call last): 13 | File "safe_pyth.py", line 300, in 14 | File "", line 5, in 15 | TypeError: plus() missing 1 required positional argument: 'b' 16 | 17 | Oh noes! An error! What went wrong? Well, Pyth doesn't use Infix notation like most languages do (the operator goes between the operands), but instead uses `Prefix (aka Polish) `_ notation, which means the operator goes *before* the operands. This has the benefit of not requiring parenthesis, making programs shorter and freeing up operators for other use. So let's try that math problem again:: 18 | 19 | +2 2 20 | 21 | Output: 22 | 23 | 4 24 | 25 | There, now its working like we expected it to. Notice the space between the ``2``'s so the parser doesn't interpret them as a ``22``. 26 | 27 | 2.2. Pyth Has Many, Many Operators 28 | ================================== 29 | 30 | The addition operator we just saw doesn't even begin to scratch the surface of Pyth's rich variety of operators. Besides addition Pyth has all the customary arithmetic operators - ``-`` for subtraction, ``*`` for multiplication, ``/`` for division, ``%`` for modulo, and ``^`` for exponentiation. Integers are defined as you would expect and Floats with the decimal point. Ex:: 31 | 32 | 0 33 | 1 34 | 18374 35 | 2.5 36 | 37 | However, negative numbers do not use a unary version of the subtraction symbol since all operators have a fixed arity (more on that later) but use the unary reversal operator: ``_``:: 38 | 39 | Invalid: -25 40 | 41 | Valid: _25 42 | 43 | Pyth also has predefined variables that are set to useful values before program execution starts. Examples are:: 44 | 45 | Z=0 46 | T=10 47 | k="" 48 | d=" " 49 | b="\n" 50 | 51 | All operators, variables, and control flow keywords, are always one character long to reduce the size of the program. This does make Pyth programs very hard to read. 52 | 53 | As I said before, Pyth has much more than arithmetic, but you'll learn about them in due time. 54 | 55 | 2.3. All Operators in Pyth Have a Fixed Arity 56 | ============================================= 57 | 58 | A very important concept in Pyth is that of arity. The `arity `_ of an operator or function (according to Wikipedia) is *the number of arguments or operands the function or operation accepts.* Most programming languages allow functions to accept different amounts of arguments, but this causes them to require parenthesis. In the want for smaller programs, Pyth has a fixed number of operands per operator, allowing it to do away with parenthesis or any other delimiter. 59 | 60 | 2.4. Operators Mean Different Things in Different Contexts 61 | ========================================================== 62 | 63 | In an effort to further increase the number of function available with only one character operators, operators do different things in Pyth depending on the values passed to it. For example, the ``+`` operator adds numbers, which you already saw, but if it gets two sequences (e.g. strings, lists) as operands, it concatenates them:: 64 | 65 | +2 T -> 12 (remember that T=10) 66 | 67 | +"Hello ""World!" -> Hello World! 68 | 69 | The ``+`` sign meaning both concatenation and addition is pretty common, but Pyth takes this to another level, with most operators having 2 or more meanings. 70 | 71 | 2.5. The Pyth Code is Compiled to Python Code Then Run 72 | ====================================================== 73 | 74 | Pyth is technically a `JIT `_ compiled language since the Pyth code is converted to Python through a series of rules defined in the file ``data.py`` and then run with the variables and functions defined in ``macros.py``. To see this in action, you can select the debug button in the online interpreter or pass the ``-d`` flag to the local one to see the compiled Python code. Here is what comes out as debug from ``^T6`` which evaluates to a million:: 75 | 76 | ================================================== 77 | ^T6 78 | ================================================== 79 | Pprint("\n",Ppow(T,6)) 80 | ================================================== 81 | 1000000 82 | 83 | As you can see, the exponentiation call is translated to a call to the function ``Ppow`` and is implicitly printed through a custom print function called ``Pprint``. The debug option can be very helpful with seeing what at first glance looks like a bunch of random characters does. 84 | 85 | Next we'll write some example programs to learn more about Pyth. -------------------------------------------------------------------------------- /docs/_build/html/_sources/getting-started.txt: -------------------------------------------------------------------------------- 1 | 1. Getting Started 2 | ****************** 3 | 4 | Pyth is a language created by `PPCG `_ (Programming Puzzles and Code Golf) user `Isaacg `_. It is meant to be a golfing language based on python (notice the name), and unlike most golfing languages is fully procedural. Notable for it's unreadability, it can be very effective for golfing purposes if used properly. Since Pyth is quite young, its features are constantly changing, and this document might be out of date for a few functions (Just check the source). Pyth is licensed under the `MIT license `_ 5 | 6 | 1.1. How to Start Programming in Pyth 7 | ===================================== 8 | Now that you know a little about Pyth, you must be wondering how on earth to start programming in it. Well there are a few options. You could install it on you machine by cloning `the repository ` then adding this alias to your .bashrc:: 9 | 10 | alias pyth="python3 /pyth.py" 11 | 12 | (Windows users, you'll have to use the PATH and call ``pyth.py``) 13 | 14 | But the method we will be using in the tutorial, and the suggested one, is to use the online interpreter at http://pyth.herokuapp.com. This provides a programming environment (with a handy function cheat-sheet) with places in which to put code and input. The code is executed on the server and sent back to the webpage. The examples won't be much different if you decide to install the interpreter yourself, and in fact this will become necessary later down the road, when we start conducting "unsafe" operations which allow for arbitrary execution of code. More detailed explanations will be provided then. 15 | 16 | Now let's start programming. 17 | 18 | 1.2. Hello World! 19 | ================= 20 | 21 | A customary start to programming tutorials is the "Hello World Program" which consists of printing out the text "Hello World!". We will be doing this task as our first example. Now, since Pyth *is* a golfing language, lets golf it, and in the process demonstrate some key features of Pyth. So without further ado, here is our first program:: 22 | 23 | "Hello World! 24 | 25 | Type this into the code textbox, and leaving the input box empty, click the run button and see what happens. The results (in the output box) should look something like this:: 26 | 27 | Hello World! 28 | 29 | Well that went pretty much as expected, but if you have any experience with other programming languages, you'll notice a few interesting things about the program. 30 | 31 | #. Printing is implicit (Just name a value or identifier and it will be printed). 32 | #. Quotes are automatically closed at the end of the program. 33 | 34 | These features are obviously beneficially for reducing the length of your programs. Another thing you should know early on if you decide to go experimenting on your own is that programs in Pyth are only one line long. The other lines are discarded and statement separation is achieved through semicolons: ``;``. 35 | 36 | Next up is learning more about the language. -------------------------------------------------------------------------------- /docs/_build/html/_sources/index.txt: -------------------------------------------------------------------------------- 1 | Welcome to Pyth's documentation! 2 | ================================ 3 | 4 | Pyth is an extremely concise language used for golfing. Try it here at: https://pyth.herokuapp.com. This is a tutorial/documentation/language-specification for it. 5 | 6 | Contents: 7 | 8 | .. toctree:: 9 | :maxdepth: 3 10 | 11 | getting-started 12 | details 13 | simple-programs 14 | simple-programs2 15 | spec_vars 16 | spec_control 17 | spec_math 18 | spec_comp 19 | spec_seq 20 | spec_func 21 | spec_misc 22 | 23 | Indices and tables 24 | ================== 25 | 26 | * :ref:`genindex` 27 | * :ref:`modindex` 28 | * :ref:`search` 29 | 30 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/simple-programs2.txt: -------------------------------------------------------------------------------- 1 | 4. Some Simple Programs - Part II 2 | ********************************* 3 | 4 | aasd 5 | 6 | Prime 7 | ===== 8 | 9 | A common toy problem given to programmers is the task of finding all the prime numbers under some positive integer ``N``. Writing a solution to this problem and then attempting to golf it will demonstrate many of Pyth's features in a natural way. So let's get started. A prime number is a number whose only factors are one and itself. There are many ways to check if a number is prime or not, involving looping through all numbers less than its square root, but since Pyth is meant to be used for golfing and not algorithmic exercises, we can use one of Pyth's operators, the prime factorization operator. -------------------------------------------------------------------------------- /docs/_build/html/_sources/spec_comp.txt: -------------------------------------------------------------------------------- 1 | 8. The Language Specification - Comparisons 2 | ******************************************* 3 | 4 | This section contains a list of comparison operators. They all take two arguments and return a boolean value depending on the relationship between the two arguments. 5 | 6 | 8.1. "<" - Is Less Than 7 | ======================= 8 | 9 | **Arity: 2** 10 | 11 | 8.1.1. Any a, Same Type b: Less Than 12 | ------------------------------------ 13 | 14 | If a and b are of the same type, checks if ``a`` is less than ``b`` by whatever way that type is compared (e.g. Numbers by size, strings lexicographically). 15 | 16 | Ex:: 17 | 18 | ================================================== 19 | <5T"abcdefgh"5 36 | ================================================== 37 | Pprint("\n",gt("abcdefgh",5)) 38 | ================================================== 39 | fgh 40 | 41 | 8.1.3. Set a, Set b: Is Subset 42 | ------------------------------ 43 | 44 | Checks if set ``a`` is a subset of set ``b``. This means that it checks if set ``b`` contains all the elements of set ``a``. 45 | 46 | Ex:: 47 | 48 | ================================================== 49 | <{[1 2){[1 2 3) 50 | ================================================== 51 | Pprint("\n",lt(Pset(Plist(1,(2))),Pset(Plist(1,(2),(3))))) 52 | ================================================== 53 | True 54 | 55 | 8.2. "q" - Is Equal To 56 | ====================== 57 | 58 | **Arity: 2** 59 | 60 | This checks if the two values are equal to each other. This is the same as the Python ``==``. 61 | 62 | Ex:: 63 | 64 | ================================================== 65 | qT5qTT 66 | ================================================== 67 | Pprint("\n",equal(T,5)) 68 | Pprint("\n",equal(T,T)) 69 | ================================================== 70 | False 71 | True 72 | 73 | 8.3. ">" - Is Greater Than 74 | ========================== 75 | 76 | **Arity: 2** 77 | 78 | 8.3.1 Any a, Same Type b: Greater Than 79 | -------------------------------------- 80 | 81 | This checks if ``a`` is greater than ``b``. Uses the same type of comparisons as ``<`` 82 | 83 | Ex:: 84 | 85 | ================================================== 86 | >5T>T5 87 | ================================================== 88 | Pprint("\n",gt(5,T)) 89 | Pprint("\n",gt(T,5)) 90 | ================================================== 91 | False 92 | True 93 | 94 | 8.3.2 Seq a, Int b: Slice From 95 | ------------------------------ 96 | 97 | This takes a slice of sequence ``a`` from index ``b`` onwards till the end. This is equivalent to the Python ``a[b:]``. The slice is not inclusive of the element at index ``b``. 98 | 99 | Ex:: 100 | 101 | <"abcdefgh"5 102 | ================================================== 103 | Pprint("\n",lt("abcdefgh",5)) 104 | ================================================== 105 | abcde 106 | 107 | 8.3.3. Set a, Set b: Is Superset 108 | -------------------------------- 109 | 110 | Checks is set ``a`` is a superset of set ``b``. This means that it checks if set ``a`` contains all the elements of set ``b``. This does not return True if the two sets are equal. 111 | 112 | Ex:: 113 | 114 | ================================================== 115 | >{[1 2 3){[1 2) 116 | ================================================== 117 | Pprint("\n",gt(Pset(Plist(1,(2),(3))),Pset(Plist(1,(2))))) 118 | ================================================== 119 | True 120 | 121 | 8.4. "n" - Not Equal To 122 | ======================= 123 | 124 | **Arity: 2** 125 | 126 | Checks if the two elements are not equal to each other. This is equivalent to Python's "!=". 127 | 128 | Ex:: 129 | 130 | ================================================== 131 | nT5nTT 132 | ================================================== 133 | Pprint("\n",ne(T,5)) 134 | Pprint("\n",ne(T,T)) 135 | ================================================== 136 | True 137 | False 138 | 139 | 8.5. "g" - Is Greater Than or Equal To 140 | ====================================== 141 | 142 | **Arity: 2** 143 | 144 | 8.5.1. Any a, Same Type b: Greater Than or Equal To 145 | --------------------------------------------------- 146 | 147 | Checks if ``a`` is greater than or equal to ``b``. 148 | 149 | Ex:: 150 | 151 | ================================================== 152 | gT5gTTg5T 153 | ================================================== 154 | Pprint("\n",gte(T,5)) 155 | Pprint("\n",gte(T,T)) 156 | Pprint("\n",gte(5,T)) 157 | ================================================== 158 | True 159 | True 160 | False 161 | 162 | 8.5.2. Set a, Set b: Superset or Equal 163 | -------------------------------------- 164 | 165 | Checks if set ``a`` is a superset of set ``b`` or equal to set ``b``. 166 | 167 | Ex:: 168 | 169 | ================================================== 170 | g{[1 2 3){[2 3)g{[1 2 3){[1 2 3) 171 | ================================================== 172 | Pprint("\n",gte(Pset(Plist(1,(2),(3))),Pset(Plist(2,(3))))) 173 | Pprint("\n",gte(Pset(Plist(1,(2),(3))),Pset(Plist(1,(2),(3))))) 174 | ================================================== 175 | True 176 | True 177 | 178 | 8.6. "}" - Contains 179 | =================== 180 | 181 | **Arity: 2** 182 | 183 | Checks if the second argument, a sequence, contains the first argument. Is equivalent to the Python ``in`` operator. 184 | 185 | Ex:: 186 | 187 | ================================================== 188 | }\a"abc" 189 | ================================================== 190 | Pprint("\n",("a" in "abc")) 191 | ================================================== 192 | True -------------------------------------------------------------------------------- /docs/_build/html/_sources/spec_control.txt: -------------------------------------------------------------------------------- 1 | 6. The Language Specification - Control Flow 2 | ******************************************** 3 | 4 | This section of the language specifications deals with control flow. It contains the keywords and the operators that affect which parts of the programs are run. 5 | 6 | 6.1. "#" - Exception Loop 7 | ========================= 8 | 9 | **Arity: Unbounded** 10 | 11 | This is the only form of error handling available in Pyth. It runs an infinite while loop until an error is reached, then breaks out of the loop. 12 | 13 | Ex:: 14 | 15 | ================================================== 16 | #/100.T=T-T1 17 | ================================================== 18 | while True: 19 | try: 20 | Pprint("\n",div(100.,T)) 21 | T=copy(minus(T,1)) 22 | 23 | except: 24 | break 25 | ================================================== 26 | 10 27 | 11 28 | 12 29 | 14 30 | 16 31 | 20 32 | 25 33 | 33 34 | 50 35 | 100 36 | 37 | 6.2. ")" - Close Parenthesis 38 | ============================ 39 | 40 | This ends one unbounded arity. Control flow like ``if`` or ``for`` all open up an unbounded arity and this closes one of them. Also works on tuple ad list constructors. 41 | 42 | Ex:: 43 | 44 | ================================================== 45 | I>5T"Hello")"Bye" 46 | ================================================== 47 | if gt(5,T): 48 | Pprint("\n","Hello") 49 | Pprint("\n","Bye") 50 | ================================================== 51 | Bye 52 | 53 | 6.3. ";" - End Statement 54 | ======================== 55 | 56 | This is effectively an infinite amount of close parenthesis. This closes how many ever aritys are needed to start completely afresh. This is the replacement for multiple lines in Pyth. 57 | 58 | Ex:: 59 | 60 | ================================================== 61 | V5I>5T"Hello";"Bye" 62 | ================================================== 63 | for N in urange(5): 64 | if gt(5,T): 65 | Pprint("\n","Hello") 66 | Pprint("\n","Bye") 67 | ================================================== 68 | Bye 69 | 70 | 6.4. "B" - Break 71 | ================ 72 | 73 | This translates into the break keyword in Python. It is used to break out of both for and while loops (and also the infinite error loop). Pyth does not have a continue statement. Break automatically puts a close parenthesis after itself. 74 | 75 | Ex:: 76 | 77 | ================================================== 78 | #ZI>ZTB~Z1 79 | ================================================== 80 | while True: 81 | try: 82 | Pprint("\n",Z) 83 | if gt(Z,T): 84 | break 85 | Z+=1 86 | 87 | except: 88 | break 89 | ================================================== 90 | 0 91 | 1 92 | 2 93 | 3 94 | 4 95 | 5 96 | 6 97 | 7 98 | 8 99 | 9 100 | 10 101 | 11 102 | 103 | 6.5. "E" - The Else Statement 104 | ============================= 105 | 106 | **Arity: Unbounded** 107 | 108 | This is the else part of the if-else construct. It is pretty self explanatory and works like it would in any programing langaue. This can also be used as part of a `for-else or while-else `_ construct. The If still needs a close parenthesis after it. 109 | 110 | Ex:: 111 | 112 | ================================================== 113 | I>5T"It's greater")E"It's less than" 114 | ================================================== 115 | if gt(5,T): 116 | Pprint("\n","It's greater") 117 | else: 118 | Pprint("\n","It's less than") 119 | ================================================== 120 | It's less than 121 | 122 | 6.6. "F" - The For Loop 123 | ======================= 124 | 125 | **Arity: Variable, Sequence, Unbounded** 126 | 127 | This is the ubiquitous for loop. It works like it does in Python, with it looping through a sequence. 128 | 129 | Ex:: 130 | 131 | ================================================== 132 | FNU5N 133 | ================================================== 134 | for N in urange(5): 135 | Pprint("\n",N) 136 | ================================================== 137 | 0 138 | 1 139 | 2 140 | 3 141 | 4 142 | 143 | 6.7. "I" - The If Statement 144 | =========================== 145 | 146 | **Arity: Boolean, Unbounded** 147 | 148 | This is the If statement from Python. If the first argument is truthy, it executes the code, else it does nothing. Requires a close paren unless it is the last piece of code. 149 | 150 | Ex:: 151 | 152 | ================================================== 153 | I>5T"The Universe Has Exploded" 154 | ================================================== 155 | if gt(5,T): 156 | Pprint("\n","The Universe Has Exploded") 157 | ================================================== 158 | 159 | 6.8. "V" - Unary-Range-Loop 160 | =========================== 161 | 162 | **Arity: Integer, Unbounded** 163 | 164 | It is the shortest way to do a for loop. It takes an integer and translates it self to ``FNU``. This makes it execute the following code that many times, with ``N`` being the loop variable. 165 | 166 | Ex:: 167 | 168 | ================================================== 169 | VT*NN 170 | ================================================== 171 | for N in urange(T): 172 | Pprint("\n",times(N,N)) 173 | ================================================== 174 | 0 175 | 1 176 | 4 177 | 9 178 | 16 179 | 25 180 | 36 181 | 49 182 | 64 183 | 81 184 | 185 | 6.9. "W" - While Loop 186 | ===================== 187 | 188 | **Arity: Boolean, Unbounded** 189 | 190 | This the while loop construct from Python. It executes the following code until the condition becomes False. 191 | 192 | Ex:: 193 | 194 | ================================================== 195 | W a.headerlink, 194 | h2:hover > a.headerlink, 195 | h3:hover > a.headerlink, 196 | h4:hover > a.headerlink, 197 | h5:hover > a.headerlink, 198 | h6:hover > a.headerlink, 199 | dt:hover > a.headerlink { 200 | visibility: visible; 201 | } 202 | 203 | div.body p.caption { 204 | text-align: inherit; 205 | } 206 | 207 | div.body td { 208 | text-align: left; 209 | } 210 | 211 | .field-list ul { 212 | padding-left: 1em; 213 | } 214 | 215 | .first { 216 | margin-top: 0 !important; 217 | } 218 | 219 | p.rubric { 220 | margin-top: 30px; 221 | font-weight: bold; 222 | } 223 | 224 | img.align-left, .figure.align-left, object.align-left { 225 | clear: left; 226 | float: left; 227 | margin-right: 1em; 228 | } 229 | 230 | img.align-right, .figure.align-right, object.align-right { 231 | clear: right; 232 | float: right; 233 | margin-left: 1em; 234 | } 235 | 236 | img.align-center, .figure.align-center, object.align-center { 237 | display: block; 238 | margin-left: auto; 239 | margin-right: auto; 240 | } 241 | 242 | .align-left { 243 | text-align: left; 244 | } 245 | 246 | .align-center { 247 | text-align: center; 248 | } 249 | 250 | .align-right { 251 | text-align: right; 252 | } 253 | 254 | /* -- sidebars -------------------------------------------------------------- */ 255 | 256 | div.sidebar { 257 | margin: 0 0 0.5em 1em; 258 | border: 1px solid #ddb; 259 | padding: 7px 7px 0 7px; 260 | background-color: #ffe; 261 | width: 40%; 262 | float: right; 263 | } 264 | 265 | p.sidebar-title { 266 | font-weight: bold; 267 | } 268 | 269 | /* -- topics ---------------------------------------------------------------- */ 270 | 271 | div.topic { 272 | border: 1px solid #ccc; 273 | padding: 7px 7px 0 7px; 274 | margin: 10px 0 10px 0; 275 | } 276 | 277 | p.topic-title { 278 | font-size: 1.1em; 279 | font-weight: bold; 280 | margin-top: 10px; 281 | } 282 | 283 | /* -- admonitions ----------------------------------------------------------- */ 284 | 285 | div.admonition { 286 | margin-top: 10px; 287 | margin-bottom: 10px; 288 | padding: 7px; 289 | } 290 | 291 | div.admonition dt { 292 | font-weight: bold; 293 | } 294 | 295 | div.admonition dl { 296 | margin-bottom: 0; 297 | } 298 | 299 | p.admonition-title { 300 | margin: 0px 10px 5px 0px; 301 | font-weight: bold; 302 | } 303 | 304 | div.body p.centered { 305 | text-align: center; 306 | margin-top: 25px; 307 | } 308 | 309 | /* -- tables ---------------------------------------------------------------- */ 310 | 311 | table.docutils { 312 | border: 0; 313 | border-collapse: collapse; 314 | } 315 | 316 | table.docutils td, table.docutils th { 317 | padding: 1px 8px 1px 5px; 318 | border-top: 0; 319 | border-left: 0; 320 | border-right: 0; 321 | border-bottom: 1px solid #aaa; 322 | } 323 | 324 | table.field-list td, table.field-list th { 325 | border: 0 !important; 326 | } 327 | 328 | table.footnote td, table.footnote th { 329 | border: 0 !important; 330 | } 331 | 332 | th { 333 | text-align: left; 334 | padding-right: 5px; 335 | } 336 | 337 | table.citation { 338 | border-left: solid 1px gray; 339 | margin-left: 1px; 340 | } 341 | 342 | table.citation td { 343 | border-bottom: none; 344 | } 345 | 346 | /* -- other body styles ----------------------------------------------------- */ 347 | 348 | ol.arabic { 349 | list-style: decimal; 350 | } 351 | 352 | ol.loweralpha { 353 | list-style: lower-alpha; 354 | } 355 | 356 | ol.upperalpha { 357 | list-style: upper-alpha; 358 | } 359 | 360 | ol.lowerroman { 361 | list-style: lower-roman; 362 | } 363 | 364 | ol.upperroman { 365 | list-style: upper-roman; 366 | } 367 | 368 | dl { 369 | margin-bottom: 15px; 370 | } 371 | 372 | dd p { 373 | margin-top: 0px; 374 | } 375 | 376 | dd ul, dd table { 377 | margin-bottom: 10px; 378 | } 379 | 380 | dd { 381 | margin-top: 3px; 382 | margin-bottom: 10px; 383 | margin-left: 30px; 384 | } 385 | 386 | dt:target, .highlighted { 387 | background-color: #fbe54e; 388 | } 389 | 390 | dl.glossary dt { 391 | font-weight: bold; 392 | font-size: 1.1em; 393 | } 394 | 395 | .field-list ul { 396 | margin: 0; 397 | padding-left: 1em; 398 | } 399 | 400 | .field-list p { 401 | margin: 0; 402 | } 403 | 404 | .optional { 405 | font-size: 1.3em; 406 | } 407 | 408 | .versionmodified { 409 | font-style: italic; 410 | } 411 | 412 | .system-message { 413 | background-color: #fda; 414 | padding: 5px; 415 | border: 3px solid red; 416 | } 417 | 418 | .footnote:target { 419 | background-color: #ffa; 420 | } 421 | 422 | .line-block { 423 | display: block; 424 | margin-top: 1em; 425 | margin-bottom: 1em; 426 | } 427 | 428 | .line-block .line-block { 429 | margin-top: 0; 430 | margin-bottom: 0; 431 | margin-left: 1.5em; 432 | } 433 | 434 | .guilabel, .menuselection { 435 | font-family: sans-serif; 436 | } 437 | 438 | .accelerator { 439 | text-decoration: underline; 440 | } 441 | 442 | .classifier { 443 | font-style: oblique; 444 | } 445 | 446 | abbr, acronym { 447 | border-bottom: dotted 1px; 448 | cursor: help; 449 | } 450 | 451 | /* -- code displays --------------------------------------------------------- */ 452 | 453 | pre { 454 | overflow: auto; 455 | overflow-y: hidden; /* fixes display issues on Chrome browsers */ 456 | } 457 | 458 | td.linenos pre { 459 | padding: 5px 0px; 460 | border: 0; 461 | background-color: transparent; 462 | color: #aaa; 463 | } 464 | 465 | table.highlighttable { 466 | margin-left: 0.5em; 467 | } 468 | 469 | table.highlighttable td { 470 | padding: 0 0.5em 0 0.5em; 471 | } 472 | 473 | tt.descname { 474 | background-color: transparent; 475 | font-weight: bold; 476 | font-size: 1.2em; 477 | } 478 | 479 | tt.descclassname { 480 | background-color: transparent; 481 | } 482 | 483 | tt.xref, a tt { 484 | background-color: transparent; 485 | font-weight: bold; 486 | } 487 | 488 | h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { 489 | background-color: transparent; 490 | } 491 | 492 | .viewcode-link { 493 | float: right; 494 | } 495 | 496 | .viewcode-back { 497 | float: right; 498 | font-family: sans-serif; 499 | } 500 | 501 | div.viewcode-block:target { 502 | margin: -1px -10px; 503 | padding: 0 10px; 504 | } 505 | 506 | /* -- math display ---------------------------------------------------------- */ 507 | 508 | img.math { 509 | vertical-align: middle; 510 | } 511 | 512 | div.body div.math p { 513 | text-align: center; 514 | } 515 | 516 | span.eqno { 517 | float: right; 518 | } 519 | 520 | /* -- printout stylesheet --------------------------------------------------- */ 521 | 522 | @media print { 523 | div.document, 524 | div.documentwrapper, 525 | div.bodywrapper { 526 | margin: 0 !important; 527 | width: 100%; 528 | } 529 | 530 | div.sphinxsidebar, 531 | div.related, 532 | div.footer, 533 | #top-link { 534 | display: none; 535 | } 536 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/comment-close.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/comment.png -------------------------------------------------------------------------------- /docs/_build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:"\f02d"}.icon-book:before{content:"\f02d"}.fa-caret-down:before{content:"\f0d7"}.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before{content:"\f0d8"}.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before{content:"\f0d9"}.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before{content:"\f0da"}.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}img{width:100%;height:auto}} 2 | -------------------------------------------------------------------------------- /docs/_build/html/_static/default.css: -------------------------------------------------------------------------------- 1 | /* 2 | * default.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- default theme. 6 | * 7 | * :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: sans-serif; 18 | font-size: 100%; 19 | background-color: #11303d; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: #1c4e63; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: #ffffff; 40 | color: #000000; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | div.footer { 45 | color: #ffffff; 46 | width: 100%; 47 | padding: 9px 0 9px 0; 48 | text-align: center; 49 | font-size: 75%; 50 | } 51 | 52 | div.footer a { 53 | color: #ffffff; 54 | text-decoration: underline; 55 | } 56 | 57 | div.related { 58 | background-color: #133f52; 59 | line-height: 30px; 60 | color: #ffffff; 61 | } 62 | 63 | div.related a { 64 | color: #ffffff; 65 | } 66 | 67 | div.sphinxsidebar { 68 | } 69 | 70 | div.sphinxsidebar h3 { 71 | font-family: 'Trebuchet MS', sans-serif; 72 | color: #ffffff; 73 | font-size: 1.4em; 74 | font-weight: normal; 75 | margin: 0; 76 | padding: 0; 77 | } 78 | 79 | div.sphinxsidebar h3 a { 80 | color: #ffffff; 81 | } 82 | 83 | div.sphinxsidebar h4 { 84 | font-family: 'Trebuchet MS', sans-serif; 85 | color: #ffffff; 86 | font-size: 1.3em; 87 | font-weight: normal; 88 | margin: 5px 0 0 0; 89 | padding: 0; 90 | } 91 | 92 | div.sphinxsidebar p { 93 | color: #ffffff; 94 | } 95 | 96 | div.sphinxsidebar p.topless { 97 | margin: 5px 10px 10px 10px; 98 | } 99 | 100 | div.sphinxsidebar ul { 101 | margin: 10px; 102 | padding: 0; 103 | color: #ffffff; 104 | } 105 | 106 | div.sphinxsidebar a { 107 | color: #98dbcc; 108 | } 109 | 110 | div.sphinxsidebar input { 111 | border: 1px solid #98dbcc; 112 | font-family: sans-serif; 113 | font-size: 1em; 114 | } 115 | 116 | 117 | 118 | /* -- hyperlink styles ------------------------------------------------------ */ 119 | 120 | a { 121 | color: #355f7c; 122 | text-decoration: none; 123 | } 124 | 125 | a:visited { 126 | color: #355f7c; 127 | text-decoration: none; 128 | } 129 | 130 | a:hover { 131 | text-decoration: underline; 132 | } 133 | 134 | 135 | 136 | /* -- body styles ----------------------------------------------------------- */ 137 | 138 | div.body h1, 139 | div.body h2, 140 | div.body h3, 141 | div.body h4, 142 | div.body h5, 143 | div.body h6 { 144 | font-family: 'Trebuchet MS', sans-serif; 145 | background-color: #f2f2f2; 146 | font-weight: normal; 147 | color: #20435c; 148 | border-bottom: 1px solid #ccc; 149 | margin: 20px -20px 10px -20px; 150 | padding: 3px 0 3px 10px; 151 | } 152 | 153 | div.body h1 { margin-top: 0; font-size: 200%; } 154 | div.body h2 { font-size: 160%; } 155 | div.body h3 { font-size: 140%; } 156 | div.body h4 { font-size: 120%; } 157 | div.body h5 { font-size: 110%; } 158 | div.body h6 { font-size: 100%; } 159 | 160 | a.headerlink { 161 | color: #c60f0f; 162 | font-size: 0.8em; 163 | padding: 0 4px 0 4px; 164 | text-decoration: none; 165 | } 166 | 167 | a.headerlink:hover { 168 | background-color: #c60f0f; 169 | color: white; 170 | } 171 | 172 | div.body p, div.body dd, div.body li { 173 | text-align: justify; 174 | line-height: 130%; 175 | } 176 | 177 | div.admonition p.admonition-title + p { 178 | display: inline; 179 | } 180 | 181 | div.admonition p { 182 | margin-bottom: 5px; 183 | } 184 | 185 | div.admonition pre { 186 | margin-bottom: 5px; 187 | } 188 | 189 | div.admonition ul, div.admonition ol { 190 | margin-bottom: 5px; 191 | } 192 | 193 | div.note { 194 | background-color: #eee; 195 | border: 1px solid #ccc; 196 | } 197 | 198 | div.seealso { 199 | background-color: #ffc; 200 | border: 1px solid #ff6; 201 | } 202 | 203 | div.topic { 204 | background-color: #eee; 205 | } 206 | 207 | div.warning { 208 | background-color: #ffe4e4; 209 | border: 1px solid #f66; 210 | } 211 | 212 | p.admonition-title { 213 | display: inline; 214 | } 215 | 216 | p.admonition-title:after { 217 | content: ":"; 218 | } 219 | 220 | pre { 221 | padding: 5px; 222 | background-color: #eeffcc; 223 | color: #333333; 224 | line-height: 120%; 225 | border: 1px solid #ac9; 226 | border-left: none; 227 | border-right: none; 228 | } 229 | 230 | tt { 231 | background-color: #ecf0f3; 232 | padding: 0 1px 0 1px; 233 | font-size: 0.95em; 234 | } 235 | 236 | th { 237 | background-color: #ede; 238 | } 239 | 240 | .warning tt { 241 | background: #efc2c2; 242 | } 243 | 244 | .note tt { 245 | background: #d6d6d6; 246 | } 247 | 248 | .viewcode-back { 249 | font-family: sans-serif; 250 | } 251 | 252 | div.viewcode-block:target { 253 | background-color: #f4debf; 254 | border-top: 1px solid #ac9; 255 | border-bottom: 1px solid #ac9; 256 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s == 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node) { 70 | if (node.nodeType == 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { 74 | var span = document.createElement("span"); 75 | span.className = className; 76 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 77 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 78 | document.createTextNode(val.substr(pos + text.length)), 79 | node.nextSibling)); 80 | node.nodeValue = val.substr(0, pos); 81 | } 82 | } 83 | else if (!jQuery(node).is("button, select, textarea")) { 84 | jQuery.each(node.childNodes, function() { 85 | highlight(this); 86 | }); 87 | } 88 | } 89 | return this.each(function() { 90 | highlight(this); 91 | }); 92 | }; 93 | 94 | /** 95 | * Small JavaScript module for the documentation. 96 | */ 97 | var Documentation = { 98 | 99 | init : function() { 100 | this.fixFirefoxAnchorBug(); 101 | this.highlightSearchWords(); 102 | this.initIndexTable(); 103 | }, 104 | 105 | /** 106 | * i18n support 107 | */ 108 | TRANSLATIONS : {}, 109 | PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, 110 | LOCALE : 'unknown', 111 | 112 | // gettext and ngettext don't access this so that the functions 113 | // can safely bound to a different name (_ = Documentation.gettext) 114 | gettext : function(string) { 115 | var translated = Documentation.TRANSLATIONS[string]; 116 | if (typeof translated == 'undefined') 117 | return string; 118 | return (typeof translated == 'string') ? translated : translated[0]; 119 | }, 120 | 121 | ngettext : function(singular, plural, n) { 122 | var translated = Documentation.TRANSLATIONS[singular]; 123 | if (typeof translated == 'undefined') 124 | return (n == 1) ? singular : plural; 125 | return translated[Documentation.PLURALEXPR(n)]; 126 | }, 127 | 128 | addTranslations : function(catalog) { 129 | for (var key in catalog.messages) 130 | this.TRANSLATIONS[key] = catalog.messages[key]; 131 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 132 | this.LOCALE = catalog.locale; 133 | }, 134 | 135 | /** 136 | * add context elements like header anchor links 137 | */ 138 | addContextElements : function() { 139 | $('div[id] > :header:first').each(function() { 140 | $('\u00B6'). 141 | attr('href', '#' + this.id). 142 | attr('title', _('Permalink to this headline')). 143 | appendTo(this); 144 | }); 145 | $('dt[id]').each(function() { 146 | $('\u00B6'). 147 | attr('href', '#' + this.id). 148 | attr('title', _('Permalink to this definition')). 149 | appendTo(this); 150 | }); 151 | }, 152 | 153 | /** 154 | * workaround a firefox stupidity 155 | */ 156 | fixFirefoxAnchorBug : function() { 157 | if (document.location.hash && $.browser.mozilla) 158 | window.setTimeout(function() { 159 | document.location.href += ''; 160 | }, 10); 161 | }, 162 | 163 | /** 164 | * highlight the search words provided in the url in the text 165 | */ 166 | highlightSearchWords : function() { 167 | var params = $.getQueryParameters(); 168 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 169 | if (terms.length) { 170 | var body = $('div.body'); 171 | window.setTimeout(function() { 172 | $.each(terms, function() { 173 | body.highlightText(this.toLowerCase(), 'highlighted'); 174 | }); 175 | }, 10); 176 | $('') 178 | .appendTo($('#searchbox')); 179 | } 180 | }, 181 | 182 | /** 183 | * init the domain index toggle buttons 184 | */ 185 | initIndexTable : function() { 186 | var togglers = $('img.toggler').click(function() { 187 | var src = $(this).attr('src'); 188 | var idnum = $(this).attr('id').substr(7); 189 | $('tr.cg-' + idnum).toggle(); 190 | if (src.substr(-9) == 'minus.png') 191 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 192 | else 193 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 194 | }).css('display', ''); 195 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 196 | togglers.click(); 197 | } 198 | }, 199 | 200 | /** 201 | * helper function to hide the search marks again 202 | */ 203 | hideSearchWords : function() { 204 | $('#searchbox .highlight-link').fadeOut(300); 205 | $('span.highlighted').removeClass('highlighted'); 206 | }, 207 | 208 | /** 209 | * make the url absolute 210 | */ 211 | makeURL : function(relativeURL) { 212 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 213 | }, 214 | 215 | /** 216 | * get the current relative url 217 | */ 218 | getCurrentURL : function() { 219 | var path = document.location.pathname; 220 | var parts = path.split(/\//); 221 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 222 | if (this == '..') 223 | parts.pop(); 224 | }); 225 | var url = parts.join('/'); 226 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 227 | } 228 | }; 229 | 230 | // quick alias for translations 231 | _ = Documentation.gettext; 232 | 233 | $(document).ready(function() { 234 | Documentation.init(); 235 | }); 236 | -------------------------------------------------------------------------------- /docs/_build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/down.png -------------------------------------------------------------------------------- /docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | $( document ).ready(function() { 2 | // Shift nav in mobile when clicking the menu. 3 | $(document).on('click', "[data-toggle='wy-nav-top']", function() { 4 | $("[data-toggle='wy-nav-shift']").toggleClass("shift"); 5 | $("[data-toggle='rst-versions']").toggleClass("shift"); 6 | }); 7 | // Close menu when you click a link. 8 | $(document).on('click', ".wy-menu-vertical .current ul li a", function() { 9 | $("[data-toggle='wy-nav-shift']").removeClass("shift"); 10 | $("[data-toggle='rst-versions']").toggleClass("shift"); 11 | }); 12 | $(document).on('click', "[data-toggle='rst-current-version']", function() { 13 | $("[data-toggle='rst-versions']").toggleClass("shift-up"); 14 | }); 15 | // Make tables responsive 16 | $("table.docutils:not(.field-list)").wrap("
"); 17 | }); 18 | 19 | window.SphinxRtdTheme = (function (jquery) { 20 | var stickyNav = (function () { 21 | var navBar, 22 | win, 23 | stickyNavCssClass = 'stickynav', 24 | applyStickNav = function () { 25 | if (navBar.height() <= win.height()) { 26 | navBar.addClass(stickyNavCssClass); 27 | } else { 28 | navBar.removeClass(stickyNavCssClass); 29 | } 30 | }, 31 | enable = function () { 32 | applyStickNav(); 33 | win.on('resize', applyStickNav); 34 | }, 35 | init = function () { 36 | navBar = jquery('nav.wy-nav-side:first'); 37 | win = jquery(window); 38 | }; 39 | jquery(init); 40 | return { 41 | enable : enable 42 | }; 43 | }()); 44 | return { 45 | StickyNav : stickyNav 46 | }; 47 | }($)); 48 | -------------------------------------------------------------------------------- /docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 8 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 9 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 10 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 11 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 12 | .highlight .ge { font-style: italic } /* Generic.Emph */ 13 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 14 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 15 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 16 | .highlight .go { color: #333333 } /* Generic.Output */ 17 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 18 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 19 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 20 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 21 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 22 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 23 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 24 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 25 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 26 | .highlight .kt { color: #902000 } /* Keyword.Type */ 27 | .highlight .m { color: #208050 } /* Literal.Number */ 28 | .highlight .s { color: #4070a0 } /* Literal.String */ 29 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 30 | .highlight .nb { color: #007020 } /* Name.Builtin */ 31 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 32 | .highlight .no { color: #60add5 } /* Name.Constant */ 33 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 34 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 35 | .highlight .ne { color: #007020 } /* Name.Exception */ 36 | .highlight .nf { color: #06287e } /* Name.Function */ 37 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 38 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 39 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 40 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 41 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 42 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 44 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 45 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 46 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 47 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 48 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 49 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 50 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 51 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 52 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 53 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 54 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 55 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 56 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 57 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 58 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 59 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 60 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 61 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 62 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/_build/html/_static/sidebar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * sidebar.js 3 | * ~~~~~~~~~~ 4 | * 5 | * This script makes the Sphinx sidebar collapsible. 6 | * 7 | * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds 8 | * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton 9 | * used to collapse and expand the sidebar. 10 | * 11 | * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden 12 | * and the width of the sidebar and the margin-left of the document 13 | * are decreased. When the sidebar is expanded the opposite happens. 14 | * This script saves a per-browser/per-session cookie used to 15 | * remember the position of the sidebar among the pages. 16 | * Once the browser is closed the cookie is deleted and the position 17 | * reset to the default (expanded). 18 | * 19 | * :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 20 | * :license: BSD, see LICENSE for details. 21 | * 22 | */ 23 | 24 | $(function() { 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | // global elements used by the functions. 34 | // the 'sidebarbutton' element is defined as global after its 35 | // creation, in the add_sidebar_button function 36 | var bodywrapper = $('.bodywrapper'); 37 | var sidebar = $('.sphinxsidebar'); 38 | var sidebarwrapper = $('.sphinxsidebarwrapper'); 39 | 40 | // for some reason, the document has no sidebar; do not run into errors 41 | if (!sidebar.length) return; 42 | 43 | // original margin-left of the bodywrapper and width of the sidebar 44 | // with the sidebar expanded 45 | var bw_margin_expanded = bodywrapper.css('margin-left'); 46 | var ssb_width_expanded = sidebar.width(); 47 | 48 | // margin-left of the bodywrapper and width of the sidebar 49 | // with the sidebar collapsed 50 | var bw_margin_collapsed = '.8em'; 51 | var ssb_width_collapsed = '.8em'; 52 | 53 | // colors used by the current theme 54 | var dark_color = $('.related').css('background-color'); 55 | var light_color = $('.document').css('background-color'); 56 | 57 | function sidebar_is_collapsed() { 58 | return sidebarwrapper.is(':not(:visible)'); 59 | } 60 | 61 | function toggle_sidebar() { 62 | if (sidebar_is_collapsed()) 63 | expand_sidebar(); 64 | else 65 | collapse_sidebar(); 66 | } 67 | 68 | function collapse_sidebar() { 69 | sidebarwrapper.hide(); 70 | sidebar.css('width', ssb_width_collapsed); 71 | bodywrapper.css('margin-left', bw_margin_collapsed); 72 | sidebarbutton.css({ 73 | 'margin-left': '0', 74 | 'height': bodywrapper.height() 75 | }); 76 | sidebarbutton.find('span').text('»'); 77 | sidebarbutton.attr('title', _('Expand sidebar')); 78 | document.cookie = 'sidebar=collapsed'; 79 | } 80 | 81 | function expand_sidebar() { 82 | bodywrapper.css('margin-left', bw_margin_expanded); 83 | sidebar.css('width', ssb_width_expanded); 84 | sidebarwrapper.show(); 85 | sidebarbutton.css({ 86 | 'margin-left': ssb_width_expanded-12, 87 | 'height': bodywrapper.height() 88 | }); 89 | sidebarbutton.find('span').text('«'); 90 | sidebarbutton.attr('title', _('Collapse sidebar')); 91 | document.cookie = 'sidebar=expanded'; 92 | } 93 | 94 | function add_sidebar_button() { 95 | sidebarwrapper.css({ 96 | 'float': 'left', 97 | 'margin-right': '0', 98 | 'width': ssb_width_expanded - 28 99 | }); 100 | // create the button 101 | sidebar.append( 102 | '
«
' 103 | ); 104 | var sidebarbutton = $('#sidebarbutton'); 105 | light_color = sidebarbutton.css('background-color'); 106 | // find the height of the viewport to center the '<<' in the page 107 | var viewport_height; 108 | if (window.innerHeight) 109 | viewport_height = window.innerHeight; 110 | else 111 | viewport_height = $(window).height(); 112 | sidebarbutton.find('span').css({ 113 | 'display': 'block', 114 | 'margin-top': (viewport_height - sidebar.position().top - 20) / 2 115 | }); 116 | 117 | sidebarbutton.click(toggle_sidebar); 118 | sidebarbutton.attr('title', _('Collapse sidebar')); 119 | sidebarbutton.css({ 120 | 'color': '#FFFFFF', 121 | 'border-left': '1px solid ' + dark_color, 122 | 'font-size': '1.2em', 123 | 'cursor': 'pointer', 124 | 'height': bodywrapper.height(), 125 | 'padding-top': '1px', 126 | 'margin-left': ssb_width_expanded - 12 127 | }); 128 | 129 | sidebarbutton.hover( 130 | function () { 131 | $(this).css('background-color', dark_color); 132 | }, 133 | function () { 134 | $(this).css('background-color', light_color); 135 | } 136 | ); 137 | } 138 | 139 | function set_position_from_cookie() { 140 | if (!document.cookie) 141 | return; 142 | var items = document.cookie.split(';'); 143 | for(var k=0; k2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | -------------------------------------------------------------------------------- /docs/_build/html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/up-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/_static/up.png -------------------------------------------------------------------------------- /docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /docs/_build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({envversion:42,terms:{represent:5,all:[],code:[],scratch:8,alien:2,psort:10,concept:8,customari:[1,8],abil:6,follow:7,jflk:10,whose:4,decid:1,typeerror:8,depend:[3,10,8],ay5i:10,pprint:[2,3,7,5,8,9],young:1,tail:[],program:[],under:[],preprocess:5,sent:1,digit:10,sourc:1,everi:[10,5,2],string:[],straightforward:5,fals:[3,7],constructor:[],lkjg:10,veri:[8,1,5,9],untouch:10,implicitli:8,xt2:10,level:8,button:[1,8],list:[],factori:[],"try":[0,7,8,5],k5k:[],div:[7,2],initialis:9,upper:10,smaller:8,ten:[],natur:4,contructor:[],seper:[],sign:[8,5],consequ:10,zero:[],ubiquit:7,pass:[10,8],further:[1,8],click:1,append:[],even:[8,5],index:3,what:[],abc:[3,10,5,7,2],equivl:[],appear:2,compar:3,preserv:2,neg:[8,2],sum:[5,2],abl:5,calcul:[10,2],access:9,abbrevi:2,version:[8,7],conduct:1,ever:[7,5],method:[1,5],whatev:3,gener:2,here:[0,8,1,5,2],middl:10,let:[4,1,8,5],path:1,becom:[10,1,7],implicit:[1,5],interpret:[1,8],box:1,search:0,unread:1,conta:[],convers:[],amount:[7,8,5],pick:2,action:8,extrem:0,chang:1,codegolf:[],abcd:3,decim:[8,2],appli:[5,2],modul:[0,8,10],prefer:5,bashrc:1,"boolean":[3,7],org:[],instal:1,decrement:[],should:[1,5],select:[8,2],fnr1tn:[],from:[],would:[7,8,5],doubl:[],two:[3,10,5,8,2],next:[8,1,5,10,9],few:[1,9],call:[1,8,5],"_25":[8,2],type:[],until:[3,10,7,5],more:[],sort:[],acc:2,capit:[],peopl:5,aca:2,notic:[1,8,5],pnot:5,flag:8,oop:5,examin:5,hold:5,effort:8,must:1,logarithm:10,none:10,join:[],augment:[],alia:1,raw_input:5,work:[10,7,8,5],flk:10,obvious:1,can:[1,2,4,5,8,7],learn:[1,8,5],cac:2,cab:2,caa:2,purpos:1,root:4,def:[10,5],control:[],process:[],stackexchang:[],accept:8,"5q1zt":7,liter:[],fibonacci:[],want:8,onlin:[1,8],plist:[3,10,2],alwai:8,surfac:8,end:[],newlin:9,sjfljdl:10,quot:[],anoth:[8,1,5,9],occur:2,divis:[],concis:0,memoiz:5,g1hghgq1:5,answer:[5,2],instead:[8,9],simpl:[],updat:[],map:6,product:[],lexicograph:3,qt5qtt:3,mess:[],dive:5,after:7,befor:8,wrong:8,lot:10,date:1,multipl:[],data:8,demonstr:[4,1,5],kjclkshfgl:10,e25:10,github:1,attempt:4,practic:5,divid:[10,2],element:[],caus:8,"switch":10,environ:[1,8],kzj1vqk:5,allow:[1,8,2],suggest:1,order:[9,2],aasd:4,origin:5,help:8,over:[10,5],through:[7,4,1,8,5],affect:7,still:[7,5],paramet:10,fir:[],write:[4,8,5],gte:[3,5],till:[],fix:[],better:5,jit:8,exchang:5,effot:[],bye:7,might:1,easier:5,them:[7,10,5,8,2],within:[10,2],"return":[3,10,5,2],fnrzhtn:5,thei:[3,5,2],handl:[7,5],noe:8,handi:[1,9],initi:9,"break":[],mention:9,p12:2,now:[1,8,5],name:[1,5],anyth:2,revers:[],separ:[10,1],achiev:1,whoos:[],truthi:[7,2],each:[3,10,9,5,2],debug:[8,5],fulli:1,went:[1,8],psum:10,truncat:[10,2],mean:[],subset:[],ghr1hq1:5,isaacg1:1,replac:[7,5],best:5,hard:8,continu:7,procedur:1,hlo:2,expect:[1,8,5],forgot:5,operand:8,our:[1,5],happen:[1,5],reduct:5,out:[10,1,8,7],variabl:[],abcdefghijklmnopqrstuvwxyz:9,unbound:[10,7],space:[],goe:8,miss:8,equivel:[10,7],fnr1htn:[],predefin:8,content:0,print:[1,8,5],occurr:[],correct:5,math:8,common:[4,8,5],ass:[],glimps:2,million:8,given:4,free:8,parenthesi:[],base:5,dictionari:[],asd:[],put:[1,7],plen:[10,7,9],gt5gttg5t:3,infix:8,featur:[4,1],shortest:7,puzzl:1,could:1,traceback:8,asjdasljl:10,local:8,alphab:9,thing:[],length:2,place:1,stone:[],assign:[],first:[],oper:[],rang:[],directli:9,aextrem:[],arrai:10,number:[],yourself:1,wasi:[],unlik:[10,1,5,9],alreadi:8,done:5,open:7,primari:9,safe_pyth:8,size:[3,8],differ:[],cartesian:[],sheet:1,exponenti:[],top:9,construct:7,abcabcabcabcabc:2,abcdefgh:3,toi:4,bbb:2,statement:[],recent:8,store:5,includ:5,ariti:[],option:[8,5],relationship:3,copi:[],"var":5,part:[],pars:10,exactli:5,than:[],hellohellohellohellohello:9,aaa:2,keyword:[7,8,5],aab:2,provid:[10,1],remov:[10,5],second:[3,10],charact:[8,9,5,10,2],urang:[7,10,5,9],were:5,posit:[10,4,8],seri:8,pre:9,comput:[10,5,2],argument:[10,2,3,7,8,5],raw:[],seed:5,increment:[],need:[7,5],seem:8,saw:8,minu:[7,5,2],bitwis:10,squar:4,equival:[3,10,2],ppcg:1,note:[10,5],also:[7,5,8,2],exampl:[1,8,5],take:[3,10,7,8,5],which:[10,1,2,5,8,7],taki:9,wonder:1,noth:7,singl:9,ct4:10,begin:[10,8],unless:7,aba:2,previou:5,reach:[10,7],abb:2,most:[8,1,5,9],letter:[10,9],deceler:5,xor:[],contain:[],splat:[],afresh:7,don:5,consist:1,later:[1,8],flow:[],doe:[10,2,3,7,8,5],repitit:[],semicolon:[1,5],usual:5,section:[3,7,2],fact:[1,5],shop:[],unari:[],think:5,golf:[0,4,1,10],cheat:1,text:1,random:8,setwis:[],earth:1,find:[4,5,2],primes_upp:2,involv:4,onli:[10,1,2,4,9,5,8,7],just:[9,8,1,5,2],pretti:[7,8,1,5,9],solut:[4,5],ztb:7,sut:10,dict:10,rich:8,factor:[],assign_at:[10,9],meant:[4,1],fibonacci_numb:[],unus:5,variou:10,get:[],express:[7,9],stop:10,obviou:5,increas:8,requir:[7,8,2],prime:[],aac:2,organ:2,fnu5n:7,bab:2,bac:2,baa:2,comma:10,where:5,unsaf:1,wiki:[],set:[],modulo:8,seq:[],mutabl:[],univers:7,see:[1,8,5],num:[],result:[10,1,2],close:[],analog:2,subject:5,infinit:[7,5],said:[8,9],extend:[],someth:1,wikipedia:8,label:2,enough:8,won:1,simplest:5,"import":[10,8,5],awai:8,experi:1,approach:[],aadjjllsss:10,accord:8,str:[],kei:1,lowercas:9,vhtn:5,len:[],solv:5,come:[8,9],addit:[],both:[7,10,5,8,2],fnu:[7,5],last:[],delimit:8,ffrom:[],howev:[10,5,8,9],equal:[],jt2:10,etc:10,tutori:[0,1],logic:[],fgh:3,com:[0,1],con:[],clone:1,lyt:7,simpli:2,technic:8,point:[8,2],"3by12":5,decument:[],bcdefghijklmnopqrstuvwxyz:10,fnuhtn:5,prang:5,duplic:10,quit:1,creat:[10,1],coupl:[],bbc:2,invers:2,empti:[],sinc:[10,1,4,9,8,5],much:[1,8,5],besid:8,valu:[3,8,9,5,2],interest:1,heeelllloooooooby:10,remaind:[10,2],exercis:[4,5],convert:[10,8],ani:[],input:[],stoneabcdefghijklmnopqrstuvwxyz:10,repetit:[],"case":5,multi:2,save:5,look:[1,8],webpag:1,strart:5,xut5z:10,act:5,defin:[5,8,2],"while":[],jbut:9,abov:5,error:[8,7],loop:[],subsect:2,have:[],almost:10,henc:5,non:10,itself:[4,7,9],pset:[3,10,2],skjfl:[],receiv:2,alphabet:[],make:[10,7,8,5],shorten:5,same:[],shorter:[5,8,9],python:[],split:[],auto:[],start:[],complet:[7,5,9],http:[0,1],effect:[7,1,2],isaacg:1,n5n:5,rais:2,user:1,glanc:8,divison:[],aka:8,expand:5,built:10,lower:[10,5],task:[4,1],knk:5,macro:8,well:[1,8],without:[1,5],command:5,thi:[0,1,2,3,4,5,6,7,8,9,10],programm:4,cca:2,self:[7,9],ccc:2,ccb:2,explan:1,identifi:1,nt5ntt:3,execut:[1,8,7],less:[],jkut:9,file:8,polish:8,powerset:5,languag:[],superset:[],easi:[8,5],onward:3,had:5,except:[],littl:1,chees:[],add:[5,8,9],valid:8,python3:1,versa:10,ado:1,expon:2,explanatori:[7,9],match:10,earli:1,format:[],read:8,g1hgh:5,piec:7,arbritrai:[],know:1,recurs:[],licens:1,mod:2,outright:5,like:[10,1,2,9,5,8,7],arbitrari:[1,2],whitespac:10,negat:[],modulu:[],mit:1,benefit:8,necessari:1,either:2,bunch:8,output:[10,1,8,5],page:0,right:8,deal:[10,6,7],arguement:10,some:[],back:1,intern:10,literal_ev:[5,9],integ:[10,4,7,8,2],server:1,ppow:[9,8,2],slice:[],yike:5,k1fnr1hq:5,normal:[10,2],definit:10,token:[],per:8,leav:[10,1],textbox:1,condit:7,notabl:1,machin:1,plu:[8,9,5,10,2],object:10,run:[],power:2,compress:7,ration:2,els:[],properli:1,repositori:1,found:10,immut:10,subtract:[],between:[3,8],kzj1vqkakj:5,chapter:[10,5,6,9],acb:2,about:[],herokuapp:[0,1],greater:[],chop:[],"1gh":5,discard:1,road:1,own:1,"float":[],bound:5,automat:[7,1,5],due:8,down:1,bba:2,v5i:7,your:1,r5t:10,fnr1hqn:5,surround:5,inclus:[3,10,5],git:[],log:[],wai:[10,2,3,4,7,5,9],aren:[],support:2,"long":[1,8],custom:8,avail:[7,8,5],stuck:[],window:1,arithmet:[],thorughout:9,fraction:2,jane:9,paren:7,constantli:1,"function":[10,1,2,5,8,9],reduc:[],head:[],creation:5,preinitialis:[5,9],form:[7,9],tupl:[],translat:[8,7],line:[],"true":[3,10,7],count:[],concaten:[],tripl:5,algorithm:[4,5],temp:5,possibl:[10,2],"default":10,fnrztn:5,otherwis:[5,2],problem:[4,8,5],unrel:9,cbb:2,cbc:2,kjclkshfglasjfljdlakjaflkajflkajfalkjgaf:10,cba:2,evalu:[],jdut:[10,9],"int":[],dure:5,parser:[5,8,9],doesn:8,explod:7,exist:5,rule:[8,5],langaug:[],pip:[],face:2,check:[1,3,4,9,8,5],again:[8,5],cg2:10,when:[9,1,10,2],detail:[],invalid:8,other:[10,1,2,3,8,5],lookup:9,rememb:[8,5],varieti:8,you:[8,1,5,2],repeat:[],porgram:[],benefici:1,sequenc:[],symbol:8,falsei:2,langau:7,ptupl:10,formal:9,smilei:2,lang:[],philosoph:[],eof:10,ternari:[],vice:10,lexicographi:[],bca:2,bcb:2,bcc:2,influenc:5,time:[7,8,9,5,2],escap:[],yu3:10},objtypes:{},objnames:{},filenames:["index","getting-started","spec_math","spec_comp","simple-programs2","simple-programs","spec_func","spec_control","details","spec_vars","spec_seq"],titles:["Welcome to Pyth’s documentation!","1. Getting Started","7. The Language Specification - Arithmetic","8. The Language Specification - Comparisons","4. Some Simple Programs - Part II","3. Some Simple Programs","10. The Language Specification - Functional Programming","6. The Language Specification - Control Flow","2. More Details About Pyth","5. The Language Specification - Variables","9. The Language Specification - Sequences"],objects:{},titleterms:{unari:[10,7,2],all:[8,2],code:8,less:3,setwis:2,prefix:8,primer:[],powerset:10,languag:[10,2,3,7,6,9],how:1,fix:8,pprint:[],except:7,tail:10,program:[4,1,6,5],factor:2,input:[5,9],repetit:2,"case":10,liter:10,string:[10,9,2],get:1,python:8,auto:9,"break":[7,9],world:1,superset:3,recurs:5,prime:[4,2],specif:[10,2,3,7,6,9],approach:[],revers:2,list:[10,9],iter:5,token:10,k5k:[],contain:3,uppercas:10,mean:8,compil:8,set:[3,10,2],ten:[10,9],negat:2,contructor:10,some:[4,5],mutabl:10,zero:9,num:[10,2],helloworld:[],close:7,modulu:[10,2],variabl:9,index:10,what:[],slice:[3,2],xor:10,space:9,sum:10,fnr1htn:[],occurr:2,factori:5,process:10,run:8,extend:2,len:10,parenthesi:7,lowercas:10,base:10,dictionari:9,subtract:2,valu:10,addit:2,comparison:3,about:8,last:2,convers:10,equal:3,chop:10,thing:8,length:10,context:8,logic:2,mani:8,head:10,assign:[9,2],lambda:5,oper:[8,7],subset:3,rang:[10,7],"float":10,number:5,prang:[],strip:10,decrement:10,differ:[8,2],cartesian:2,from:3,seq:[3,10,2],coupl:10,exponenti:2,doubl:[10,9],empti:9,start:1,arithmet:2,statement:7,type:3,more:8,sort:10,pyth:[0,1,8,5],capit:10,option:10,tupl:10,under:[],stone:[],append:10,ani:[3,2],part:4,els:7,line:9,than:3,count:2,concaten:2,join:10,augment:2,notat:8,"while":7,str:10,loop:[7,5],capword:10,control:7,"function":6,have:8,evalu:[10,9],"int":[3,10,2],ariti:8,indic:0,raw:9,fibonacci:5,increment:10,tabl:0,greater:3,multipl:2,welcom:0,quot:9,alphabet:9,format:2,detail:8,same:3,divis:[10,2],till:3,split:10,document:0,simpl:[4,5],updat:10,product:2,copi:9,sequenc:10,constructor:10,log:10,end:[10,7],splat:10,repeat:2,reduc:5,philosoph:[],ternari:7,swapcas:10,flow:7,element:10,titl:10,escap:10,first:5,hello:1}}) -------------------------------------------------------------------------------- /docs/_build/html/spec_var.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 5. The Language Specification - Variables — Pyth 1.0 documentation 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 39 | 40 |
41 |
42 |
43 |
44 | 45 |
46 |

5. The Language Specification - Variables

47 |

The next few chapters will be formal specifications about the language. Each chapter will have listings in alphabetical order. This chapter is about the preinitialised variables in Pyth.

48 |

5.1.

49 |
50 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |

This Page

58 | 62 | 74 | 75 |
76 |
77 |
78 |
79 | 88 | 92 | 93 | -------------------------------------------------------------------------------- /docs/adding.rst: -------------------------------------------------------------------------------- 1 | 6. Adding to Pyth 2 | ***************** 3 | 4 | Pyth is an enthusiastically open source project. If you've caught a bug, thought up a cool new idea, or want to add to the project in any way, you can do so via `Pyth's Github page `_. If you want to leave a suggestion, file a bug a report or simply get help with the language, you can open an issue by clicking on "New issue" `here `_. If you've got some code you'd like add, you can do so via a pull request. For information on how to do so, `look here `_. 5 | 6 | However you end up using Pyth, I hope you enjoy it. 7 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Pyth documentation build configuration file, created by 4 | # sphinx-quickstart on Wed Mar 04 19:19:39 2015. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys 16 | import os 17 | import sphinx_rtd_theme 18 | 19 | # If extensions (or modules to document with autodoc) are in another directory, 20 | # add these directories to sys.path here. If the directory is relative to the 21 | # documentation root, use os.path.abspath to make it absolute, like shown here. 22 | #sys.path.insert(0, os.path.abspath('.')) 23 | 24 | # -- General configuration ------------------------------------------------ 25 | 26 | # If your documentation needs a minimal Sphinx version, state it here. 27 | #needs_sphinx = '1.0' 28 | 29 | # Add any Sphinx extension module names here, as strings. They can be 30 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 31 | # ones. 32 | extensions = [ 33 | 'sphinx.ext.autodoc', 34 | 'sphinx.ext.todo', 35 | 'sphinx.ext.mathjax', 36 | ] 37 | 38 | # Add any paths that contain templates here, relative to this directory. 39 | templates_path = ['_templates'] 40 | 41 | # The suffix of source filenames. 42 | source_suffix = '.rst' 43 | 44 | # The encoding of source files. 45 | #source_encoding = 'utf-8-sig' 46 | 47 | # The master toctree document. 48 | master_doc = 'index' 49 | 50 | # General information about the project. 51 | project = u'Pyth' 52 | copyright = u'2015, Isaacg1' 53 | 54 | # The version info for the project you're documenting, acts as replacement for 55 | # |version| and |release|, also used in various other places throughout the 56 | # built documents. 57 | # 58 | # The short X.Y version. 59 | version = '1.0' 60 | # The full version, including alpha/beta/rc tags. 61 | release = '1.0' 62 | 63 | # The language for content autogenerated by Sphinx. Refer to documentation 64 | # for a list of supported languages. 65 | #language = None 66 | 67 | # There are two options for replacing |today|: either, you set today to some 68 | # non-false value, then it is used: 69 | #today = '' 70 | # Else, today_fmt is used as the format for a strftime call. 71 | #today_fmt = '%B %d, %Y' 72 | 73 | # List of patterns, relative to source directory, that match files and 74 | # directories to ignore when looking for source files. 75 | exclude_patterns = ['_build'] 76 | 77 | # The reST default role (used for this markup: `text`) to use for all 78 | # documents. 79 | #default_role = None 80 | 81 | # If true, '()' will be appended to :func: etc. cross-reference text. 82 | #add_function_parentheses = True 83 | 84 | # If true, the current module name will be prepended to all description 85 | # unit titles (such as .. function::). 86 | #add_module_names = True 87 | 88 | # If true, sectionauthor and moduleauthor directives will be shown in the 89 | # output. They are ignored by default. 90 | #show_authors = False 91 | 92 | # The name of the Pygments (syntax highlighting) style to use. 93 | pygments_style = 'sphinx' 94 | 95 | # A list of ignored prefixes for module index sorting. 96 | #modindex_common_prefix = [] 97 | 98 | # If true, keep warnings as "system message" paragraphs in the built documents. 99 | #keep_warnings = False 100 | 101 | 102 | # -- Options for HTML output ---------------------------------------------- 103 | 104 | # The theme to use for HTML and HTML Help pages. See the documentation for 105 | # a list of builtin themes. 106 | html_theme = 'sphinx_rtd_theme' 107 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 108 | 109 | # Theme options are theme-specific and customize the look and feel of a theme 110 | # further. For a list of options available for each theme, see the 111 | # documentation. 112 | #html_theme_options = {} 113 | 114 | # Add any paths that contain custom themes here, relative to this directory. 115 | #html_theme_path = [] 116 | 117 | # The name for this set of Sphinx documents. If None, it defaults to 118 | # " v documentation". 119 | #html_title = None 120 | 121 | # A shorter title for the navigation bar. Default is the same as html_title. 122 | #html_short_title = None 123 | 124 | # The name of an image file (relative to this directory) to place at the top 125 | # of the sidebar. 126 | #html_logo = None 127 | 128 | # The name of an image file (within the static path) to use as favicon of the 129 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 130 | # pixels large. 131 | #html_favicon = None 132 | 133 | # Add any paths that contain custom static files (such as style sheets) here, 134 | # relative to this directory. They are copied after the builtin static files, 135 | # so a file named "default.css" will overwrite the builtin "default.css". 136 | html_static_path = ['_static'] 137 | 138 | # Add any extra paths that contain custom files (such as robots.txt or 139 | # .htaccess) here, relative to this directory. These files are copied 140 | # directly to the root of the documentation. 141 | #html_extra_path = [] 142 | 143 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 144 | # using the given strftime format. 145 | #html_last_updated_fmt = '%b %d, %Y' 146 | 147 | # If true, SmartyPants will be used to convert quotes and dashes to 148 | # typographically correct entities. 149 | #html_use_smartypants = True 150 | 151 | # Custom sidebar templates, maps document names to template names. 152 | #html_sidebars = {} 153 | 154 | # Additional templates that should be rendered to pages, maps page names to 155 | # template names. 156 | #html_additional_pages = {} 157 | 158 | # If false, no module index is generated. 159 | #html_domain_indices = True 160 | 161 | # If false, no index is generated. 162 | #html_use_index = True 163 | 164 | # If true, the index is split into individual pages for each letter. 165 | #html_split_index = False 166 | 167 | # If true, links to the reST sources are added to the pages. 168 | #html_show_sourcelink = True 169 | 170 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 171 | #html_show_sphinx = True 172 | 173 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 174 | #html_show_copyright = True 175 | 176 | # If true, an OpenSearch description file will be output, and all pages will 177 | # contain a tag referring to it. The value of this option must be the 178 | # base URL from which the finished HTML is served. 179 | #html_use_opensearch = '' 180 | 181 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 182 | #html_file_suffix = None 183 | 184 | # Output file base name for HTML help builder. 185 | htmlhelp_basename = 'Pythdoc' 186 | 187 | 188 | # -- Options for LaTeX output --------------------------------------------- 189 | 190 | # The paper size ('letterpaper' or 'a4paper'). 191 | #'papersize': 'letterpaper', 192 | 193 | # The font size ('10pt', '11pt' or '12pt'). 194 | #'pointsize': '10pt', 195 | 196 | # Additional stuff for the LaTeX preamble. 197 | #'preamble': '', 198 | latex_elements = { 199 | } 200 | 201 | # Grouping the document tree into LaTeX files. List of tuples 202 | # (source start file, target name, title, 203 | # author, documentclass [howto, manual, or own class]). 204 | latex_documents = [ 205 | ('index', 'Pyth.tex', u'Pyth Documentation', 206 | u'Isaacg1', 'manual'), 207 | ] 208 | 209 | # The name of an image file (relative to this directory) to place at the top of 210 | # the title page. 211 | #latex_logo = None 212 | 213 | # For "manual" documents, if this is true, then toplevel headings are parts, 214 | # not chapters. 215 | #latex_use_parts = False 216 | 217 | # If true, show page references after internal links. 218 | #latex_show_pagerefs = False 219 | 220 | # If true, show URL addresses after external links. 221 | #latex_show_urls = False 222 | 223 | # Documents to append as an appendix to all manuals. 224 | #latex_appendices = [] 225 | 226 | # If false, no module index is generated. 227 | #latex_domain_indices = True 228 | 229 | 230 | # -- Options for manual page output --------------------------------------- 231 | 232 | # One entry per manual page. List of tuples 233 | # (source start file, name, description, authors, manual section). 234 | man_pages = [ 235 | ('index', 'pyth', u'Pyth Documentation', 236 | [u'Isaacg1'], 1) 237 | ] 238 | 239 | # If true, show URL addresses after external links. 240 | #man_show_urls = False 241 | 242 | 243 | # -- Options for Texinfo output ------------------------------------------- 244 | 245 | # Grouping the document tree into Texinfo files. List of tuples 246 | # (source start file, target name, title, author, 247 | # dir menu entry, description, category) 248 | texinfo_documents = [ 249 | ('index', 'Pyth', u'Pyth Documentation', 250 | u'Isaacg1', 'Pyth', 'One line description of project.', 251 | 'Miscellaneous'), 252 | ] 253 | 254 | # Documents to append as an appendix to all manuals. 255 | #texinfo_appendices = [] 256 | 257 | # If false, no module index is generated. 258 | #texinfo_domain_indices = True 259 | 260 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 261 | #texinfo_show_urls = 'footnote' 262 | 263 | # If true, do not generate a @detailmenu in the "Top" node's menu. 264 | #texinfo_no_detailmenu = False 265 | -------------------------------------------------------------------------------- /docs/details.rst: -------------------------------------------------------------------------------- 1 | 2. More Details About Pyth 2 | ************************** 3 | 4 | Now that you have the programming environment set up, let's learn some more about the language. 5 | 6 | 2.1. Pyth Uses Prefix Notation 7 | ============================== 8 | 9 | Try entering ``2+2``. It'll be 4 right?:: 10 | 11 | 2 12 | Traceback (most recent call last): 13 | File "safe_pyth.py", line 300, in 14 | File "", line 5, in 15 | TypeError: plus() missing 1 required positional argument: 'b' 16 | 17 | Oh noes! An error! What went wrong? Well, Pyth doesn't use Infix notation (the operator goes between the operands) like most languages do. Instead, Pyth uses `Prefix (aka Polish) `_ notation, which means the operator goes *before* the operands. This has the benefit of not requiring parenthesis, making programs shorter and freeing up operators for other uses. Let's try that math problem again:: 18 | 19 | +2 2 20 | 21 | Output: 22 | 23 | 4 24 | 25 | Now it is working as expected! Notice the space between the ``2``'s so the parser doesn't interpret them as a ``22``. 26 | 27 | 2.2. Pyth Has Many, Many Operators 28 | ================================== 29 | 30 | The addition operator we just saw doesn't even begin to scratch the surface of Pyth's rich variety of operators. As well as addition, Pyth has all the customary arithmetic operators - ``-`` for subtraction, ``*`` for multiplication, ``/`` for division, ``%`` for modulo, and ``^`` for exponentiation. 31 | 32 | Integers are defined as you would expect and Floats with the decimal point. Ex:: 33 | 34 | 0 35 | 1 36 | 18374 37 | 2.5 38 | 39 | However, negative numbers do not use a unary version of the subtraction symbol since all operators have a fixed arity (more on arity later). Instead, negative numbers use the unary reversal operator: ``_``:: 40 | 41 | Invalid: -25 42 | 43 | Valid: _25 44 | 45 | Pyth also has many predefined variables:: 46 | 47 | Z=0 48 | T=10 49 | k="" 50 | d=" " 51 | b="\n" 52 | 53 | All operators, variables, and control flow keywords, are always one character long to reduce the size of the program. 54 | 55 | 2.3. All Operators in Pyth Have a Fixed Arity 56 | ============================================= 57 | 58 | The `arity `_ of an operator or function (according to Wikipedia) is *the number of arguments or operands the function or operation accepts.* Most programming languages allow functions to accept different numbers of arguments, but doing so requires parenthesis. Pyth instead has a fixed number of operands per operator, allowing it to do away with parenthesis or any other delimiter. 59 | 60 | 2.4. Operators Mean Different Things in Different Contexts 61 | ========================================================== 62 | 63 | To further increase the number of functions available with only one character operators, operators operate differently depending on the values passed to it. For example, we saw the ``+`` operator adds numbers, but if ``+`` gets two sequences (e.g. strings, lists) as operands, it concatenates them:: 64 | 65 | +2 T -> 12 (remember that T=10) 66 | 67 | +"Hello ""World!" -> Hello World! 68 | 69 | Letting ``+`` mean both concatenation and addition is pretty common, but Pyth takes this to another level, with most operators having 2 or more meanings. 70 | 71 | 2.5. The Pyth Code is Compiled to Python Code Then Run 72 | ====================================================== 73 | 74 | Pyth is technically a `JIT `_ compiled language since the Pyth code is converted to Python through a series of rules defined in the file ``data.py`` and then run with the variables and functions defined in ``macros.py``. You can select the debug button in the online interpreter or pass the ``-d`` flag to the local one to see the compiled Python code. Here is what comes out as debug from ``^T6`` which evaluates to a million:: 75 | 76 | ================================================== 77 | ^T6 78 | ================================================== 79 | Pprint("\n",Ppow(T,6)) 80 | ================================================== 81 | 1000000 82 | 83 | As you can see, the exponentiation call is translated to a call to the function ``Ppow`` and is implicitly printed through a custom print function called ``Pprint``. The debug option can be very helpful with seeing what at first glance looks like a bunch of random characters does. 84 | -------------------------------------------------------------------------------- /docs/docs.rst: -------------------------------------------------------------------------------- 1 | 5. Learning More - Documentation and Errors 2 | **************************** 3 | 4 | 5.1. Documentation 5 | ================== 6 | 7 | Now that you've got a basic grasp of Pyth, the best way to learn more about the language is via the documentation. Pyth's documentation is located `on Github `_, and is updated continually as the language evolves. 8 | 9 | While the documentation is a good first step towards understanding how a function works, the only way to get a full understanding is by using it. Write programs using that function, and it'll become clear. 10 | 11 | 5.2. Errors 12 | =========== 13 | 14 | There are two levels of errors you might get: errors at the Pyth level, and errors at the Python level. 15 | 16 | 5.2.1 Pyth Errors 17 | ================= 18 | 19 | Currently, there are only 3 types of errors implemented in Pyth: token not implemented errors, unsafe input errors, and wrong type errors. I'll go through these one by one. 20 | 21 | **Token not implemented errors** occur when you try to use an unimplemented token. They look like this:: 22 | 23 | ==================== 6 chars ===================== 24 | 5.@1 1 25 | ================================================== 26 | Traceback (most recent call last): 27 | File "pyth.py", line 454, in 28 | py_code_line = general_parse(code) 29 | File "pyth.py", line 38, in general_parse 30 | parsed, code = parse(code) 31 | File "pyth.py", line 105, in parse 32 | raise PythParseError(active_char, rest_code) 33 | extra_parse.PythParseError: .@ is not implemented, 4 from the end. 34 | 35 | These are most commonly caused by using non-ASCII characters in Pyth code outside of strings, and by ending floating point numeric literals with a ``.``, which is confused with tokens of the form ``._``, as seen above. 36 | 37 | **Unsafe input errors** occur when you try to use ``$`` (the python code injection character) in the online compiler / executor or when the ``-s`` flag (safe mode) is enabled. Using ``$`` is a security hole, and is therefore disabled online. 38 | 39 | **Wrong type errors** are the most common type of error. Most functions are defined via type overloading, where the function does something entirely different depending on what types are given as input. However, not all combinations of types have an associated functionality. For instance:: 40 | 41 | ==================== 9 chars ===================== 42 | @"abc"1.5 43 | ================================================== 44 | Pprint("\n",lookup("abc",1.5)) 45 | ================================================== 46 | Traceback (most recent call last): 47 | File "pyth.py", line 478, in 48 | File "", line 4, in 49 | File "/app/macros.py", line 84, in lookup 50 | macros.BadTypeCombinationError: 51 | Error occured in function: @ 52 | Arg 1: 'abc', type str. 53 | Arg 2: 1.5, type float. 54 | 55 | The relevant part to look at is the last four lines. The fourth to last line indicates that an error as caused due to a bad type combination. The third to last line indicates that the error occurred in the ``@`` function, and the rest of the lines indicate that the error occurred because ``@`` was called with a string as its first argument and a float as its second argument, for which it has no defined functionality. 56 | 57 | 5.2.2 Python Errors 58 | =================== 59 | 60 | Occasionally you will get an error such as:: 61 | 62 | ==================== 4 chars ===================== 63 | @""1 64 | ================================================== 65 | Pprint("\n",lookup("",1)) 66 | ================================================== 67 | Traceback (most recent call last): 68 | File "pyth.py", line 478, in 69 | File "", line 4, in 70 | File "/app/macros.py", line 73, in lookup 71 | ZeroDivisionError: integer division or modulo by zero 72 | 73 | that doesn't fall into any of the previous categories. At this point, the best solution is to simply try different variants on the program in an attempt to understand how it ticks. If that doesn't work, the only remaining recourse is to look at the code itself. 74 | 75 | As indicated by the traceback, looking at line 73 of ``macro.py`` we see that ``@`` attempts to perform a lookup in the string at the index given by the second argument modulus the length of the string. Since the length of the string is zero, Python's modulus operator will fail and throw a ``ZeroDivisionError``. 76 | -------------------------------------------------------------------------------- /docs/getting-started.rst: -------------------------------------------------------------------------------- 1 | 1. Getting Started 2 | ****************** 3 | 4 | Pyth is a golfing language based on Python (hence the name) created by `Programming Puzzles and Code Golf `_ (PPCG) user `Isaacg `_. Unlike most golfing languages, Pyth is fully procedural. Since Pyth is quite young, its features are constantly changing, and this document might be out of date for a few functions (Just check the source). Pyth is licensed under the `MIT license `_. 5 | 6 | 1.1. How to Start Programming in Pyth 7 | ===================================== 8 | You have a few options when it comes to running Pyth. You could install it on your machine by cloning `the repository ` then adding this alias to your .bashrc:: 9 | 10 | alias pyth="python3 /pyth.py" 11 | 12 | (Windows users, you'll have to use the PATH and call ``pyth.py``) 13 | 14 | But the method we will be using in the tutorial, and the suggested one, is to use the online interpreter at http://pyth.herokuapp.com. This provides a programming environment with places in which to put code and input (and a handy function cheat-sheet!). The code is executed on the server and sent back to the webpage. The examples won't be too different if you decide to install the interpreter yourself. Installing the interpreter, however, will become necessary, when we start conducting "unsafe" operations which allow for arbitrary execution of code. 15 | 16 | 1.2. Hello World! 17 | ================= 18 | 19 | A customary start to programming tutorials is the "Hello World Program" which consists of printing out the text "Hello World!". Since Pyth *is* a golfing language, let's golf it! In the process, we will demonstrate some key features of Pyth. So without further ado, here is our first program:: 20 | 21 | "Hello World! 22 | 23 | Type this into the code textbox, leave the input box empty, click the run button. The results (in the output box) should look something like this:: 24 | 25 | Hello World! 26 | 27 | Well, that went pretty much as expected, but if you have any experience with other programming languages, you'll notice a few interesting things about the program. 28 | 29 | #. Printing is implicit (Just name a value or identifier and it will be printed). 30 | #. Quotes are automatically closed at the end of the program. 31 | 32 | These features are obviously beneficially for reducing the length of your programs. Another thing you should know early on if you decide to go experimenting on your own is that programs in Pyth are typically only one line long. Statement separation is typically achieved through semicolons: ``;``. 33 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to Pyth's documentation! 2 | ================================ 3 | 4 | Pyth is an extremely concise language used for golfing. Try it here at: https://pyth.herokuapp.com. This is a tutorial/documentation/language-specification for it. 5 | 6 | Contents: 7 | 8 | .. toctree:: 9 | :maxdepth: 3 10 | 11 | getting-started 12 | details 13 | simple-programs 14 | simple-programs2 15 | docs 16 | adding 17 | spec_vars 18 | spec_control 19 | spec_math 20 | spec_comp 21 | spec_seq 22 | 23 | Indices and tables 24 | ================== 25 | 26 | * :ref:`genindex` 27 | * :ref:`modindex` 28 | * :ref:`search` 29 | 30 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Pyth.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Pyth.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/simple-programs2.rst: -------------------------------------------------------------------------------- 1 | 4. Some Simple Programs - Part II 2 | ********************************* 3 | 4 | Collatz Sequence 5 | ===== 6 | 7 | Another relatively simple programming problem for us to golf down is to generate Collatz sequences. The Collatz sequence consists of repeatedly applying the following procedure: If the current number is even, divide it by two. If the current number is odd, triple it and add one. Repeat until 1 is reached. Suppose we would like to print out the entire sequence, from the input to 1. Here is a very straightforward implementation, which illustrates many of Pyth's statements:: 8 | 9 | input: 3 10 | 11 | ==================== 23 chars ==================== 12 | WtQI%Q2=Qh*Q3).?=Q/Q2)Q 13 | ================================================== 14 | assign('Q',Punsafe_eval(input())) 15 | while tail(Q): 16 | if mod(Q,2): 17 | assign('Q',head(times(Q,3))) 18 | else: 19 | assign('Q',div(Q,2)) 20 | imp_print(Q) 21 | ================================================== 22 | 10 23 | 5 24 | 16 25 | 8 26 | 4 27 | 2 28 | 1 29 | 30 | Here, we use a while loop, ``W``, with an if statement, ``I``, and an else statement, ``.?`` in the body. The if and else adjust the value of the changing variable, ``Q``, then the value is printed with the final ``Q``. The loop condition is checked using ``tQ``, which, since ``t`` is the decrement function, is nonzero and thus truthy whenever ``Q!=1`` as desired. ``%Q2``, corresponding to ``Q%2`` in most languages, is truthy whenever ``Q`` is odd. 31 | 32 | As an improvement, we can use ``?``, Pyth's ``if ... then ... else ...`` operator. Like C, but unlike Python, the conditional goes in front, then the truthy branch, then the falsy branch. This allows us to get rid of the statement overhead and the repetition of ``=Q``:: 33 | 34 | ==================== 17 chars ==================== 35 | WtQ=Q?%Q2h*Q3/Q2Q 36 | ================================================== 37 | assign('Q',eval(input())) 38 | while tail(Q): 39 | assign('Q',(head(times(Q,3)) if mod(Q,2) else div(Q,2))) 40 | imp_print(Q) 41 | ================================================== 42 | 10 43 | 5 44 | 16 45 | 8 46 | 4 47 | 2 48 | 1 49 | 50 | 51 | That saved 5 characters, or 23%. However, we can still do better. Pyth's assignment and lookup functions, ``X`` and ``@`` respectively, have a feature which is very handy in exactly this situation. Assignment and lookup wrap around when called on sequences, which means that if we lookup the ``Qth`` location of a sequence consisting of the two possible Collatz sequence successors, the proper one will be selected. Fortunately, the perfect function exists, ``,``, which constructs a 2-tuple of its 2 arguments. Putting these together gives us:: 52 | 53 | ==================== 16 chars ==================== 54 | WtQ=Q@,/Q2h*3QQQ 55 | ================================================== 56 | Q=copy(literal_eval(input())) 57 | while tail(Q): 58 | Q=copy(lookup((div(Q,2),head(times(3,Q))),Q)) 59 | Pprint("\n",Q) 60 | ================================================== 61 | 10 62 | 5 63 | 16 64 | 8 65 | 4 66 | 2 67 | 1 68 | 69 | That's as short as it can be, as far as I know. 70 | -------------------------------------------------------------------------------- /docs/spec_comp.rst: -------------------------------------------------------------------------------- 1 | 10. The Language Specification - Comparisons 2 | ******************************************* 3 | 4 | This section contains a list of comparison operators. They all take two arguments and return a boolean value depending on the relationship between the two arguments. 5 | 6 | 10.1. "<" - Is Less Than 7 | ======================= 8 | 9 | **Arity: 2** 10 | 11 | 10.1.1. Any a, Same Type b: Less Than 12 | ------------------------------------ 13 | 14 | If a and b are of the same type, checks if ``a`` is less than ``b`` by whatever way that type is compared (e.g. Numbers by size, strings lexicographically). 15 | 16 | Ex:: 17 | 18 | ================================================== 19 | <5T" - Is Greater Than 74 | ========================== 75 | 76 | **Arity: 2** 77 | 78 | 10.3.1 Any a, Same Type b: Greater Than 79 | -------------------------------------- 80 | 81 | This checks if ``a`` is greater than ``b``. Uses the same type of comparisons as ``<`` 82 | 83 | Ex:: 84 | 85 | ================================================== 86 | >5T>T5 87 | ================================================== 88 | Pprint("\n",gt(5,T)) 89 | Pprint("\n",gt(T,5)) 90 | ================================================== 91 | False 92 | True 93 | 94 | 10.3.2 Seq a, Int b: Slice From 95 | ------------------------------ 96 | 97 | This takes a slice of sequence ``a`` from index ``b`` onwards till the end. This is equivalent to the Python ``a[b:]``. The slice is inclusive of the element at index ``b``. 98 | 99 | Ex:: 100 | 101 | ================================================== 102 | >"abcdefgh"5 103 | ================================================== 104 | Pprint("\n",gt("abcdefgh",5)) 105 | ================================================== 106 | fgh 107 | 108 | 10.3.3. Set a, Set b: Is Superset 109 | -------------------------------- 110 | 111 | Checks is set ``a`` is a superset of set ``b``. This means that it checks if set ``a`` contains all the elements of set ``b``. This does not return True if the two sets are equal. 112 | 113 | Ex:: 114 | 115 | ================================================== 116 | >{[1 2 3){[1 2) 117 | ================================================== 118 | Pprint("\n",gt(Pset(Plist(1,(2),(3))),Pset(Plist(1,(2))))) 119 | ================================================== 120 | True 121 | 122 | 10.4. "n" - Not Equal To 123 | ======================= 124 | 125 | **Arity: 2** 126 | 127 | Checks if the two elements are not equal to each other. This is equivalent to Python's "!=". 128 | 129 | Ex:: 130 | 131 | ================================================== 132 | nT5nTT 133 | ================================================== 134 | Pprint("\n",ne(T,5)) 135 | Pprint("\n",ne(T,T)) 136 | ================================================== 137 | True 138 | False 139 | 140 | 10.5. "g" - Is Greater Than or Equal To 141 | ====================================== 142 | 143 | **Arity: 2** 144 | 145 | 10.5.1. Any a, Same Type b: Greater Than or Equal To 146 | --------------------------------------------------- 147 | 148 | Checks if ``a`` is greater than or equal to ``b``. 149 | 150 | Ex:: 151 | 152 | ================================================== 153 | gT5gTTg5T 154 | ================================================== 155 | Pprint("\n",gte(T,5)) 156 | Pprint("\n",gte(T,T)) 157 | Pprint("\n",gte(5,T)) 158 | ================================================== 159 | True 160 | True 161 | False 162 | 163 | 10.5.2. Seq a, Int b: Slice From, 1-indexed 164 | ========================================= 165 | 166 | This takes a slice of ``a``, from the element ``b-1``. It is equivalent to ``a[b-1:]``. 167 | 168 | Ex:: 169 | 170 | ==================== 3 chars ===================== 171 | gG5 172 | ================================================== 173 | Pprint("\n",gte(G,5)) 174 | ================================================== 175 | efghijklmnopqrstuvwxyz 176 | 177 | 10.5.3. Set a, Set b: Superset or Equal 178 | -------------------------------------- 179 | 180 | Checks if set ``a`` is a superset of set ``b`` or equal to set ``b``. 181 | 182 | Ex:: 183 | 184 | ================================================== 185 | g{[1 2 3){[2 3)g{[1 2 3){[1 2 3) 186 | ================================================== 187 | Pprint("\n",gte(Pset(Plist(1,(2),(3))),Pset(Plist(2,(3))))) 188 | Pprint("\n",gte(Pset(Plist(1,(2),(3))),Pset(Plist(1,(2),(3))))) 189 | ================================================== 190 | True 191 | True 192 | 193 | 10.6. "}" - Contains 194 | =================== 195 | 196 | **Arity: 2** 197 | 198 | Checks if the second argument, a collection, contains the first argument. Is equivalent to the Python ``in`` operator. 199 | 200 | Ex:: 201 | 202 | ================================================== 203 | }\a"abc" 204 | ================================================== 205 | Pprint("\n",("a" in "abc")) 206 | ================================================== 207 | True 208 | -------------------------------------------------------------------------------- /docs/spec_control.rst: -------------------------------------------------------------------------------- 1 | 8. The Language Specification - Control Flow 2 | ******************************************** 3 | 4 | This section of the language specifications deals with control flow. It contains the keywords and the operators that affect which parts of the programs are run. 5 | 6 | 8.1. "#" - Exception Loop 7 | ========================= 8 | 9 | **Arity: Unbounded** 10 | 11 | This is the only form of error handling available in Pyth. It runs an infinite while loop until an error is reached, then breaks out of the loop. 12 | 13 | Ex:: 14 | 15 | ==================== 11 chars ==================== 16 | #/100T=T-T1 17 | ================================================== 18 | while True: 19 | try: 20 | imp_print(div(100,T)) 21 | assign('T',minus(T,1)) 22 | except Exception: 23 | break 24 | ================================================== 25 | 10 26 | 11 27 | 12 28 | 14 29 | 16 30 | 20 31 | 25 32 | 33 33 | 50 34 | 100 35 | 36 | 37 | 8.2. ")" - Close Parenthesis 38 | ============================ 39 | 40 | This ends one function or statement. Control flow like ``if`` or ``for`` all open up an unbounded arity and this closes one of them. Also useful for tuple and list constructors. 41 | 42 | Ex:: 43 | 44 | ==================== 28 chars ==================== 45 | I>5T"Hello")"Bye"[0 1 2 3 4) 46 | ================================================== 47 | if gt(5,T): 48 | Pprint("\n","Hello") 49 | Pprint("\n","Bye") 50 | Pprint("\n",Plist(0,(1),(2),(3),(4))) 51 | ================================================== 52 | Bye 53 | [0, 1, 2, 3, 4] 54 | 55 | 8.3. ";" - End Statement 56 | ======================== 57 | 58 | This is effectively an infinite amount of close parenthesis. This closes how many ever arities are needed to start completely afresh. 59 | 60 | Ex:: 61 | 62 | ==================== 16 chars ==================== 63 | V5I>5T[1 2;"Bye" 64 | ================================================== 65 | for N in urange(5): 66 | if gt(5,T): 67 | Pprint("\n",Plist(1,(2))) 68 | Pprint("\n","Bye") 69 | ================================================== 70 | Bye 71 | 72 | 8.4. "B" - Break 73 | ================ 74 | 75 | This translates into the break keyword in Python. It is used to break out of both for and while loops (and also the infinite error loop). Pyth does not have a continue statement. Break automatically puts a close parenthesis after itself. 76 | 77 | Ex:: 78 | 79 | ================================================== 80 | #ZI>ZTB~Z1 81 | ================================================== 82 | while True: 83 | try: 84 | Pprint("\n",Z) 85 | if gt(Z,T): 86 | break 87 | Z+=1 88 | 89 | except: 90 | break 91 | ================================================== 92 | 0 93 | 1 94 | 2 95 | 3 96 | 4 97 | 5 98 | 6 99 | 7 100 | 8 101 | 9 102 | 10 103 | 11 104 | 105 | 8.5. ".?" - The Else Statement 106 | ============================= 107 | 108 | **Arity: Unbounded** 109 | 110 | This is the else part of the if-else construct. It is pretty self explanatory and works like it would in any programing language. This can also be used as part of a `for-else or while-else `_ construct. The If still needs a close parenthesis after it. 111 | 112 | Ex:: 113 | 114 | ================================================== 115 | I>5T"It's greater").?"It's less than" 116 | ================================================== 117 | if gt(5,T): 118 | Pprint("\n","It's greater") 119 | else: 120 | Pprint("\n","It's less than") 121 | ================================================== 122 | It's less than 123 | 124 | 8.6. "F" - The For Loop 125 | ======================= 126 | 127 | **Arity: Variable, Sequence, Unbounded** 128 | 129 | This is the ubiquitous for loop. It works like it does in Python, iterating through a sequence. 130 | 131 | Ex:: 132 | 133 | ================================================== 134 | FNU5N 135 | ================================================== 136 | for N in urange(5): 137 | Pprint("\n",N) 138 | ================================================== 139 | 0 140 | 1 141 | 2 142 | 3 143 | 4 144 | 145 | 8.7. "I" - The If Statement 146 | =========================== 147 | 148 | **Arity: Boolean, Unbounded** 149 | 150 | This is the If statement from Python. If the first argument is truthy, it executes the code, else it does nothing. 151 | 152 | Ex:: 153 | 154 | ================================================== 155 | I>5T"The Universe Has Exploded" 156 | ================================================== 157 | if gt(5,T): 158 | Pprint("\n","The Universe Has Exploded") 159 | ================================================== 160 | 161 | 8.8. "V" - Unary-Range-Loop 162 | =========================== 163 | 164 | **Arity: Integer, Unbounded** 165 | 166 | It is the shortest way to do a for loop. It is equivalent to the characters ``FNU``. This makes it execute the following code a number of times equal to the input, with ``N`` being the loop variable. If a sequence is given as input, it is converted to an integer via its length. 167 | 168 | Ex:: 169 | 170 | ================================================== 171 | VT*NN 172 | ================================================== 173 | for N in urange(T): 174 | Pprint("\n",times(N,N)) 175 | ================================================== 176 | 0 177 | 1 178 | 4 179 | 9 180 | 16 181 | 25 182 | 36 183 | 49 184 | 64 185 | 81 186 | 187 | 8.9. "W" - While Loop 188 | ===================== 189 | 190 | **Arity: Boolean, Unbounded** 191 | 192 | This the while loop construct from Python. It executes the following code until the condition becomes False. 193 | 194 | Ex:: 195 | 196 | ================================================== 197 | W`_ of the two sequences. They have to be of the same type. This means that it generates all the possible ways that you can select one value from both sequences. 97 | 98 | Ex:: 99 | 100 | ================================================== 101 | *"abc" "123" 102 | ================================================== 103 | Pprint("\n",times("abc",("123"))) 104 | ================================================== 105 | [('a', '1'), ('a', '2'), ('a', '3'), ('b', '1'), ('b', '2'), ('b', '3'), ('c', '1'), ('c', '2'), ('c', '3')] 106 | 107 | 9.3. "-" - Subtraction 108 | ====================== 109 | 110 | **Arity: 2** 111 | 112 | 9.3.1. Num a, Num b: Subtraction 113 | -------------------------------- 114 | 115 | Computes the difference of ``a`` from ``b``. 116 | 117 | Ex:: 118 | 119 | ================================================== 120 | -T4 121 | ================================================== 122 | Pprint("\n",minus(T,4)) 123 | ================================================== 124 | 6 125 | 126 | 9.3.2. Col a, Col b: Setwise Difference 127 | --------------------------------------- 128 | 129 | Computes the setwise difference of ``a`` from ``b``. This means it returns a collection with the elements in ``a`` that are not in ``b``, using the type of ``a``. It preserves the order of ``a``. 130 | 131 | Ex:: 132 | 133 | ==================== 10 chars ==================== 134 | -[1 2 3)[2 135 | ================================================== 136 | Pprint("\n",minus(Plist(1,(2),(3)),Plist(2))) 137 | ================================================== 138 | [1, 3] 139 | 140 | 9.4. "/" - Division 141 | =================== 142 | 143 | **Arity: 2** 144 | 145 | 9.4.1. Num a, Num b: Division 146 | ----------------------------- 147 | 148 | Returns ``a`` divided by ``b``. Uses integer division which means it truncates the fractional part of the answer. 149 | 150 | Ex:: 151 | 152 | ================================================== 153 | /T4 154 | ================================================== 155 | Pprint("\n",div(T,4)) 156 | ================================================== 157 | 2 158 | 159 | 9.4.2. Seq a, any b: Count Occurrences 160 | -------------------------------------- 161 | 162 | Returns the number of times element b appeared in sequence a. 163 | 164 | Ex:: 165 | 166 | ================================================== 167 | /[1 2 3 2 5)2 168 | ================================================== 169 | Pprint("\n",div(Plist(1,(2),(3),(2),(5)),2)) 170 | ================================================== 171 | 2 172 | 173 | 9.5. "%" - Modulus 174 | ================== 175 | 176 | **Arity: 2** 177 | 178 | 9.5.1. Num a, Num b: Modulus 179 | ---------------------------- 180 | 181 | Returns the remainder when ``a`` is integer divided by ``b``. 182 | 183 | Ex:: 184 | 185 | ================================================== 186 | %T3 187 | ================================================== 188 | Pprint("\n",mod(T,3)) 189 | ================================================== 190 | 1 191 | 192 | 9.5.2. String a, Any b: String Formatting 193 | ----------------------------------------- 194 | 195 | This applies Python's string formatting that normally occurs with ``%``. Requires ``%s`` or any of the other within the string,, just like in Python. 196 | 197 | Ex:: 198 | 199 | ================================================== 200 | %"a: %d"2 201 | ================================================== 202 | Pprint("\n",mod("a: %d",2)) 203 | ================================================== 204 | a: 2 205 | 206 | 9.5.3. Int a, Seq b: Extended Slicing 207 | ------------------------------------- 208 | 209 | Pyth's slicing operator does not support extended slicing, so this operator has the effect of doing ``b[::a]``. This means that it will pick every ``a`` elements of ``b``. 210 | 211 | Ex:: 212 | 213 | ================================================== 214 | %2"Hello 215 | ================================================== 216 | Pprint("\n",mod(2,"Hello")) 217 | ================================================== 218 | Hlo 219 | 220 | 9.6. "^" - Exponentiation 221 | ========================= 222 | 223 | **Arity: 2** 224 | 225 | 9.6.1. Num a, Num b: Exponentiation 226 | ----------------------------------- 227 | 228 | This raises the ``a`` to the power of ``b``. Like Python, it allows rational exponents. 229 | 230 | Ex:: 231 | 232 | ================================================== 233 | ^4 2 234 | ================================================== 235 | Pprint("\n",Ppow(4,(2))) 236 | ================================================== 237 | 16 238 | 239 | 9.6.2. Seq a, Int b: Cartesian Product With Repeats 240 | --------------------------------------------------- 241 | 242 | Finds the Cartesian Product of ``b`` copies of sequence ``a``. This means that it finds all possible sequences with length ``b`` that contain only elements from sequence ``a``. 243 | 244 | Ex:: 245 | 246 | ================================================== 247 | ^"abc"3 248 | ================================================== 249 | Pprint("\n",Ppow("abc",3)) 250 | ================================================== 251 | ['aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc'] 252 | 253 | 9.7. "_" - Unary Negation 254 | ========================= 255 | 256 | **Arity: 1** 257 | 258 | 9.7.1. Num a: Negation 259 | ---------------------- 260 | 261 | Returns the additive inverse of ``a`` or ``-a``. There are no negative number literals in Pyth, this is how you define negatives in Pyth. 262 | 263 | Ex:: 264 | 265 | ================================================== 266 | _25 267 | ================================================== 268 | Pprint("\n",neg(25)) 269 | ================================================== 270 | -25 271 | 272 | 9.7.2. Seq a: Reversal 273 | ---------------------- 274 | 275 | Returns ``a`` in reversed order. This is equivalent to the alien smiley face, ``[::-1]`` in Python. 276 | 277 | Ex:: 278 | 279 | ================================================== 280 | _"abc" 281 | ================================================== 282 | Pprint("\n",neg("abc")) 283 | ================================================== 284 | cba 285 | 286 | 9.7.3. Dict a: Invert 287 | --------------------- 288 | 289 | Returns ``a`` with its keys and values swapped. 290 | 291 | Ex:: 292 | 293 | ==================== 7 chars ===================== 294 | XH1\a_H 295 | ================================================== 296 | Pprint("\n",assign_at(H,1,"a")) 297 | Pprint("\n",neg(H)) 298 | ================================================== 299 | {1: 'a'} 300 | {'a': 1} 301 | 302 | 9.8. "P" - Prime Factorization 303 | =============================== 304 | 305 | **Arity: 1** 306 | 307 | 9.8.1. Int a: Prime Factorization 308 | ---------------------------------- 309 | 310 | Returns the `prime factorization of `_ ``a``. Returns it as a list and multiplicities are just repeated. 311 | 312 | Ex:: 313 | 314 | ================================================== 315 | P12 316 | ================================================== 317 | Pprint("\n",primes_upper(12)) 318 | ================================================== 319 | [2, 2, 3] 320 | 321 | 9.8.2. Seq a: All But Last 322 | --------------------------- 323 | 324 | Returns all but the last element of ``a``. This is equivalent to the Python ``[:-1]`` 325 | 326 | Ex:: 327 | 328 | ================================================== 329 | P"abc" 330 | ================================================== 331 | Pprint("\n",primes_upper("abc")) 332 | ================================================== 333 | ab 334 | -------------------------------------------------------------------------------- /docs/spec_vars.rst: -------------------------------------------------------------------------------- 1 | 7. The Language Specification - Variables 2 | ***************************************** 3 | 4 | The next few chapters will be formal specifications about the language. Each chapter will have listings in alphabetical order. Since many function have completely unrelated uses, each will be listed by its primary use. This chapter is about the preinitialised variables in Pyth. 5 | 6 | 7.1. "G" - The Alphabet 7 | ======================= 8 | 9 | This variable is preinitialised to the lowercase letters in the alphabet (i.e. "abcdefghijklmnopqrstuvwxyz"). 10 | 11 | Ex:: 12 | 13 | ================================================== 14 | @G5 15 | ================================================== 16 | Pprint("\n",lookup(G,5)) 17 | ================================================== 18 | f 19 | 20 | 7.2. "H" - Empty Dictionary 21 | =========================== 22 | 23 | This variable is set to an empty Python dictionary. Pyth also has a dictionary constructor, ``.d``. 24 | 25 | Ex:: 26 | 27 | ================================================== 28 | XH"a"5 29 | ================================================== 30 | Pprint("\n",assign_at(H,"a",5)) 31 | ================================================== 32 | {'a': 5} 33 | 34 | 7.3. "J" - Auto-Assignment With Copy 35 | ==================================== 36 | 37 | This, like ``K`` gets auto assigned the first time it is used. However, this is not directly assigned but assigned to a copy. 38 | 39 | Ex:: 40 | 41 | ================================================== 42 | J5*3J 43 | ================================================== 44 | J=copy(5) 45 | Pprint("\n",times(3,J)) 46 | ================================================== 47 | 15 48 | 49 | 7.4. "K" - Auto-Assignment 50 | ========================== 51 | 52 | The first time time this variable is mentioned, it assigns itself to the next expression. Unlike ``J``, this is not assigned to a copy but instead directly. The difference is relevant for mutable data types. 53 | 54 | Ex:: 55 | 56 | ================================================== 57 | K7+TK 58 | ================================================== 59 | K=7 60 | Pprint("\n",plus(T,K)) 61 | ================================================== 62 | 17 63 | 64 | 7.5. "N" - Double Quote 65 | ======================= 66 | 67 | This is pre-set to a string containing only a double quote. This useful since its one character shorter than ``\"``. 68 | 69 | Ex:: 70 | 71 | ================================================== 72 | +++"Jane said "N"Hello!"N 73 | ================================================== 74 | Pprint("\n",plus(plus(plus("Jane said ",N),"Hello!"),N)) 75 | ================================================== 76 | Jane said "Hello!" 77 | 78 | 7.6. "Q" - Evaluated Input 79 | ========================== 80 | 81 | This variable auto-initializes to the evaluated input. The parser checks whether ``Q`` is in the code, and if it is, adds a line to the top setting ``Q`` equal to the evaluated input. This is the primary form of input in most programs. 82 | 83 | Ex:: 84 | 85 | input: 10 86 | 87 | ================================================== 88 | yQ 89 | ================================================== 90 | Q=copy(literal_eval(input())) 91 | Pprint("\n",subsets(Q)) 92 | ================================================== 93 | 20 94 | 95 | 7.7. "T" - Ten 96 | ============== 97 | 98 | Pretty self-explanatory. It starts off equalling ten. Ten is a very useful value. 99 | 100 | Ex:: 101 | 102 | ================================================== 103 | ^T6 104 | ================================================== 105 | Pprint("\n",Ppow(T,6)) 106 | ================================================== 107 | 1000000 108 | 109 | 7.8. "Y" - Empty List 110 | ===================== 111 | 112 | Just an empty list that comes in handy when appending throughout a loop. 113 | 114 | Ex:: 115 | 116 | ================================================== 117 | lY 118 | ================================================== 119 | Pprint("\n",Plen(Y)) 120 | ================================================== 121 | 0 122 | 123 | 7.9. "Z" - Zero 124 | =============== 125 | 126 | This starts of as another very useful value, 0. 127 | 128 | Ex:: 129 | 130 | ================================================== 131 | *Z5 132 | ================================================== 133 | Pprint("\n",times(Z,5)) 134 | ================================================== 135 | 0 136 | 137 | 7.10. "b" - Line Break 138 | ====================== 139 | 140 | This is set to a newline character. 141 | 142 | Ex:: 143 | 144 | ================================================== 145 | jbUT 146 | ================================================== 147 | Pprint("\n",join(b,urange(T))) 148 | ================================================== 149 | 0 150 | 1 151 | 2 152 | 3 153 | 4 154 | 5 155 | 6 156 | 7 157 | 8 158 | 9 159 | 160 | 7.11. "d" - Space 161 | ================= 162 | 163 | This is set to a string containing a single space. 164 | 165 | Ex:: 166 | 167 | ================================================== 168 | jdUT 169 | ================================================== 170 | Pprint("\n",join(d,urange(T))) 171 | ================================================== 172 | 0 1 2 3 4 5 6 7 8 9 173 | 174 | 7.12. "k" - Empty String 175 | ======================== 176 | 177 | Pre-initialised to an empty string. Useful for joining. 178 | 179 | Ex:: 180 | 181 | ================================================== 182 | jkUT 183 | ================================================== 184 | Pprint("\n",join(k,urange(T))) 185 | ================================================== 186 | 0123456789 187 | 188 | 7.13. "z" - Raw Input 189 | ===================== 190 | 191 | This is set to the input, like ``Q``, but not evaluated. This is useful for string input. 192 | 193 | Ex:: 194 | 195 | input: Hello 196 | 197 | ================================================== 198 | *z5 199 | ================================================== 200 | z=copy(input()) 201 | Pprint("\n",times(z,5)) 202 | ================================================== 203 | HelloHelloHelloHelloHello 204 | -------------------------------------------------------------------------------- /extra_parse.py: -------------------------------------------------------------------------------- 1 | # To be included in pyth.py 2 | 3 | 4 | class PythParseError(Exception): 5 | 6 | def __init__(self, active_char, rest_code): 7 | self.active_char = active_char 8 | self.rest_code = rest_code 9 | 10 | def __str__(self): 11 | return "%s is not implemented, %d from the end." % \ 12 | (self.active_char, len(self.rest_code) + 1) 13 | 14 | 15 | class UnsafeInputError(Exception): 16 | 17 | def __init__(self, active_char, rest_code): 18 | self.active_char = active_char 19 | self.rest_code = rest_code 20 | 21 | def __str__(self): 22 | return "%s is unsafe, %d from the end." % \ 23 | (self.active_char, len(self.rest_code) + 1) 24 | 25 | def str_parse_next(active_token): 26 | point = 0 27 | out = [] 28 | while point < len(active_token): 29 | if active_token[point] == '\\': 30 | if len(active_token) == point + 1: 31 | out.append('\\\\') 32 | break 33 | elif active_token[point + 1] in ('\\', '"'): 34 | out.append(active_token[point:point+2]) 35 | point += 2 36 | continue 37 | elif active_token[point + 1] == '\n': 38 | point += 2 39 | continue 40 | if active_token[point] == '\n': 41 | out.append('\\n') 42 | elif active_token[point] == '\r': 43 | out.append('\\r') 44 | elif active_token[point] == '\0': 45 | out.append('\\000') 46 | else: 47 | out.append(active_token[point]) 48 | point += 1 49 | if out.count('"') == 1: 50 | out.append('"') 51 | assert out.count('"') == 2 52 | return ''.join(out) 53 | -------------------------------------------------------------------------------- /favicon2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isaacg1/pyth/97cdf30d749d2a0d6ec1bb4b9bc417c34cce05bb/favicon2.ico -------------------------------------------------------------------------------- /how-to-use-pyth.txt: -------------------------------------------------------------------------------- 1 | How to use pyth: 2 | 3 | Compiler/executer: 4 | 5 | git clone https://github.com/isaacg1/pyth.git 6 | (linux) 7 | 8 | or go to 9 | https://github.com/isaacg1/pyth 10 | and choose download as zip, then extract it. 11 | (any) 12 | 13 | To run programs from the command line from the directory you cloned/extracted to: 14 | 15 | python3 pyth.py -c "" 16 | (linux) 17 | 18 | py -3 pyth.py -c "" 19 | (windows) 20 | 21 | Really simple example: 22 | 23 | +1 1 24 | 25 | Returns 2. 26 | (If it returned 1, check that you used quotes) 27 | 28 | This illustrates a basic feature of pyth: Pyth uses Polish notation, 29 | also known as prefix notation, where functions, operators and statements 30 | come before their arguments. 31 | 32 | It also illustrates the default printing behavior of Pyth: Expressions that 33 | return a value are printed by default. 34 | 35 | Functions: 36 | Various arities 37 | 1: 38 | !0 39 | 40 | 2: 41 | r3 9 42 | 43 | 3: 44 | :"Hello!"2 4 45 | 46 | Assignment: 47 | =Z9*ZZ 48 | =Z"Hello"~Z" world" 49 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Pyth Compiler/Executor 5 | 6 | 7 | 8 | 9 | 10 | 79 | 80 | 81 |
82 |

Pyth Compiler/Executor

83 |
84 |
85 |
86 |
87 | Output: 88 |

 89 | 					
90 | 91 | 92 | 93 | 94 |
95 | 99 | Switch to Test Suite 100 |
101 | 102 | 103 |
104 | 105 |
106 | 107 |
108 |
109 | 110 |
111 |
112 | Debug on?: 113 |


114 |
115 | 116 |
117 |
118 |

Code length: 0

119 |

Compiler last updated: {{formatted_time}} UTC

120 |
121 | 122 |
123 | 124 |
125 |

Pyth Character Reference

126 | Key and text version 127 | 136 |
137 |
138 |
139 |
140 | 141 |
142 |
143 | 301 | 302 | 303 | 304 | -------------------------------------------------------------------------------- /lexer.py: -------------------------------------------------------------------------------- 1 | def lex(code): 2 | remainder = code 3 | tokens = [] 4 | while remainder: 5 | split_point = find_split_point(remainder) 6 | token, remainder = remainder[:split_point], remainder[split_point:] 7 | tokens.append(token) 8 | return tokens 9 | 10 | def find_split_point(code): 11 | if len(code) == 1: 12 | return 1 13 | if code[0] == ".": 14 | if code[1] == '"': 15 | return string_split(code[1:]) + 1 16 | if code[1] not in "0123456789": 17 | return 2 18 | if code[0] == '\\': 19 | return 2 20 | if code[0] in ".123456789": 21 | return num_split(code) 22 | if code[0] == '"': 23 | return string_split(code) 24 | if code[0] == '$': 25 | return python_lit_split(code) 26 | return 1 27 | 28 | def string_split(code): 29 | assert code[0] == '"' 30 | point = 1 31 | while point < len(code): 32 | if code[point] == '\\': 33 | if len(code) == point + 1: 34 | point += 1 35 | break 36 | elif code[point+1] in ('"', '\\'): 37 | point += 2 38 | continue 39 | if code[point] == '"': 40 | point += 1 41 | break 42 | else: 43 | point += 1 44 | return point 45 | 46 | def num_split(code): 47 | point = 0 48 | seen_a_dot = False 49 | while point < len(code) \ 50 | and code[point] in ".0123456789" \ 51 | and (not (seen_a_dot and code[point] == '.')): 52 | seen_a_dot = seen_a_dot or code[point] == '.' 53 | point += 1 54 | if point < len(code) and code[point-1] == '.': 55 | point -= 1 56 | return point 57 | 58 | def python_lit_split(code): 59 | assert code[0] == '$' 60 | if '$' not in code[1:]: 61 | return len(code) 62 | else: 63 | return code[1:].index('$') + 2 64 | -------------------------------------------------------------------------------- /packed-pyth.py: -------------------------------------------------------------------------------- 1 | import pyth 2 | 3 | def byte_to_k_bits(b, k): 4 | assert 0 <= b < 2 ** k 5 | return bin(b)[2:].zfill(k) 6 | 7 | def bytes_to_packed(bs): 8 | return ''.join(byte_to_k_bits(b, 7) for b in bs) 9 | 10 | def bin_string_to_padded_bytes(b_str): 11 | end = len(b_str) % 8 12 | if end: 13 | pb_str = b_str + '0' * (8 - end) 14 | else: 15 | pb_str = b_str 16 | b_list = [] 17 | for i in range(len(pb_str)//8): 18 | sub = pb_str[i*8: (i+1)*8] 19 | b = int(sub, 2) 20 | b_list.append(b) 21 | return bytes(b_list) 22 | 23 | def bytes_to_bin_string(bs): 24 | return ''.join(byte_to_k_bits(b, 8) for b in bs) 25 | 26 | def bin_string_to_ascii_bytes(b_str): 27 | b_list = [] 28 | for i in range(len(b_str)//7): 29 | sub = b_str[i*7: (i+1)*7] 30 | b = int(sub, 2) 31 | b_list.append(b) 32 | return bytes(b_list) 33 | 34 | def packed_bytes_to_str(packed_bytes): 35 | return bin_string_to_ascii_bytes(bytes_to_bin_string(packed_bytes)) 36 | 37 | def str_to_packed_bytes(str_): 38 | return bin_string_to_padded_bytes(bytes_to_packed(str_)) 39 | 40 | import argparse 41 | 42 | parser = argparse.ArgumentParser() 43 | group = parser.add_mutually_exclusive_group() 44 | group.add_argument("file", help='unpack, run as Pyth program', nargs='?') 45 | group.add_argument('-p', '--pack', help='pack ASCII file SRC into file DST', nargs=2 46 | , metavar=('SRC', 'DST')) 47 | group.add_argument('-u', '--unpack', help='unpack packed file SRC into file DST', nargs=2 48 | , metavar=('SRC', 'DST')) 49 | parser.add_argument('input', help='Input for Pyth program', nargs='?', default='') 50 | parser.add_argument('-d', '--debug', help='Show Pyth program that was run' 51 | , action='store_true') 52 | args = parser.parse_args() 53 | 54 | if args.file: 55 | with open(args.file, 'rb') as f: 56 | data = f.read() 57 | pyth_code_bytes = packed_bytes_to_str(data) 58 | pyth_code = pyth_code_bytes.decode('ascii') 59 | if args.debug: 60 | print(pyth_code) 61 | result, error = pyth.run_code(pyth_code, args.input) 62 | if error: 63 | print(error) 64 | else: 65 | print(result, end='') 66 | elif args.pack: 67 | src = args.pack[0] 68 | dst = args.pack[1] 69 | with open(src, 'rb') as f: 70 | data = f.read() 71 | packed_bytes = str_to_packed_bytes(data) 72 | str_ = packed_bytes_to_str(packed_bytes) 73 | assert data == str_, "Inverse works" 74 | 75 | with open(dst, 'wb') as f: 76 | writen = f.write(packed_bytes) 77 | elif args.unpack: 78 | src = args.unpack[0] 79 | dst = args.unpack[1] 80 | with open(src, 'rb') as f: 81 | data = f.read() 82 | str_ = packed_bytes_to_str(data) 83 | packed_bytes = str_to_packed_bytes(str_) 84 | assert data == packed_bytes, "Inverse works" 85 | with open(dst, 'wb') as f: 86 | writen = f.write(str_) 87 | else: 88 | assert False, "Argument parsing failed" 89 | 90 | """ 91 | with open(args.file, 'rb') as f: 92 | data = f.read() 93 | 94 | print(data) 95 | packed_bytes = str_to_packed_bytes(data) 96 | print(packed_bytes) 97 | str_ = packed_bytes_to_str(packed_bytes) 98 | print(str_) 99 | 100 | with open('out', 'wb') as f: 101 | writen = f.write(packed_bytes) 102 | """ 103 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==0.10.1 2 | Jinja2==2.7.3 3 | MarkupSafe==0.23 4 | Werkzeug==0.9.6 5 | gunicorn==19.1.1 6 | itsdangerous==0.24 7 | pillow==2.8.2 8 | -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.4.1 2 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | #!venv/bin/python 2 | from flask import Flask, render_template, request, Response 3 | import os 4 | import time 5 | import subprocess 6 | 7 | app = Flask(__name__, template_folder='.', static_folder='.') 8 | 9 | 10 | @app.route('/') 11 | def root(): 12 | time_in_secs = os.path.getmtime('pyth.py') 13 | time_in_python = time.gmtime(time_in_secs) 14 | formatted_time = time.strftime("%d %b %Y", time_in_python) 15 | return render_template('index.html', 16 | formatted_time=formatted_time, 17 | code=request.args.get('code', ''), 18 | input=request.args.get('input', ''), 19 | debug=int(request.args.get('debug', 0)), 20 | test_suite=int(request.args.get('test_suite', 0)), 21 | test_suite_input=request.args.get('test_suite_input', ''), 22 | input_size=int(request.args.get('input_size', 1))) 23 | 24 | 25 | def run_code(code_message, input_message, debug_on): 26 | resp = '' 27 | 28 | input_message += '\n' 29 | pyth_code = '\n'.join(code_message.split("\r\n")) 30 | pyth_process = \ 31 | subprocess.Popen(['/usr/bin/env', 32 | 'python3', 33 | 'pyth.py', 34 | '-csd' if debug_on else '-cs', 35 | pyth_code], 36 | stdin=subprocess.PIPE, 37 | stdout=subprocess.PIPE, 38 | stderr=subprocess.STDOUT) 39 | 40 | output, errors = \ 41 | pyth_process.communicate(input=bytearray(input_message, 'utf-8')) 42 | 43 | if code_message: 44 | resp += output.decode() + (errors if errors else '') 45 | 46 | return resp 47 | 48 | 49 | @app.route('/submit', methods=['POST']) 50 | def submit(): 51 | code_message = request.form.get('code', '') 52 | input_message = request.form.get('input', '') 53 | debug_on = int(request.form.get('debug'), 0) 54 | 55 | return Response(run_code(code_message, input_message, debug_on)) 56 | 57 | 58 | @app.route('/submit_test_suite', methods=['POST']) 59 | def submit_test_suite(): 60 | code_message = request.form.get('code', '') 61 | input_size = int(request.form.get('input_size', '1'), 0) 62 | inputs = ["\n".join(i) for i in zip(*[iter(request.form.get('input', '').split("\n"))] * input_size)] 63 | debug_on = int(request.form.get('debug'), 0) 64 | 65 | return Response("\n".join([run_code(code_message, inputs[0], debug_on)] + 66 | [run_code(code_message, i, False) for i in inputs[1:]]) if inputs else "") 67 | 68 | 69 | @app.route('/') 70 | def other(path): 71 | return app.send_static_file(path) 72 | 73 | if __name__ == '__main__': 74 | app.run(debug=True) 75 | -------------------------------------------------------------------------------- /tree.py: -------------------------------------------------------------------------------- 1 | import extra_parse 2 | import data 3 | import sys 4 | 5 | # Call with Pyth program on STDIN. 6 | 7 | 8 | global J_used 9 | global K_used 10 | J_used = False 11 | K_used = False 12 | nums = '0123456789' 13 | 14 | 15 | def make_tree(code): 16 | if code == '': 17 | return [], '' 18 | char, code = code[0], code[1:] 19 | if char == '.' and code[0] not in nums: 20 | char += code[0] 21 | code = code[1:] 22 | if char in '.' + nums: 23 | while code and code[0] in nums: 24 | char += code[0] 25 | code = code[1:] 26 | return [char], code 27 | if char == '"': 28 | _, new_code = extra_parse.str_parse(char, code) 29 | char += code[:len(code) - len(new_code)] 30 | code = new_code 31 | return [char], code 32 | if char == '$': 33 | _, new_code = extra_parse.python_parse(char, code) 34 | char += code[:len(code) - len(new_code)] 35 | code = new_code 36 | return [char], code 37 | if char == '\\': 38 | if code: 39 | char += '\\' + code[0] 40 | code = code[1:] 41 | return [char], code 42 | if char == ')': 43 | return [], code 44 | if char == ';': 45 | return [], ';' + code 46 | if char in data.variables: 47 | return [char], code 48 | global J_used 49 | if char == 'J': 50 | if J_used: 51 | return [char], code 52 | else: 53 | J_used = True 54 | global K_used 55 | if char == 'K': 56 | if K_used: 57 | return [char], code 58 | else: 59 | K_used = True 60 | if char in data.c_to_s or char in 'V': 61 | if char in 'V': 62 | init_arity = 1 63 | else: 64 | init_arity = data.c_to_s[char][1] 65 | args = [char] 66 | while len(args) < init_arity + 1 and code: 67 | child, new_code = make_tree(code) 68 | code = new_code 69 | args.append(child) 70 | while args[-1] and args[-1][0] not in data.end_statement and code: 71 | child, new_code = make_tree(code) 72 | code = new_code 73 | args.append(child) 74 | if not args[-1]: 75 | args = args[:-1] 76 | return args, code 77 | if char in data.c_to_f: 78 | arity = data.c_to_f[char][1] 79 | if char in data.c_to_i: 80 | arity = data.c_to_i[char][1] 81 | if char in data.replacements: 82 | # This may change! 83 | arity = 1 84 | if char in data.c_to_i or char in data.c_to_f or char in data.replacements: 85 | if arity == 0: 86 | return [char], code 87 | if not code: 88 | return [char, []], code 89 | elif code[0] in 'FMI': 90 | arity = 1 91 | char += code[0] 92 | code = code[1:] 93 | elif code[0] in 'LRV': 94 | arity = 2 95 | char += code[0] 96 | code = code[1:] 97 | elif code[0] in 'W': 98 | arity += 1 99 | char += code[0] 100 | code = code[1:] 101 | elif code[0] in 'B': 102 | char += code[0] 103 | code = code[1:] 104 | while code[0] in 'M': 105 | arity = 1 106 | char += code[0] 107 | code = code[1:] 108 | args = [char] 109 | while (arity < 0 or len(args) < arity + 1) and code: 110 | child, new_code = make_tree(code) 111 | code = new_code 112 | args.append(child) 113 | return args, code 114 | raise NameError("%s unimplemented" % char) 115 | 116 | 117 | def assemble_trees(code): 118 | trees = [] 119 | while code: 120 | tree, code = make_tree(code) 121 | if code and code[0] == ';': 122 | code = code[1:] 123 | trees.append(tree) 124 | return trees 125 | 126 | 127 | def disp_tree(trees): 128 | graph = Digraph() 129 | count = 0 130 | 131 | def add(tree, count): 132 | if not tree: 133 | return count 134 | root = count 135 | graph.node(str(root), label=tree[0]) 136 | for subtree in tree[1:]: 137 | if subtree: 138 | count += 1 139 | graph.edge(str(root), str(count)) 140 | count = add(subtree, count) 141 | return count 142 | for tree in trees: 143 | count = add(tree, count) + 1 144 | graph.render('tree-rep.gv', view=True) 145 | 146 | 147 | def text_tree(trees): 148 | def single_tree(tree): 149 | head, *children = tree 150 | if not children: 151 | return head 152 | start = head + ' ' 153 | rest = (single_tree(children[0]) if len(children) == 1 154 | else ''.join( 155 | '\n' + single_tree(child) 156 | for child in children)) 157 | return start + rest.replace('\n', '\n' + ' ' * len(start)) 158 | return '\n'.join(single_tree(tree) for tree in trees) 159 | 160 | code = input() 161 | trees = assemble_trees(code) 162 | if len(sys.argv) > 1: 163 | from graphviz import Digraph 164 | disp_tree(trees) 165 | else: 166 | print(text_tree(trees)) 167 | --------------------------------------------------------------------------------