Explorar el Código

Update examples/numbat_syntax.nbt

David Peter hace 1 año
padre
commit
66b2fc410a
Se han modificado 1 ficheros con 10 adiciones y 7 borrados
  1. 10 7
      examples/numbat_syntax.nbt

+ 10 - 7
examples/numbat_syntax.nbt

@@ -113,13 +113,16 @@ type(2 m/s)                      # Print the type of an expression
 
 # 10. Structs
 
-struct Foo {                        # defining a struct
-  foo: Current,
-  bar: Scalar
+struct Element {                 # Define a struct
+    name: String,
+    atomic_number: Scalar,
+    density: MassDensity,
 }
 
-Foo {foo: 1A, bar: pi}              # constructing a struct
-
-let r: Foo = Foo {foo: 1A, bar: pi}
+let hydrogen = Element {         # Instantiate it
+    name: "Hydrogen",
+    atomic_number: 1,
+    density: 0.08988 g/L,
+}
 
-r.foo                               # Field access is performed with `.field` notation
+hydrogen.density                 # Access field of a struct