Structs with reference fields

Structs with references require explicitly setting the initial value to a reference value unless the struct already defines its own initial value.

Zero-value references, or nil pointers, will NOT be supported in the future, for now data structures such as Linked Lists or Binary Trees that rely on reference fields that can use the value 0, understanding that it is unsafe, and that it can cause a panic.

  1. struct Node {
  2. a &Node
  3. b &Node = 0 // Auto-initialized to nil, use with caution!
  4. }
  5. // Reference fields must be initialized unless an initial value is declared.
  6. // Zero (0) is OK but use with caution, it's a nil pointer.
  7. foo := Node{
  8. a: 0
  9. }
  10. bar := Node{
  11. a: &foo
  12. }
  13. baz := Node{
  14. a: 0
  15. b: 0
  16. }
  17. qux := Node{
  18. a: &foo
  19. b: &bar
  20. }
  21. println(baz)
  22. println(qux)