Last active
March 18, 2019 04:10
-
-
Save fudanchii/365dd7cef218c039045f89171617be3b to your computer and use it in GitHub Desktop.
imouto language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def-module luhn) | |
(use (Strings [reverse split parse]) | |
(Funcs [map reduce_indexed]) | |
(Funcs/Results [expect])) | |
(pub def-fn luhn (:: string bool) [bin] | |
(-<>> bin | |
(|> reverse) | |
(|> split <> "") | |
(|> map <> parse<uint32>) | |
(|> map <> expect "luhn: BIN (Bank Identification Number) expected") | |
(|> reduce_indexed <> luhn-elt 0) | |
(|> % <> 10) | |
(|> = 0))) | |
(def-fn luhn-elt (:: int int int int) [acu elt idx] | |
(if (= 0 (% idx 2)) | |
(+ acu elt) | |
(+ acu (let [n (* 2 elt)] | |
(if (> n 9) (- n 9) n))))) | |
; vim: ft=lisp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def-trait Eq<T> | |
(fn eq (:: &self T bool)) | |
(fn ne (:: &self T bool))) | |
(def-struct File | |
{ name string | |
size uint64 | |
fd uint64 | |
basedir string }) | |
(def-struct Symlink | |
{ path string | |
target string }) | |
(def-impl File | |
(Eq<Symlink> | |
(def-fn eq [&self sym] | |
(= (File/filepath self) (Symlink/target sym))) | |
(def-fn ne [&self sym] | |
(!= (File/filepath self) (Symlink/target sym)))) | |
(File | |
(def-fn filepath (:: &self string) [&self] | |
(concat (File/basedir self) (File/name self))))) | |
(def-fn main [] | |
(let [f (File { | |
.name "test" | |
.size 12312 | |
.fd 99 | |
.basedir "/tmp" }) | |
s (Symlink { | |
.path "/tmp/another_one" | |
.target "/tmp/test" })] | |
(do | |
(= f s)))) | |
; vim: ft=lisp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment