Add anaphoric if statement

This commit is contained in:
Paul Tagliamonte 2013-12-25 12:11:25 -05:00
parent 744cd71171
commit 6172b60e75
2 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
;;; Hy anaphoric macros
;;
;; Copyright (c) 2013 James King <james@agentultra.com>
;; 2013 Paul R. Tagliamonte <tag@pault.ag>
;;
;; 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))

View File

@ -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 [])