0

I know it's generally NOT a good idea but I want to make Nim more "Pythonic". Examples:

1) instead of proc, use def

2) instead of echo, use print

3) instead of readLine, use input

4) instead of parseJson use json.loads

and so on.

Yes, it may not be possible to change the behavior of the functions and statements, but I'd like it to - at least - look like the "good old" Python ones.

Honestly, please don't explain me why you think it's a bad idea. I want to play and try it. No animals would be harmed, blah-blah.

Any ideas?

Thank you!

Spaceman
  • 1,185
  • 4
  • 17
  • 31
  • 1
    What makes you think you can change a languages [keywords](http://nim-lang.org/docs/manual.html#lexical-analysis-identifiers-keywords)? – Cory Kramer Jun 18 '15 at 19:02
  • 1
    @CoryKramer knowing Nim only for 2 hours, I have no idea whether I can or can not do that. That's why I created this question. – Spaceman Jun 18 '15 at 19:11
  • @tobias_k yes actually this is what I though first, but maybe there is another more convenient way... – Spaceman Jun 18 '15 at 19:11
  • 1
    I don't know nim, but besides `def`, all the others are plain functions, so you'll want to define the Python-named functions and just mane them forward their arguments to the Nim builtins, adjusting the semantic if necessary. – Matteo Italia Jun 18 '15 at 19:16
  • 4
    Not a bad question. Maybe not a good idea to most people but seems like a valid question anyway. – Lye Fish Jun 18 '15 at 20:18

1 Answers1

3

For echo, readLine, and parseJson you can look up their definitions in system.nim and json.nim and define your own procs. This should work:

import json

proc print*(x: varargs[expr, `$`]) {.magic: "Echo", tags: [WriteIOEffect], sideEffect.}

proc input*(f: File): TaintedString  {.tags: [ReadIOEffect], benign.}

proc loads(p: var JsonParser): JsonNode = parseJson(p)

Regarding def, I don't think it is possible with exactly the same syntax as for proc. If you want to, you can come up with some def macro, which itself generates the AST of some proc. But as far as I can see, the resulting syntax for defining a proc would be pretty ugly.

bluenote10
  • 23,414
  • 14
  • 122
  • 178