m'fn kwargs

This commit is contained in:
Paul Tagliamonte 2012-12-22 23:07:09 -05:00
parent 81820abace
commit 87b602fc9f
4 changed files with 20 additions and 10 deletions

View File

@ -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!

View File

@ -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.

View File

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

View File

@ -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']