Add anaphoric if statement
This commit is contained in:
parent
744cd71171
commit
6172b60e75
@ -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))
|
||||
|
@ -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 [])
|
||||
|
Loading…
x
Reference in New Issue
Block a user