hilariously debuggable lisp: Hy
If anyone wants to check out some new Hy stuff, check out the REPL 3.0 at hy.pault.ag
Also, check out the GitHub Repo, and star it, or consider contributing to it.
Hang tight, this is technical -- Hopefully you're a rockn' Pythonista already. If not, hang on!
Right, so, here's the Hython we're working with:
;;;; testing.hy (import-from sunlight openstates) (defn get-legislators [state] "Get some Legislators from a state" (kwapply (.legislators openstates) {"state" state})) (defn print-legislator-count [state] "Print the Legislative count for a state" (print (len (get-legislators state))))
And a Python script to run it:
#!/usr/bin/env python import hy import testing # import pdb; pdb.set_trace() testing.print_legislator_count("ma")
Which outputs (correctly): 198.
Now, let's try and debug this sucker:
I added import pdb; pdb.set_trace() to the top of the Pythonic script (after the imports), to drop into a pdb shell:
> /home/tag/tmp/invoke.py(8)() -> testing.print_legislator_count("ma") (Pdb)
(Pdb) l 3 import hy 4 import testing 5 6 import pdb; pdb.set_trace() 7 8 -> testing.print_legislator_count("ma") [EOF]
(Pdb) s --Call-- > /home/tag/tmp/testing.hy(12)print_legislator_count() -> (defn print-legislator-count [state]
Whoh! Right! We've just invoked Lisp. Let's step through the Lisp code:
> /home/tag/tmp/testing.hy(14)print_legislator_count() -> (print (len (get-legislators state)))) (Pdb) --Call-- > /home/tag/tmp/testing.hy(7)get_legislators() -> (defn get-legislators [state] (Pdb) > /home/tag/tmp/testing.hy(9)get_legislators()->[ (SNIP) ] -> (kwapply (.legislators openstates) {"state" state})) (Pdb) l 4 (import-from sunlight openstates) 5 6 7 (defn get-legislators [state] 8 "Get some Legislators from a state" 9 -> (kwapply (.legislators openstates) {"state" state})) 10 11 12 (defn print-legislator-count [state] 13 "Print the Legislative count for a state" 14 (print (len (get-legislators state)))) (Pdb)
Rockn'. This worked hilariously well.
-> (kwapply (.legislators openstates) {"state" state})) (Pdb) state 'ma'
Whoh, right there. Look at that! Python's pdb has access to Hy's bits! Neat :)
And. just to prove it's actually Python :)
(Pdb) s 198 --Return-- > /home/tag/tmp/testing.hy(14)print_legislator_count()->None -> (print (len (get-legislators state)))) (Pdb) s --Return-- > /home/tag/tmp/invoke.py(8)()->None -> testing.print_legislator_count("ma")
Whoo! From Python to Lisp and back!
Now, for fun, here's some pudb action:
And, now, some bpython voodoo:
Hopefully this is the start of something wicked neat! :)