Commit Graph

301 Commits

Author SHA1 Message Date
kirbyfan64
d282d65cde Add zipwith 2014-02-22 02:14:27 +02:00
han semaj
24a1567b00 Implement every? and some 2014-02-11 21:42:56 +13:00
Abhishek L
a41a3c7edc faster distinct: maintain seen items in a set
* hy/core/language.hy: maintain the seen items in a set instead of a
  list in `distinct`. This is much faster for lookups.
2014-02-04 01:35:41 +05:30
Abhishek L
4432c00c59 Replace forgotten instances of coll? function
Replacing coll? wherever applicable
2014-02-03 21:48:30 +05:30
Abhishek L
4b54e3c748 Merge master onto pr/471
Conflicts:
	hy/core/language.hy
2014-01-30 21:50:23 +05:30
James King
cbb8cc1d37 Add integer-char? to core 2014-01-28 17:28:41 -05:00
Nicolas Dandrimont
52144820ca Add a cons object and related mechanisms
Closes: #183
2014-01-23 23:08:52 +01:00
Nicolas Dandrimont
fad67bd8f5 Merge branch 'master' into pr/468 2014-01-23 22:14:23 +01: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
Abhishek L
10f1f24a18 Adding a simple `identity' function
* hy/core/language.hy: Adding a simple `identity` function that returns
  the argument supplied to it

* docs/language/core.rst: Updated docs with identity function
2014-01-22 00:56:28 +05:30
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
Nicolas Dandrimont
1e793e696a Fix indentation of *exports* 2014-01-12 17:34:05 +01:00
Abhishek L
f159f1499b Adding a simple coll? function to the core
* hy/core/language.hy:
  -Added a simple coll? function that checks whether the given argument
  is an iterable and not a string,
  - Also replaced the check in `flatten` by coll?

* tests/native_tests/core.hy: Tests updated for checking coll?
2014-01-12 15:49:09 +05:30
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
Nicolas Dandrimont
d3fa1fd1a8 Add disassemble function to hy.core.language
This function dumps the AST or the python code generated by evaluating a quoted expression to stdout.

Fixes #58
2014-01-04 03:47:04 +01:00
Nicolas Dandrimont
2f7d40b409 Factor the calling-module-name function 2014-01-03 21:41:14 +01:00
Nicolas Dandrimont
88451bbeaa Merge branch 'better-macroexpand' of https://github.com/sbp/hy into sbp-better-macroexpand
Conflicts:
	hy/core/language.hy
	tests/native_tests/language.hy
2014-01-02 00:49:40 +01:00
Bob Tolbert
032200bcb4 Some small doc fixes
This cleans up a number of doc warnings, including a bad
underline for zero?

While there, added a nil? function to match up with the
new nil is None.

Also un-hid myself from coreteam.
2013-12-31 16:14:05 -07: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
Abhishek L
948e6d34c7 Merge branch master onto pr/284
Conflicts:
	hy/core/language.hy
2013-12-06 20:07:39 +05:30
Nicolas Dandrimont
cc147512fc Merge branch 'paultag/feature/support-question-marks' of https://github.com/paultag/hy into paultag-paultag/feature/support-question-marks
Conflicts:
	hy/core/language.hy
2013-12-05 19:28:59 +01:00
Nicolas Dandrimont
f0a9149383 Merge branch 'string-cast' of https://github.com/Willyfrog/hy into Willyfrog-string-cast 2013-12-05 19:04:22 +01:00
Paul Tagliamonte
fd60a864eb Translate all foo? -> is_foo. Close #334
The fancypants Hy award goes to Nick for coming up with the quoted
symbol hack for exports. This broke with foo?, since the export string
needs to be is_foo, but using a quoted string will pick up the change
due to it being a Symbol.

Mad clown love for that, @olasd.
2013-12-01 15:03:31 -05: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
06628dbba5 Fully qualify the HyTypeError reference
No need to import it explicitly, the hy module is available everywhere.
2013-10-17 18:53:43 +02:00
Sean B. Palmer
c34db29ba8 Fixed --name-- scope problem using ugly inspect code 2013-10-11 14:30:55 +01:00
Sean B. Palmer
defccc6853 Added macroexpand-1 2013-10-11 13:50:10 +01:00
Sean B. Palmer
a34db9119b Add macroexpand to core/language.hy 2013-10-11 11:55:14 +01:00
Guillermo Vaya
34275fab60 Added type coercing to the right integer for the platform 2013-10-11 08:35:32 +02:00
Guillermo Vaya
25bf3dec42 Add a method for casting into byte string or unicode depending on python version 2013-10-03 23:39:17 +02:00
Nicolas Dandrimont
a90c866327 Rewrite language.hy not to require hy.core.macros
As was intended when the bootstrap and core macros were separated.
2013-09-29 18:13:28 +02: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
Bob Tolbert
7e8a7edbdc finally fixed access to hy.core.macros here. have to explicitly require them 2013-09-14 12:17:06 -06:00
Bob Tolbert
d9dee8ec67 One more commit to change the test for Python 2/3 to a macro
Note that this can't use the macro in hy.core.macros so there
is a local copy in language.hy
2013-09-03 18:41:11 -06:00
Bob Tolbert
9d2ad4b4ff slightly cleaner version of drop-while, could use yield-from when ready 2013-09-03 13:52:00 -06:00
Bob Tolbert
399ea1889a Second (smaller) set of native core functions
This rounds out the first pass at a set of core functions, adding
some that were not in the first PR.

From here I'm working on a contrib.seq and contrib.io module to
hold less obvious but maybe interesting native functions that can
move to core if desired.

This should also close out issure #150 asking for some core
functions like these.
2013-09-03 13:52:00 -06:00
Paul Tagliamonte
b2c51d0130 Merge branch 'master' into pr/287 2013-09-02 22:55:31 -04:00
kaizoku
b892ec4e66 Add zero? predicate to check if an object is zero 2013-09-02 02:28:21 -07: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
Bob Tolbert
41ae4f4d2c Update:
Updated most methods to replace While with For, and added tons of new tests
    for things like (cycle []) and lists with None's in them.

    thanks @olasd

Add set of new core functions

Add set of new core functions to the stdlib.

Moved the auto-import code from compile_expression to
HySymbol so that "even?' in this style expression will
be found and imported.

(list (filter even? [1 2 3 4 5]))

The core functions are documented in 2 sections, one
for basic functions like (even?..) and (nth ...) and
one for all the sequence functions.

Update: This removes all the caching decorators, misnamed as
'lazy-seq' from the core. All sequence methods now just use
yield to return a generator, so they are Python-lazy

Further refinements of core functions

Cleaned up the docs to use 'iterator' instead of 'generator'

Fixed drop to just return the iterator instead of an extra
yield loop. But also added a test to catch dropping too
many.
2013-07-29 08:52:28 -06:00
Paul Tagliamonte
3dde930ede Merge branch 'master' into pr/236 2013-07-16 20:57:29 -04:00
Bob Tolbert
62f1f40830 Add set of new core functions
Add set of new core functions to the stdlib.

Moved the auto-import code from compile_expression to
HySymbol so that "even?' in this style expression will
be found and imported.

(list (filter even? [1 2 3 4 5]))

The core functions are documented in 2 sections, one
for basic functions like (even?..) and (nth ...) and
one for all the sequence functions.

Update: This removes all the caching decorators, misnamed as
'lazy-seq' from the core. All sequence methods now just use
yield to return a generator, so they are Python-lazy

Further refinements of core functions

Cleaned up the docs to use 'iterator' instead of 'generator'

Fixed drop to just return the iterator instead of an extra
yield loop. But also added a test to catch dropping too
many.
2013-07-13 09:55:16 -06:00
Joe H. Rahme
236ebccc74 Removes setf in favor of setv 2013-07-10 02:16:49 +02:00
Paul Tagliamonte
b78be9a594 Jank @olasd's hack, clean up core.
The core shall from now on be only for the core language bits. Macro
 bits shall live in hy.macros and in hy.compiler. This cleans up
 garbage.
2013-07-06 14:00:11 -04:00
Paul Tagliamonte
86af7eacf1 Add in a new core language file.
This will let us implement common functions seen in other lisps,
 and allow them to be importable, without explicit imports. The goal
 is to keep this as small as we can; we don't want too much magic.

 I've added `take' and `drop' as examples of what we can do.
2013-06-29 18:51:11 -04:00
Konrad Hinsen
269da19d76 Make macros module-specific.
A macro is available in the module where it was defined and
in any module that does a require of the defining module.
Only macros defined in hy.core are globally available.
Fixes #181
2013-05-16 15:34:14 +02:00
Nicolas Dandrimont
0986f9001e Change macros to be called with separate arguments
This provides free argument-length checking for macros.
2013-05-11 09:09:34 +02:00
Julien Danjou
a0285903e6 Cleanup
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-05-05 20:42:48 +02:00
Nicolas Dandrimont
510ad53c71 mangles kthxbye 2013-05-05 20:42:48 +02:00
Julien Danjou
2ef9a0fdaf Rename decorate-with' to with-decorator'
Fixes #158

Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-28 17:14:22 +02:00
Julien Danjou
f25177e9a6 Add a `unless' macro
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-28 17:04:35 +02:00
Julien Danjou
f68e3b972b Add a `when' macro
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-28 17:04:35 +02:00
Julien Danjou
c241236bf5 Remove useless class attribute
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-22 14:58:05 +02:00
John Jacobsen
8d8dd62168 Move take and drop from AST impl. in compiler.py to macros in core/bootstrap.py 2013-04-21 19:08:30 -05:00
Julien Danjou
07860b5ce6 Allow variable without value in `let' declaration
Fixes issue #138

Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-20 05:18:45 -07:00
Paul R. Tagliamonte
aadf47ed99 documenting hy.core.mangles 2013-04-18 22:50:46 -04:00
Paul R. Tagliamonte
d3a019b3dd Don't quote things in (quote) - Closes #129 2013-04-17 23:20:56 -04:00
Paul R. Tagliamonte
db3e2bd346 updating the nested mangles 2013-04-11 22:25:23 -04:00
Paul R. Tagliamonte
e22a0ff73c Mangle a macro until it stops moving
this helps if we use a macro in something that got tree-mangled
  back out.
2013-04-07 18:41:41 -04:00
Paul R. Tagliamonte
bfc71e4a60 Add tail threading (->>) 2013-04-07 15:05:30 -04:00
Paul R. Tagliamonte
03dfbde1b8 style voodoo 2013-04-06 23:11:43 -04:00
Paul R. Tagliamonte
e0ed7cac40 Revert "Make HySymbol bytes free!"
This reverts commit 8b144a4f3d.
2013-04-06 20:02:08 -04:00
Julien Danjou
8b144a4f3d Make HySymbol bytes free!
We can know use any amount and type of bytes to build a HyString, meaning we
can use Unicode and UTF-8 for our function and variables.

Eat that, snake!

Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-06 23:37:34 +02:00
Paul R. Tagliamonte
4b57fd0a51 Adding in an If mangle 2013-04-06 11:10:33 -04:00
Paul R. Tagliamonte
7abc472336 Implementing `let' 2013-04-05 21:54:04 -04:00
Paul R. Tagliamonte
d762625aeb also ignore setf / setv 2013-04-05 20:00:19 -04:00
Paul R. Tagliamonte
1d01d8874a Bugfix for #50. I'm slowly starting to take a shine to this. 2013-04-05 19:29:31 -04:00
Paul R. Tagliamonte
7c9fa3758c Print is for loosers. 2013-04-04 21:50:01 -04:00
Paul R. Tagliamonte
256506ede0 Sketch for #50 - branch mangler
This is only slightly better. The insert point needs to walk
    with the for loop.
2013-04-04 21:47:00 -04:00
Christopher Allan Webber
f8be07b643 Defun is now an alias for defn 2013-04-01 16:36:56 -05:00
Christopher Allan Webber
9416422330 Changing cond to be more common lisp / emacs lisp like
Instead of:
  (cond (condition-1) (body-1)
        (condition-2) (body-2))

We now work like:

  (cond ((condition-1) (body-1)
         (condition-2) (body-2)))
2013-04-01 10:33:45 -05:00
Paul R. Tagliamonte
83a9bdc87d adding in rest macros 2013-03-18 19:49:36 -04:00
Paul R. Tagliamonte
8f6c77831b Adding first' / car' 2013-03-18 16:11:29 -04:00
Paul R. Tagliamonte
4cb4e7384e holy shit it's 2013 2013-03-18 10:27:14 -04:00
Paul R. Tagliamonte
0bc2dd8d00 Moving `for' to a "macro" 2013-03-13 20:41:53 -04:00
Paul R. Tagliamonte
a238ac53c3 Adding back Python 2.6. 2013-03-13 20:02:16 -04:00
Paul Tagliamonte
57775a95a6 Fiddling with the threading macro 2013-03-13 10:11:14 -04:00
Paul R. Tagliamonte
daa6443e7c Adding in a Threading macro (->) 2013-03-12 22:04:51 -04:00
Paul R. Tagliamonte
276df1b103 thinking through some manglers. 2013-03-09 16:34:35 -05:00
Paul R. Tagliamonte
a19d085620 Adding in better things. 2013-03-09 15:10:49 -05:00
Paul R. Tagliamonte
ab2cf5beda futzing with condlike things. 2013-03-09 00:17:02 -05:00
Paul R. Tagliamonte
8c07829ff9 thinking about some new stuff. 2013-03-08 23:07:21 -05:00
Paul Tagliamonte
67b803b99a Breaking things to start again. 2013-03-08 18:18:43 -05:00
Paul R. Tagliamonte
3166fec53e Thinking some ideas out. 2013-03-07 22:52:47 -05:00