Giter Site home page Giter Site logo

Comments (2)

tov avatar tov commented on August 25, 2024

But now this code works:

let Link = MaybeC(Node?)
defstruct Node(
       prev: Link,
       data: MaybeC(X),
       next: Link)

The order matters. It shouldn't, but it's what we have now.

from dssl2.

tov avatar tov commented on August 25, 2024

Update:

#lang dssl2

def MaybeC(c): OrC(c, NoneC)

let IntLink = MaybeC(IntNode?)
struct IntNode:
    let prev: IntLink
    let data: int?
    let next: IntLink

class _Node[T]:
    let _prev: _Link(T)
    let _data: MaybeC(T)
    let _next: _Link(T)

    def __init__(self):
        self._prev = None
        self._data = None
        self._next = None
        
    def prev(self): self._prev
    def data(self): self._data
    def next(self): self._next
    def set_prev(self, v): self._prev = v
    def set_data(self, v): self._data = v
    def set_next(self, v): self._next = v
        
def _Link(T): MaybeC(_Node?[T])

let n = _Node[int?]()

assert n.data() is None
n.set_data(5)
assert n.data() == 5
assert_error n.set_data('hello')
assert n.data() == 5

assert n.next() is None
n.set_next(n)
assert n.next() is n
n.set_next(None)
assert n.next() is None

from dssl2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.