Skip to main content

Declaring the Point class

⚠️ DADA DOESN'T REALLY EXIST. ⚠️

See the About page for more information. Also, you have to pretend that all the code examples are editable and runnable, with live IDE tooltips and so forth. =)

The main data structures in Dada are classes. The full class syntax has various bells and whistles, but let's start off with the simplest form. We'll define a class Point for storing (x, y) values. It will have two fields, x and y:

class Point(x, y)
# ^^^^^ ^ ^
# | | |
# | | Field name
# | Field name
# Class name

Constructor functions

The class Point(..) syntax also creates a constructor function that creates an instance of Point when called. To get a feel for how classes work in practice, work with the following code. Feel free to make changes and see what happens! You'll also notice that when you move your cursor, the code executes up until the line you selected.

Loading...