Add anaphoric if statement
This commit is contained in:
parent
744cd71171
commit
6172b60e75
@ -1,6 +1,7 @@
|
|||||||
;;; Hy anaphoric macros
|
;;; Hy anaphoric macros
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2013 James King <james@agentultra.com>
|
;; 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
|
;; Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
;; copy of this software and associated documentation files (the "Software"),
|
;; copy of this software and associated documentation files (the "Software"),
|
||||||
@ -23,6 +24,10 @@
|
|||||||
;;; These macros make writing functional programs more concise
|
;;; 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]
|
(defmacro ap-each [lst &rest body]
|
||||||
"Evaluate the body form for each element in the list."
|
"Evaluate the body form for each element in the list."
|
||||||
`(foreach [it ~lst] ~@body))
|
`(foreach [it ~lst] ~@body))
|
||||||
|
@ -31,6 +31,12 @@
|
|||||||
(defn assert-equal [x y]
|
(defn assert-equal [x y]
|
||||||
(assert (= 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 []
|
(defn test-ap-each []
|
||||||
"NATIVE: testing anaphoric each"
|
"NATIVE: testing anaphoric each"
|
||||||
(setv res [])
|
(setv res [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user