Last active
February 19, 2017 20:57
-
-
Save blackode/cb14d767765197d5d1b0eeb9f19653c6 to your computer and use it in GitHub Desktop.
Defiinig the macros and Testing
This file contains hidden or 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
| defmodule WhileLoop do | |
| defmacro while(condition_expression, do: do_block) do | |
| quote do | |
| try do | |
| for _ <- Stream.cycle([:fine]) do | |
| if(unquote(condition_expression)) do | |
| unquote do_block | |
| else | |
| WhileLoop.break | |
| end | |
| end | |
| catch | |
| :break -> :ok | |
| end | |
| end | |
| end | |
| def break, do: throw :break | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment