Merge branch 'master' into pr/438
This commit is contained in:
commit
e0f9c9c191
1
AUTHORS
1
AUTHORS
@ -36,3 +36,4 @@
|
||||
* Tuukka Turto <tuukka.turto@oktaeder.net>
|
||||
* Vasudev Kamath <kamathvasudev@gmail.com>
|
||||
* Yuval Langer <yuval.langer@gmail.com>
|
||||
* Fatih Kadir Akın <fka@fatihak.in>
|
||||
|
BIN
docs/_static/cuddles-transparent-small.png
vendored
Normal file
BIN
docs/_static/cuddles-transparent-small.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
BIN
docs/_static/cuddles-transparent.png
vendored
Normal file
BIN
docs/_static/cuddles-transparent.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
@ -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
|
||||
<https://pypi.python.org/pypi/virtualenv>`_
|
||||
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 <https://pypi.python.org/pypi/hy>`_ 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
|
||||
|
@ -1,6 +1,7 @@
|
||||
;;; Hy tail-call optimization
|
||||
;;
|
||||
;; Copyright (c) 2014 Clinton Dreisbach <clinton@dreisbach.us>
|
||||
;; Copyright (c) 2014 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"),
|
||||
@ -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))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user