Comments (5)
I just created an issue based on this page.
from oolib.
cool :-)
from oolib.
That's nice idea. I've been thinking about interface for a while and I was going to implement it like this:
# `interface` is a reserved word so `protocol` is used instead.
protocol IFly:
proc fly() =
discard
class Bird impl IFly:
proc fly() =
echo "I'm flying!"
and then it's converted below like nim-interface-implements:
type IFly = tuple
fly: proc()
type Bird = ref object
proc fly(self: Bird) =
echo "I'm flying!"
proc toProtocol(self: Bird): IFly =
return (
fly: self.fly()
)
I'm interested in your idea, but I can't think of a way to implement it. Can you tell me some details?
from oolib.
I see. very nice. the syntax looks very clean and clear.
There is (yet) another interface implementation called iface from yglukhov.
The details need to be fleshed out. I am not sure it works.
Nim has a compiler feature to check if code compiled (checked during compile time)
https://nim-lang.github.io/Nim/system#compiles%2Cuntyped
when compiles(3 + 4):
echo "'+' for integers is available"
so if we do:
# check_bird_fly
when not compiles(new Bird().fly()):
{.error "fly proc not yet implemented for Bird type".}
perhaps it's a simple solution. maybe make it more explicit like:
checkImpl(Bird,IFly)
, then it will expand to try all the IFly
defined procs for Bird.
is that clearer now? None of the code was checked, it was just an idea. see if u can get it to work... Thanks!
from oolib.
I see, I understand.
So the type of the first argument of checkImpl()
is typed
, right?
I think I can implement it well, so I'll try. Thanks!
from oolib.
Related Issues (20)
- properties with asterisks are not parsed
- `func` in implementation class cannot be parsed
- Field
- Let {.pClass.} have `ClassData`
- `{.protocoled.}` to make a tuple `protocol`
- `{.initial.}` to set initial values
- Helper functions for namedtuple
- Enable implemented class to call implemented procedures in `protocol` HOT 1
- Constructor for distinct type
- Encapsulation in classes and immutable fields in them. HOT 3
- Abolish some kind of class
- Remake class macro
- Adopt design by contract
- Instanceof feature for protocol's HOT 2
- `self: var T`
- `isInstanceOf` problem with multiple `impl` HOT 5
- `MetaData` custom pragma for class and protocol
- Sealed class
- Improve error messages with `protocol` HOT 1
- How to convert `multiple impl class` to base `protocol` type? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oolib.