Based on Dylan's anaphora
Last active
June 14, 2021 18:35
-
-
Save pedro-w/859aa3c8bc7e3e2165b3901762b57075 to your computer and use it in GitHub Desktop.
if-let for Dylan
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: iflet | |
Synopsis: | |
Author: | |
Copyright: | |
define macro if-let | |
{ if-let (?:name = ?:expression) ?b1:body else ?b2:body end } | |
=> { let ?name = ?expression; | |
if(?name) ?b1 else ?b2 end } | |
{ if-let (?:name = ?:expression) ?:body end } | |
=> { let ?name = ?expression; | |
if(?name) ?body end } | |
end macro if-let; | |
define function main | |
(name :: <string>, arguments :: <vector>) | |
if-let (pos = position(arguments, "cat", test: \=)) | |
format-out("You have a cat at position %d\n", pos); | |
else | |
format-out("You don't have any cats\n"); | |
end; | |
exit-application(0); | |
end function main; | |
main(application-name(), application-arguments()); |
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: iflet | |
Synopsis: | |
Author: | |
Copyright: | |
define macro if-let | |
{ if-let ?:name = ?:expression ?b1:body else ?b2:body end } | |
=> { let ?name = ?expression; | |
if(?name) ?b1 else ?b2 end } | |
{ if-let ?:name = ?:expression ?:body end } | |
=> { let ?name = ?expression; | |
if(?name) ?body end } | |
end macro if-let; | |
define function main | |
(name :: <string>, arguments :: <vector>) | |
if-let pos = position(arguments, "cat", test: \=) | |
format-out("You have a cat at position %d\n", pos); | |
else | |
format-out("You don't have any cats\n"); | |
end; | |
exit-application(0); | |
end function main; | |
main(application-name(), application-arguments()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment