Skip to content

constructor

pannous edited this page Nov 5, 2020 · 7 revisions

constructors

There is a subtle difference between
person{name:"Joe" address{street:"no way 123"}}
person:{name="Joe" address:{street="no way 123"}}

While both construct an object person, the variant with colon constructs pure data while the variant without colon constructs the person via a constructor, if available.

class person{
 init{
    id=random()
 }
}

a=person{} // preferred way
a=person() // works as constructor unless person is a function

By default classes are extendible, so person{name:"Joe" address{street:"no way 123"}} works as expected: the person object now has a name field and an id field via the init constructor.

There are situations where objects are meant to be immutable or non-extendible, or where successful construction depends on the right data at initialization time. These required fields can be denoted via exclamation mark:

class person{
  name!
  address
}

Now every construction person{name:"blah"} must provide the name argument/field property.

Home

Philosophy

data & code blocks

features

inventions

evaluation

keywords

iteration

tasks

examples

todo : bad ideas and open questions

⚠️ specification and progress are out of sync

Clone this wiki locally