louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | import std/io |
| 2 | |
| 3 | // The HTTP-router match of issue #295 (a string and a list of strings): |
| 4 | // its decision tree's leaves call the arms' lifted continuations, so the |
| 5 | // Core is linear in the arms. |
| 6 | fn route :: method: String segments: List<String> -> String |
| 7 | { |
| 8 | match (method, segments) |
| 9 | { ("GET", ["archive"]) -> "archive" |
| 10 | , ("GET", ["search"]) -> "search" |
| 11 | , ("GET", ["trash"]) -> "trash" |
| 12 | , ("GET", ["label", label]) -> "label " <> label |
| 13 | , ("POST", ["notes", note]) -> "revise " <> note |
| 14 | , ("GET", ["notes", note, "edit"]) -> "edit " <> note |
| 15 | , ("POST", ["notes", note, "tag"]) -> "tag " <> note |
| 16 | , ("POST", ["notes", note, verb]) -> verb <> " " <> note |
| 17 | , _ -> "missing" |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | pub fn main :: -> () / <io> |
| 22 | { |
| 23 | io.println (route "POST" ["notes", "n", "pin"]) |
| 24 | io.println (route "GET" ["archive"]) |
| 25 | io.println (route "GET" ["search"]) |
| 26 | io.println (route "GET" ["trash"]) |
| 27 | io.println (route "GET" ["label", "x"]) |
| 28 | io.println (route "POST" ["notes", "n"]) |
| 29 | io.println (route "GET" ["notes", "n", "edit"]) |
| 30 | io.println (route "POST" ["notes", "n", "tag"]) |
| 31 | io.println (route "PUT" ["archive"]) |
| 32 | io.println (route "GET" []) |
| 33 | io.println (route "GET" ["archive", "extra"]) |
| 34 | } |
| 35 | //> pin n |
| 36 | //> archive |
| 37 | //> search |
| 38 | //> trash |
| 39 | //> label x |
| 40 | //> revise n |
| 41 | //> edit n |
| 42 | //> tag n |
| 43 | //> missing |
| 44 | //> missing |
| 45 | //> missing |