Skip to content

Instantly share code, notes, and snippets.

@darius
Created December 2, 2023 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darius/342109fa899ca0aa1ea3251ec919c59d to your computer and use it in GitHub Desktop.
Save darius/342109fa899ca0aa1ea3251ec919c59d to your computer and use it in GitHub Desktop.
;; "The ultimate conditional syntax" by Lionell Parreaux, examples
;; (untested translations to Cant)
;; Example 1
(hm (may some-value
(be {none} 0))
(let _ (console .log "It's not none!"))
(may some-value
(be {some {~ {some name} {left str}}}
(do [(name name.capitalize)]
(may value
(be "" (chain name " has no value"))
(be str (chain name " has value " str)))))
(be {some {none} (or {right} {left})}
"anonymous")))
;; Figure 1
(may name
(be (-- (? (~ .prefix? "_"))
(-> ~.tail-option {some name-postfix})
(when (every ~.digit? name-postfix))
(-> ||name-postfix.to-int-option {some index})
(when (and (< 0 index) (<= index arity))))
{right {~ index name}})
(else
{left name}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment