hd-lang

A Tour of hd

Each page makes one claim about hd, explains in a few sentences why it matters, and gives you a program to run and change right in the page. Most pages also name a one-line edit that turns the program into a compile error, so you see the error the claim is about.

Start the tour

Contents

  1. Hello, hdA program starts at main, and main says what it may touch
  2. Values and mutA struct is a value, so a function changes yours only if you hand it over with &mut
  3. FunctionsA public signature is a contract, checked on both sides
  4. Strings and numbersA number never changes type on its own, so every conversion is in the code
  5. Enums and matchA match covers every case, so a new case can't be forgotten
  6. Option, not nullThere is no null: a value that may be missing says so in its type
  7. Errors and ?Errors are values in the return type, and ? passes them up
  8. Control flow as valuesif, match, and loops produce values, so a name is set once on every path
  9. PipesA pipe reads in the order things happen, and _ shows where the value goes
  10. Data and copy-with-changesA record says which fields are required, and ... copies one with changes
  11. Sharing with &mutTwo holders see one object only when you write &mut
  12. Element referencesfor p in &mut players changes the elements in place, and the list holds still while you do
  13. Lists are valuesA copy of a list never changes when the original does, and copying is cheap
  14. Generics and closuresOne generic function serves every type its bound allows, and the bound is checked
  15. Collections and iteratorsA list or map is typed by what it holds, and a lookup that may miss says so
  16. Traits and methodsA trait is a checked contract: leave out a method and the type doesn't compile
  17. Requirements and providersA signature lists what a function touches, so a test can hand it a fake
  18. TestsTests sit next to the code they check, with nothing to install
  19. Modules and pubA file shares only what it marks pub, so its helpers stay its own business
  20. Folders and packagesA folder's mod.hd lists what the folder offers, and another package is one more root
  21. Error enums and context.context turns a low-level failure into a report that says what you were doing
  22. Suspension and all!A function that can wait says so with !, and so does every call to it
  23. Least authority in mainmain's row is everything the program may touch
  24. DeriveOne @derive line gives a type random test inputs, so a property test finds the case you missed
  25. Where nextYou have seen the core of hd; the playground, the guide, and the spec go further

Want the syntax on one page? Read Learn hd in 10 Minutes.