Commit Graph

41 Commits

Author SHA1 Message Date
Gergely Nagy
3f01ed5014 Add a Botsbuildbots function
A tribute to Portal 2, this function will return an infinite list of the
contents of the AUTHORS file on GitHub master (assuming requests is
installed). Except, the macro does this, the function never gets called,
it is purely there for tribute reasons.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-09-05 12:37:51 +02:00
John MacKenzie
15ad6cb998 defmacro/g! and HyObject#startswith
Currently, defmacro/g! doesn't respond well when it comes across a
HyObject that doesn't respond to the instance method startswith (e.g.
HyInteger, HyFloat, etc.). This updates defmacro/g! to be a little
safer when searching for the gensyms it needs to create.
2014-05-15 01:51:38 +00:00
Tuukka Turto
726d1735db Merge branch 'master' into pr/571
Conflicts:
	AUTHORS
	tests/native_tests/core.hy
2014-05-13 09:32:51 +03:00
Paul Tagliamonte
ca0271df95 Merge branch 'master' into pr/574
Conflicts:
	AUTHORS
2014-05-12 20:15:51 -04:00
Tuukka Turto
b1a928037e Merge branch 'master' into pr/526 2014-05-02 10:34:37 +03:00
Matthew Wampler-Doty
f2f38a1cf8 Refactor for loop to use cond 2014-04-22 16:47:42 -07:00
Matthew Wampler-Doty
5c9a8f8975 Closes #573, restores 0.9.12 for loop behavior (and everyone wins!) 2014-04-22 08:57:18 -07:00
Matthew Wampler-Doty
43f63e9ae7 Shortening docstring 2014-04-21 13:17:40 -07:00
Matthew Wampler-Doty
834b0019a7 Fixing doto to be API compatible with Clojure's doto 2014-04-21 12:35:56 -07:00
Tuukka Turto
21cff9d14f initial implementation for doto macro
relates #567
2014-04-21 08:04:03 +03:00
Paul Tagliamonte
217f3ad65f Merge branch 'master' into pr/515 2014-04-10 22:52:41 -04:00
Christopher Allan Webber
d5194f23fa Properly add yield-from, using python's real "yield from".
The yield-from that existed previously wasn't actually implementing the
full complexity of "yield from":

  http://legacy.python.org/dev/peps/pep-0380/#formal-semantics

... this includes passing along errors, and many other things.

Also removes the yield-from backport macro, since it does not seem
possible at present to conditionally build macros.

Thus, there is no longer yield-from on pre-python-3.3 systems.

Includes updated docs and tests to reflect all this.
2014-04-10 14:07:49 -05:00
Christopher Allan Webber
774aad2ca8 defmain macro; handles the whole if __name__ == __main__ / main function dance
Example:

  (defmain [&rest args]
    (print "now we're having a fun time!")
    (print args))

Which outputs:

  $ hy test.hy
  now we're having a fun time!
  (['test.hy'],)

Includes documentation and tests.
2014-04-10 13:58:38 -05:00
Christopher Allan Webber
f3d978c5a3 Added lisp-if (or lif), with tests and documentation.
Now everyone can get along and everyone can have a pony, and that pony is
actually a unicorn that shoots rainbows from its horn.
2014-04-10 13:51:28 -05:00
Berker Peksag
3528cc8278 Kill kwapply.
Closes #433.
2014-04-09 20:10:31 +03:00
Berker Peksag
6829d6fb3a Tweak the zipwith doc a bit and add @kirbyfan64 to AUTHORS. 2014-02-22 02:21:34 +02:00
kirbyfan64
d282d65cde Add zipwith 2014-02-22 02:14:27 +02:00
Nicolas Dandrimont
b99af411c8 Merge branch 'master' into pr/461
Conflicts:
	tests/native_tests/native_macros.hy
2014-01-23 21:57:17 +01:00
Gergely Nagy
3bad6c14ee
hy/core/macros.hy: Reimplement (unless) in terms of (if-not)
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-01-18 22:57:29 +01:00
Gergely Nagy
e90b24b73a
hy/core/macros.hy: Add an (if-not) macro
Sometimes it is better to start with the false condition, sometimes that
makes the code clearer. For that, the (if-not) macro, which simply
reverses the order of the condition blocks, can be of great use.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-01-18 22:56:20 +01:00
Gergely Nagy
21709f0199 hy/core/macros.hy: Add defn-alias / defun-alias
In the same vein as defmacro-alias, this implements defn-alias /
defun-alias, which does essentially the same thing as defmacro-alias,
but for functions.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
2014-01-18 16:09:35 +01:00
Foxboron
a35ecc41bd Fix reader macros to actually be macros 2014-01-17 01:07:47 +01:00
Paul Tagliamonte
5fc047e77c Merge branch 'master' into pr/425
Conflicts:
	hy/core/language.hy
2014-01-12 12:48:26 -05:00
Paul Tagliamonte
cc2f45be69 slice is amazing, @olasd is amazing, I love everything. 2014-01-10 22:50:20 -05:00
Paul Tagliamonte
0f74b1ddf3 Add handling for (for []). Nice catch, @olasd. 2014-01-10 22:29:20 -05:00
Paul Tagliamonte
2167c21120 Adjust (for) to just use itertools.product
This is to avoid nesting in for loops, helping make clear
 what (break) and (else) do.

 This commit is hereby dedicated to @nedbat
2014-01-10 22:00:30 -05:00
Clinton N. Dreisbach
849244f3b4 Make first and rest fns instead of macros
car and cdr are still macros, but I'd recommend either making them
fns or removing them.
2014-01-10 13:46:31 -05:00
Paul Tagliamonte
eeef65b505 Change the signature of (for) and (with).
(for) is restored to clojure-like flatness.
 (with) can be used without the nested list if you don't care about the
        name.

   Tests and examples updated.
2013-12-31 13:35:31 -05:00
Bob Tolbert
765dba3e56 More updates, including from Foxboron, for errors like (for) 2013-12-31 09:56:03 -07:00
Foxboron
d82636958b added for and with macros
Fixed up anaphoric.hy and added the tests too native_tests/__init__.py

added __init__.hy
2013-12-29 16:50:21 +01:00
Foxboron
c9fdd40c9f Hy reader macros #377
Added first iteration of reader macros
Refactored defmacro and defreader
Added test inn hy/tests/lex/test_lex.py
Added new test in hy/tests/native/tests
Added new test in hy/tests/macros.

changed the error given in the dispatch macro and added some handling for missing symbol and invalid characters
2013-12-23 14:33:51 +01:00
Nicolas Dandrimont
ec2b5fb7ad Merge branch 'kwapply-macro' of https://github.com/Willyfrog/hy into Willyfrog-kwapply-macro
Conflicts:
	hy/core/language.hy
	hy/core/macros.hy
	tests/native_tests/language.hy
2013-12-22 20:03:00 +01:00
Bob Tolbert
c80e3c75a0 Adding automatic gensym macro
Adding to the manual gensym for macros are 2 new
macros, but very literal from the CL in
letoverlambda.

The first is the (with-gensyms ...) macro that
can generate a small set of syms for a macro. Works
something like:

(defmacro adder2 [A B]
  (with-gensyms [a b]
    `(let [[~a ~A] [~b ~B]]
       (+ ~a ~b))))

and ~a and ~b will be replaced with (gensym "a") and
(gensym "b") respectively.

Then the final macro is a new defmacro that will automatically
replace symbols prefaced with "g!" with a new gensym based on the
rest of the symbol. So in this final version of 'nif':

(defmacro/g! nif4 (expr pos zero neg)
  `(let [[~g!result ~expr]]
     (cond [(pos? ~g!result) ~pos]
           [(zero? ~g!result) ~zero]
           [(neg? ~g!result) ~neg])))

all uses of ~g!result will be replaced with (gensym "result").
2013-12-15 18:47:46 -07:00
Bob Tolbert
f5d88bb108 gensym in Hy
Simple implementation of gensym in Hy.

Returns a new HySymbol.

Usable in macros like:

(defmacro nif [expr pos zero neg]
  (let [[g (gensym)]]
    `(let [[~g ~expr]]
       (cond [(pos? ~g) ~pos]
             [(zero? ~g) ~zero]
             [(neg? ~g) ~neg]))))

This addresses all the general comments about (gensym), and doesn't
try to implement "auto-gensym" yet. But clearly the macro approach
instead of the pre-processor approach (as described in the
letoverlambda (http://letoverlambda.com/index.cl/guest/chap3.html#sec_5)
is the way to go
2013-12-15 12:36:36 -07:00
Guillermo Vaya
687f2c790f Adding olasd's improvements 2013-11-03 11:11:21 +01:00
Guillermo Vaya
0f525a691d removed unnecessary import 2013-11-03 11:11:11 +01:00
Nicolas Dandrimont
59e51166fb Allow calling kwapply with mixed names and dicts 2013-11-02 20:50:21 +01:00
Guillermo Vaya
f5754b404e Define kwapply as a macro
Define apply if python3
Added apply tests
2013-11-02 18:18:16 +01:00
Nicolas Dandrimont
875d5f2ff5 Rewrite the bootstrap macros in hy
This gets rid of the dichotomy between bootstrap.py and macros.hy,
by making both files hy modules.

I added some error checking to make the macros more resilient. The
biggest (user-visible) change is the change in cond, which now only
accepts lists as arguments. Tests updated accordingly.

Closes: #176 (whoops, no more bootstrap)
2013-09-29 18:13:28 +02:00
Konrad Hinsen
b11f2fcf49 Macro if-python2 for compile-time choice between Python 2 and Python 3 code branches 2013-09-02 09:58:35 +02:00
Paul Tagliamonte
1c12b2870e Add yield from via macro magic.
This will let us use (basic) yield from behavior from Python 2. This
 isn't complete, and is low-hanging fruit for others willing to hack
 on hy.

 I've also changed the macrosystem to allow for proper bootstrapping.
 This is similar to how it's done elsewhere in the codebase (stdlib
 stuff).
2013-08-17 11:37:48 -04:00