From 87b602fc9ffc60548fc403c949a8fd36b27ff2b5 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Sat, 22 Dec 2012 23:07:09 -0500 Subject: [PATCH] m'fn kwargs --- AUTHORS | 3 ++- COPYRIGHT | 1 - eg/ma-legs.hy | 11 +++-------- hy/compiler/ast27.py | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 7ba5488..b649238 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,4 +7,5 @@ I'd also like to thank the following people: - Kragen Sitaker: Major thanks goes to Kragen on helping me work through some of the namespacing crap. I think the majority of the approach taken now - with expressions' eval bits is his doing in one way or another. + with expressions' eval bits for modfaker is his doing in one + way or another. Thank you! diff --git a/COPYRIGHT b/COPYRIGHT index 1d999cd..afc91b2 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -17,4 +17,3 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/eg/ma-legs.hy b/eg/ma-legs.hy index d8d5e1c..c4545b1 100644 --- a/eg/ma-legs.hy +++ b/eg/ma-legs.hy @@ -2,13 +2,8 @@ ; Copyright (c) Paul Tagliamonte, in sofar as any of this is at all ; copyrightable. -(import ["sunlight"]) +(import "sunlight") -(foreach - (kwapply (sunlight.openstates.legislators) {"state" "ma"}) - (fn [x] (print [ - (get x "first_name") - (get x "last_name") - (get x "party") - ]))) +(for [x (kwapply (sunlight.openstates.legislators) {"state" "ma"})] + (print x)) diff --git a/hy/compiler/ast27.py b/hy/compiler/ast27.py index 66da473..2c50ca2 100644 --- a/hy/compiler/ast27.py +++ b/hy/compiler/ast27.py @@ -123,6 +123,7 @@ class AST27Converter(object): "doseq": self._ast_for, "for": self._ast_for, + "kwapply": self._ast_kwapply, } def _def(self, node): @@ -138,6 +139,20 @@ class AST27Converter(object): ) return ret + def _ast_kwapply(self, node): + i = node.get_invocation() + args = i['args'] + fn = args.pop(0) + kwargs = args.pop(0) + ret = self.render(fn) + ret.keywords = [ + ast.keyword( + arg=str(x), + value=self.render(kwargs[x]) + ) for x in kwargs + ] + return ret + def _ast_while(self, node): i = node.get_invocation() args = i['args']