Commit Graph

568 Commits

Author SHA1 Message Date
Bob Tolbert
05899423df Changing --show_tracebacks to --show-tracebacks 2013-12-31 09:56:03 -07:00
Bob Tolbert
5040c29946 Cleaning up some comments from berker 2013-12-31 09:56:03 -07:00
Bob Tolbert
765dba3e56 More updates, including from Foxboron, for errors like (for) 2013-12-31 09:56:03 -07:00
Foxboron
f064d3f121 Errors into errors.py, added HyMacroExpansionError, fixed macro arg fail 2013-12-31 09:56:03 -07:00
Bob Tolbert
f6160c755a Much better version of new error messages.
This version is much simpler.

At the point that the exception is raised, we don't have access to
the actual source, just the current expression. but as the
exception percolates up, we can intercept it, add the source and
the re-raise it.

Then at the final point, in the cmdline handler, we can choose to
let the entire traceback print, or just the simpler, direct error
message.

And even with the full traceback, the last bit is nicely formatted
just like the shorter, simpler message.

The error message is colored if clint is installed, but to avoid
yet another dependency, you get monochrome without clint.

I'm sure there is a better way to do the markup, the current method
is kludgy but works.

I wish there was more shared code between HyTypeError and LexException
but they are kind of different in some fundamental ways.

This doesn't work (yet) with runtime errors generated from Python,
like NameError, but I have a method that can catch NameError and turn it
into a more pleasing output.

Finally, there is no obvious way to raise HyTypeError from pure Hy code,
so methods in core/language.hy throw ugly TypeError/ValueError.
2013-12-31 09:56:03 -07:00
Paul Tagliamonte
e754a58237 Merge branch 'master' into pr/363 2013-12-31 11:41:30 -05:00
Foxboron
426d34288f Added docs and one small bug fix in defreader 2013-12-31 15:46:21 +02:00
Abhishek L
0a80b87b7f Merge branch 'master' onto pr/395 2013-12-31 03:37:26 +05:30
Gergely Nagy
62522a5f86 Allow get with multiple arguments
When calling get with more than two arguments, treat the rest as indexes
into the expression from the former. That is, (get foo "bar" "baz")
would translate to foo["bar"]["baz"], and so on.

This fixes #362.

Requested-by: Sean B. Palmer <sean@miscoranda.com>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2013-12-30 12:04:40 +01: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
Kenan Bölükbaşı
3f590f8916 Reflect parameters of code.InteractiveConsele in HyREPL in order to make hy run inside Blender. 2013-12-29 01:22:16 +02:00
Paul Tagliamonte
9656c7f53c Add profiling macros 2013-12-28 11:25:27 -05:00
Bob Tolbert
55a7ab1667 add nil as synonym for None 2013-12-27 13:50:19 -07:00
Bob Tolbert
b2bb161cb0 Merge pull request #391 from olasd/bugfix/apply-method-call
Fix apply with method calls
2013-12-27 11:46:59 -08:00
Abhishek L
141f44c09f Merge branch 'olasd:feature/only-macroexpand-when-needed' 2013-12-27 11:50:39 +05:30
Paul Tagliamonte
1dc26148c6 Merge branch 'master' into paultag/ana/if
Conflicts:
	hy/contrib/anaphoric.hy
2013-12-26 17:57:29 -05:00
Abhishek L
c69c14cc7d contrib/anaphoric: More anaphoric macros added
* hy/contrib/anaphoric.hy: The following anaphoric macros have been
  added
  `ap-reject` : Opposite of ap-filter, yields the elements when a `pred`
  evaluates to false
  `ap-dotimes` : Execute body forms (possibly for side-effects) n times
  with `it` bound from 0 to n-1
  `ap-first` : return the first element that passes predicate
  `ap-last`  : return the last element that passes predicate
  `ap-reduce`: anaphoric form of reduce that allows `acc` and `it` to
  create a function that is applied over the list

* docs/contrib/anaphoric.rst: updated docs to reflect these changes

* tests/__init__.py: updated to explicitly include tests for anaphoric
  macros
2013-12-26 05:57:06 +02:00
Nicolas Dandrimont
81d5f08100 Only call macroexpand when needed
We only need to call macroexpand on HyExpressions,
as this is already guarded in macroexpand_1. This
saves us a few funcalls.
2013-12-26 03:00:24 +01:00
Paul Tagliamonte
6172b60e75 Add anaphoric if statement 2013-12-25 12:14:26 -05:00
Nicolas Dandrimont
cfbc792957 Fix apply with method calls
Apply didn't work on method calls (i.e. `(apply .foo [bar]) broke).
This slipped through because there were no tests of this behavior. I noticed
it while trying to merge the `meth` fixes.
2013-12-23 21:02:45 +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
Nicolas Dandrimont
ceb612f385 Merge branch 'fix/arith-identity' of https://github.com/theanalyst/hy into theanalyst-fix/arith-identity 2013-12-22 19:32:10 +01:00
Nicolas Dandrimont
799c39ffad Implement del
Closes #385.
2013-12-22 20:26:57 +02:00
Nicolas Dandrimont
0f96c24965 Make _storeize generic
This allows to change an expression's context to something else than ast.Store if needed.
2013-12-22 20:26:57 +02:00
Paul Tagliamonte
cccf90c702 Merge branch 'master' into pr/374 2013-12-22 13:22:39 -05:00
Bob Tolbert
3204c2a574 Fix for readline REPL problem Darwin Python3
On OS X Mavericks, the Hy REPL doesn't allow the 'b' character when
running with Python 3.3. This appears to be a common problem
for Darwin and readline as mentioned in this post

http://superuser.com/questions/297527/cant-type-the-b-letter-in-python-shell-in-os-x
2013-12-20 07:23:35 -07: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
f72ff53f41 Operators + and * work without args, fixes #372
Like other lisps, operators `+` and `*` return their identity values
when called with no arguments. Also with a single operand they return
the operand.

This fixes #372
2013-12-16 00:04:43 +05:30
Abhishek L
948e6d34c7 Merge branch master onto pr/284
Conflicts:
	hy/core/language.hy
2013-12-06 20:07:39 +05:30
Morten Linderud
699396b5a3 Merge pull request #358 from theanalyst/feature/macros-none
Allow macros to return None, fixes #357
2013-12-06 03:53:44 -08:00
Abhishek L
f1c68bd51a Allow macros to return None, fixes #357
Allows Hy macros to return None, to test this

  (defmacro foo [])
  (foo)

Should work now
2013-12-06 00:27:45 +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
f4f0972e6e Merge branch 'master' of https://github.com/hcarvalhoalves/hy into hcarvalhoalves-master 2013-12-05 19:10:34 +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
Nicolas Dandrimont
f9a1995be8 Make HyObject.replace more resilient
This makes it work on quoted objects
2013-12-04 03:25:33 +02:00
Morten Linderud
c933f703ff Merge pull request #349 from hcarvalhoalves/fix-osx-complete
Fix REPL completions on OS X
2013-12-02 21:01:35 -08:00
Henrique Carvalho Alves
1b7d7bcef7 Fix REPL completions on OS X 2013-12-03 01:07:05 -02: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
J Kenneth King
0b6d047239 Remove james@agentultra.com from copyright in core/macros.py 2013-11-30 10:35:57 -05:00
agentultra
5753fc0789 Fix typo in ap-map-when 2013-11-30 10:30:42 -05:00
agentultra
77db779019 Fix typo in ap-each 2013-11-30 10:29:41 -05:00
Henrique Carvalho Alves
62bc86a0b5 Fix sys.argv to reflect default Python behaviour
By default, calling the Python REPL without arguments causes
sys.argv to be a non-empty list with an empty string, and some
modules (e.g., pyNN) rely on that.
2013-11-29 23:51:41 -02:00
agentultra
cb6889314a Add documentation and doc strings 2013-11-29 19:59:20 -05:00
agentultra
179017b9bd Move anaphoric macros to contrib module 2013-11-28 23:53:02 -05:00
agentultra
20df6a5532 Make --map-when accept a predicate function instead of a form
This makes it look a little cleaner:

    (list (--map-when odd? (* it 3) [1 2 3 4 5]))
2013-11-28 16:45:07 -05:00
agentultra
8e44cc3d9a Add --each-while and --map-when
A couple of more macros:

    hy> (--each-while [1 2 3 4 5] (< it 3) (print it))
    1
    2
    3
    hy>

```--each-while``` continues to evaluate the body form while the
predicate form is true for each element in the list.

```--map-when``` uses a predicate form to determine when to apply the
map form upon the element in the list:

    hy> (list (--map-when (even? it) (* it 3) [1 2 3 4]))
    [1, 6, 3, 12]
2013-11-28 16:15:23 -05:00
agentultra
2106a0e5d4 Add anaphoric versions of map, filter, and foreach
Anaphoric macros reduce the need to specify a lambda by binding a
special name in a form passed as a parameter to the macro. This allows
you to write more concise code:

    (= (list (--filter (even? it) [1 2 3 4])) [2 4])

This patch just adds a few basic ones. Other forms that can be
converted to anaphoric versions include reduce, remove, enumerate,
etc.
2013-11-28 13:23:09 -05:00
Paul Tagliamonte
8c172c9c7e Prepare 0.9.11 2013-11-12 21:59:34 -05:00