Support Python-like class instantiation #13
litlighilit
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To support:
(currently the last line just must be written as
let o = newO(3)
)Gen O as macro/template
class O:...
generates(
<xxx>
is parameters to be instanced)but there are some strictions, among which there is an unacceptable one:
Cannot support init with no params being called!
Because both
O
andO()
calls the generated template.So this cannot be adopted to class whose
__init__
param-list is onlyself
(e.g. all classes without a custom__init__
)Write generated type define into a new module (write to another file)
Nim disallows define a type and a proc with the same name in one module, but whe they're placed in separated modules, it's allowed. So we can write
type O* = ref object ...
to a new file(maybe tempfile) and add aimport
in current module.Such a tactic can also be used when implementing pylib, such as allowing writting
str.maketrans
instead ofPyStr.maketrans
Beta Was this translation helpful? Give feedback.
All reactions