Jelajahi Sumber

Update syntax example to include logical operators

David Peter 1 tahun lalu
induk
melakukan
96b722e127
2 mengubah file dengan 8 tambahan dan 8 penghapusan
  1. 4 4
      book/src/example-numbat_syntax.md
  2. 4 4
      examples/numbat_syntax.nbt

+ 4 - 4
book/src/example-numbat_syntax.md

@@ -92,10 +92,10 @@ unit thing                       # New base unit with automatically generated
 
 # 8. Conditionals
 
-fn step(x: Scalar) -> Scalar =   # The construct 'if <cond> then <expr> else <expr>'
-  if x < 0                       # is an expression, not a statement. It can span
-    then 0                       # multiple lines.
-    else 1
+fn bump(x: Scalar) -> Scalar =   # The construct 'if <cond> then <expr> else <expr>'
+  if x >= 0 && x <= 1            # is an expression, not a statement. It can span
+    then 1                       # multiple lines.
+    else 0
 
 # 9. Procedures
 

+ 4 - 4
examples/numbat_syntax.nbt

@@ -87,10 +87,10 @@ unit thing                       # New base unit with automatically generated
 
 # 8. Conditionals
 
-fn step(x: Scalar) -> Scalar =   # The construct 'if <cond> then <expr> else <expr>'
-  if x < 0                       # is an expression, not a statement. It can span
-    then 0                       # multiple lines.
-    else 1
+fn bump(x: Scalar) -> Scalar =   # The construct 'if <cond> then <expr> else <expr>'
+  if x >= 0 && x <= 1            # is an expression, not a statement. It can span
+    then 1                       # multiple lines.
+    else 0
 
 # 9. Procedures