Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variadic if #962

Merged
merged 1 commit into from
Oct 18, 2015
Merged

variadic if #962

merged 1 commit into from
Oct 18, 2015

Conversation

gilch
Copy link
Member

@gilch gilch commented Oct 14, 2015

The if form now supports elif clauses.
It works like cond but without the implicit do.

closes #830.

The old if is still available as if*, but you don't need it since the 2- and 3- argument cases work exactly as before.

@tuturto
Copy link
Contributor

tuturto commented Oct 14, 2015

Looking sweet. Can't wait for this to be available. Can you add docs for this?

@algernon algernon added this to the Grand Language Cleanup milestone Oct 14, 2015
@gilch
Copy link
Member Author

gilch commented Oct 15, 2015

Just realized this kind of breaks lif. The 2- or 3-arg versions work as before, but truthiness is Pythonic for the elif (ellif?) clauses, which would be surprising. I wonder if there are other unintended consequences. I think I'll have to rewrite lif, but it doesn't look difficult.

@gilch
Copy link
Member Author

gilch commented Oct 15, 2015

Hm. Why is this failing? I ran nosetests before committing "variadic lif" without trouble. What was merged between my two commits? #920 "if-no-waste" (0585754) and #950 "f/one-arg-comparators" (b875fec).

The complaint is

HyMacroExpansionError: expanding `cond': UnboundLocalError("local variable '_hy_anon_var_1' referenced before assignment",)

That is not supposed to be possible just from writing a macro. Something's wrong with the compiler.

@gilch
Copy link
Member Author

gilch commented Oct 15, 2015

I think I found it. The "if-no-waste" is looking for 'if', but should look for 'if*' now.

@gilch
Copy link
Member Author

gilch commented Oct 15, 2015

Are the -* functions like for* part of the public API, or are they considered implementation details subject to change? It might affect how it's documented. I'm assuming public for now.

@gilch
Copy link
Member Author

gilch commented Oct 15, 2015

@tuturto docs added.

@tuturto
Copy link
Contributor

tuturto commented Oct 15, 2015

looking good, 👍 from me. Could squash and rebase before merge, we have been a bit sloppy about that.

@gilch
Copy link
Member Author

gilch commented Oct 16, 2015

@kirbyfan64 docs fixed.
@tuturto squashed and rebased to hylang/master. All checks have passed.

@gilch
Copy link
Member Author

gilch commented Oct 17, 2015

@hylang/core variadic if looks ready, but need second ack to merge.

the evaluation of the condition is ``False``.
``if / if* / if-not`` respect Python *truthiness*, that is, a *test* fails if it
evaluates to a "zero" (including values of ``len`` zero, ``nil``, and
``false``), and passes otherwise, but values with a ``__nonzero__`` method can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"values with a __bool__ method (or __nonzero__ on Python 2)"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch here. I think it would be preferable if Hy were consistent across host implementations, but that seems difficult to fix in this case. I'll mention __bool__ as the default and __nonzero__ as the special case for Python2.

@zackmdavis
Copy link
Contributor

_+1_ (I left some quibbling comments, but nothing that can't be addressed in a follow-up commit.)

The `if` form now supports elif clauses.
It works like `cond` but without the implicit `do`.
The old `if` is now `if*`

variadic lif now supports "ellif" clauses.

Update if-no-waste compiler to use `if*` properly.

(Sometimes one character is all it takes.)

document if

reword truthiness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

better elif
4 participants