diff --git a/AUTHORS b/AUTHORS index 0d77a98..775db60 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,3 +36,4 @@ * Tuukka Turto * Vasudev Kamath * Yuval Langer +* Fatih Kadir Akın diff --git a/docs/_static/cuddles-transparent-small.png b/docs/_static/cuddles-transparent-small.png new file mode 100644 index 0000000..1570db6 Binary files /dev/null and b/docs/_static/cuddles-transparent-small.png differ diff --git a/docs/_static/cuddles-transparent.png b/docs/_static/cuddles-transparent.png new file mode 100644 index 0000000..8f16ebd Binary files /dev/null and b/docs/_static/cuddles-transparent.png differ diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 5bdb130..79a9255 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -2,20 +2,20 @@ Quickstart ========== -.. image:: _static/cuddles.png +.. image:: _static/cuddles-transparent-small.png :alt: Karen Rustard's Cuddles -(thanks to Karen Rustad for Cuddles!) +(Thanks to Karen Rustad for Cuddles!) -HOW TO GET HY REAL FAST: +**HOW TO GET HY REAL FAST**: -1. create a `Python virtual environment +1. Create a `Virtual Python Environment `_ -2. activate your Python virtual environment -3. ``pip install hy`` -4. start a REPL with ``hy`` -5. type stuff in the REPL:: +2. Activate your Virtual Python Environment +3. Install `hy from PyPI `_ with ``pip install hy`` +4. Start a REPL with ``hy`` +5. Type stuff in the REPL:: => (print "Hy!") Hy! @@ -25,20 +25,19 @@ HOW TO GET HY REAL FAST: etc -6. hit CTRL-D when you're done +6. Hit CTRL-D when you're done OMG! That's amazing! I want to write a hy program. -7. open up an elite programming editor -8. type:: +7. Open up an elite programming editor and type:: - (print "i was going to code in python syntax, but then i got hy") + (print "I was going to code in python syntax, but then I got hy.") -9. save as ``test_program_of_awesome.hy`` -10. run:: +8. Save as ``awesome.hy`` +9. And run your first Hy program:: - hy test_program_of_awesome.hy + hy awesome.hy -11. take a deep breath so as to not hyperventilate -12. smile villainously and sneak off to your hydeaway and do +10. Take a deep breath so as to not hyperventilate +11. Smile villainously and sneak off to your hydeaway and do unspeakable things diff --git a/hy/contrib/loop.hy b/hy/contrib/loop.hy index 73526fa..2c2690a 100644 --- a/hy/contrib/loop.hy +++ b/hy/contrib/loop.hy @@ -1,6 +1,7 @@ ;;; Hy tail-call optimization ;; ;; Copyright (c) 2014 Clinton Dreisbach +;; Copyright (c) 2014 Paul R. Tagliamonte ;; ;; Permission is hereby granted, free of charge, to any person obtaining a ;; copy of this software and associated documentation files (the "Software"), @@ -55,7 +56,24 @@ (recursive-replace old-term new-term term)] [True term]) [term body]))) -(defmacro loop [bindings &rest body] + +(defmacro/g! fnr [signature &rest body] + (let [[new-body (recursive-replace 'recur g!recur-fn body)]] + `(do + (import [hy.contrib.loop [--trampoline--]]) + (with-decorator + --trampoline-- + (def ~g!recur-fn (fn [~@signature] ~@new-body))) + ~g!recur-fn))) + + +(defmacro defnr [name lambda-list &rest body] + (if (not (= (type name) HySymbol)) + (macro-error name "defnr takes a name as first argument")) + `(setv ~name (fnr ~lambda-list ~@body))) + + +(defmacro/g! loop [bindings &rest body] ;; Use inside functions like so: ;; (defun factorial [n] ;; (loop [[i n] @@ -67,13 +85,7 @@ ;; If recur is used in a non-tail-call position, None is returned, which ;; causes chaos. Fixing this to detect if recur is in a tail-call position ;; and erroring if not is a giant TODO. - (with-gensyms [recur-fn] - (let [[fnargs (map (fn [x] (first x)) bindings)] - [initargs (map second bindings)] - [new-body (recursive-replace 'recur recur-fn body)]] - `(do - (import [hy.contrib.loop [--trampoline--]]) - (def ~recur-fn - (--trampoline-- (fn [~@fnargs] - ~@new-body))) - (~recur-fn ~@initargs))))) + (let [[fnargs (map (fn [x] (first x)) bindings)] + [initargs (map second bindings)]] + `(do (defnr ~g!recur-fn [~@fnargs] ~@body) + (~g!recur-fn ~@initargs))))