slurp 0.0.0.9000
  • Reference
  • Articles
    • 03. Control Flow
    • 02. Data Types
    • 01. Getting Started

    03. Control Flow

    control_flow.Rmd

    Source for inspiration: https://riptutorial.com/common-lisp/example/11082/conditional-constructs

    If

    ;;(if (predicate)
    ;;    (do this if true...)
    ;;  (do this if false...))
    
    (if (TRUE)
        (print "This is true")
      (print "This is false")) ;; will always print "This is true"
    
    ;; use progn for multiline statements
    (if (TRUE)
        (progn
          (print "Test1")
          (print "Test2"))
      (print "No tests"))
    ;; this prints Test 1 then Test 2 and returns Test2

    When

    ;; short hand for if with only one path
    (when (> 3 4)
      (print "I got here")
      "Three is bigger than four")
    ;; prints "I got here" and returns "Three is bigger than four"

    Unless

    ;; The inverse of when, runs body only when condition is false
    (unless (> 3 4)
      "Three is not bigger than four!")
    ;; Returns "Three is not bigger than four!"

    Cond

    ;; run multiple conditions in one body
    (cond ((> 3 4) "Three is bigger than four!")
          ((> 3 3) "Three is bigger than three!")
          ((> 3 2) "Three is bigger than two!"))
    ;; Returns "Three is bigger than two!"

    Contents

    Developed by Jay Morgan.

    Site built with pkgdown 1.6.1.