diff --git a/hy/contrib/anaphoric.hy b/hy/contrib/anaphoric.hy index d0a163a..38fd0bb 100644 --- a/hy/contrib/anaphoric.hy +++ b/hy/contrib/anaphoric.hy @@ -1,6 +1,7 @@ ;;; Hy anaphoric macros ;; ;; Copyright (c) 2013 James King +;; 2013 Paul R. Tagliamonte ;; ;; Permission is hereby granted, free of charge, to any person obtaining a ;; copy of this software and associated documentation files (the "Software"), @@ -23,6 +24,10 @@ ;;; These macros make writing functional programs more concise +(defmacro ap-if (test-form &rest args) + `(let [[it ~test-form]] (if it ~@args))) + + (defmacro ap-each [lst &rest body] "Evaluate the body form for each element in the list." `(foreach [it ~lst] ~@body)) diff --git a/tests/native_tests/contrib/anaphoric.hy b/tests/native_tests/contrib/anaphoric.hy index 7fb08f4..e57f184 100644 --- a/tests/native_tests/contrib/anaphoric.hy +++ b/tests/native_tests/contrib/anaphoric.hy @@ -31,6 +31,12 @@ (defn assert-equal [x y] (assert (= x y))) + +(defn test-ap-if [] + "NATIVE: testing anaphoric if" + (ap-if true (assert-true it)) + (ap-if false true (assert-false it))) + (defn test-ap-each [] "NATIVE: testing anaphoric each" (setv res [])