Skip to content

Instantly share code, notes, and snippets.

@pedro-w
Last active June 14, 2021 18:35
Show Gist options
  • Save pedro-w/859aa3c8bc7e3e2165b3901762b57075 to your computer and use it in GitHub Desktop.
Save pedro-w/859aa3c8bc7e3e2165b3901762b57075 to your computer and use it in GitHub Desktop.
if-let for Dylan
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());
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