Last active
February 22, 2019 16:23
-
-
Save kfl/af8938855c48037847e0247790565563 to your computer and use it in GitHub Desktop.
even/odd in flat and sexp style
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
(module $evenodd | |
(export "even" (func $even)) | |
(export "odd" (func $odd)) | |
(func $even (param $n i32) (result i32) | |
get_local $n | |
i32.const 0 | |
i32.eq | |
if (result i32) | |
i32.const 1 | |
else | |
get_local $n | |
i32.const 1 | |
i32.sub | |
call $odd | |
end) | |
(func $odd (param $n i32) (result i32) | |
(if (result i32) | |
(i32.eq | |
(get_local $n) | |
(i32.const 0)) | |
(i32.const 0) | |
(call $even (i32.sub | |
(get_local $n) | |
(i32.const 1))))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use typed
if