Unpythonic

Latest version: v0.15.1

Safety actively analyzes 625513 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 7

0.14.0

**Bugfixes**:

- ``setup.py``: macros are not zip safe, because ``ZipImporter`` fails to return source code for the module and MacroPy needs that.
- fix splicing in the ``do[]`` macro; ``ExpandedDoView`` should now work correctly
- fix lambda handling in the ``lazify`` macro
- fix ``dict_items`` handling in ``mogrify`` (fixes the use of the ``curry`` macro with code using ``frozendict``)

**New**:

- ``roview``: a read-only view into a sequence. Behaves mostly the same as ``view``, but has no ``__setitem__`` or ``reverse``.
- ``mg``: a decorator to mathify a gfunc, so that it will ``m()`` the generator instances it makes.
- The ``do[]`` macro now supports ``delete[name]`` to delete a local variable previously created in the same do-expression using ``local[name << value]``.
- ``envify`` block macro, to make formal parameters live in an unpythonic ``env``.
- ``autoref`` block macro, to implicitly reference attributes of an object (for reading only).

**Breaking changes**:

- The ``macropy3`` bootstrapper now takes the ``-m`` option; ``macropy3 -m somemod``, like ``python3 -m somemod``. The alternative is to specify a filename positionally; ``macropy3 somescript.py``, like ``python3 somescript.py``. In either case, the bootstrapper will import the module in a special mode that pretends its ``__name__ == '__main__'``, to allow using the pythonic conditional main idiom also in macro-enabled code.
- The constructor of the writable ``view`` now checks that the input is not read-only (``roview``, or a ``Sequence`` that is not also a ``MutableSequence``) before allowing creation of the writable view.
- ``env`` now checks finalization status also when deleting attrs (a finalized ``env`` cannot add or delete bindings)

**Non-breaking improvements**:

- ``env`` now provides also the ``collections.abc.MutableMapping`` API.
- The ``tco`` macro now skips nested ``continuations`` blocks (to allow [Lispython](https://github.com/Technologicat/pydialect/tree/master/lispython) in [Pydialect](https://github.com/Technologicat/pydialect) to support ``continuations``).
- ``setup.py`` now installs the ``macropy3`` bootstrapper.

---

0.13.1

**New**:

- `view`: writable, sliceable view into a sequence. Use like `view(lst)[::2]`. Can be nested (i.e. sliced again). Any access (read or write) goes through to the original underlying sequence. Can assign a scalar to a slice à la NumPy. Stores slices, not indices; works also if the length of the underlying sequence suddenly changes.
- `islice`: slice syntax support for `itertools.islice`, use like `islice(myiterable)[100:10:2]` or `islice(myiterable)[42]`. (It's essentially a curried function, where the second step uses the subscript syntax instead of the function call syntax.)
- `prod`: like `sum`, but computes the product. A missing battery.
- `iindex`: like `list.index`, but for iterables. A missing battery. (Makes sense mostly for memoized input.)
- `inn(x, iterable)`: contains-check (`x in iterable`) for monotonic infinite iterables, with [automatic](http://wiki.c2.com/?LazinessImpatienceHubris) termination.
- `getattrrec`, `setattrrec` (**rec**ursive): access underlying data in an onion of wrappers.
- `primes` and `fibonacci` generators, mainly intended for testing and usage examples.
- ``SequenceView`` and ``MutableSequenceView`` abstract base classes; ``view`` is a ``MutableSequenceView``.

**Breaking changes**:

- The `fup[]` utility macro to functionally update a sequence **is gone and has been replaced** by the `fup` utility function, with slightly changed syntax to accommodate. New syntax is like `fup(lst)[3:17:2] << values`. (This is a two-step curry utilizing the subscript and lshift operators.)
- `ShadowedSequence`, and hence also `fupdate`, now raise the semantically more appropriate `IndexError` (instead of the previous `ValueError`) if the replacement sequence is too short.
- `namelambda` now returns a modified copy; the original function object is no longer mutated.

**Non-breaking improvements**:

- `ShadowedSequence` now supports slicing (read-only), equality comparison, `str` and `repr`. Out-of-range access to a single item emits a meaningful error, like in `list`.
- `env` and `dyn` now provide the `collections.abc.Mapping` API.
- `cons` and friends: `BinaryTreeIterator` and `JackOfAllTradesIterator` now support arbitarily deep cons structures.

---

0.13.0

**New**:

- ``lazify`` macro: call-by-need for Python (a.k.a. lazy functions, like in Haskell)
- ``frozendict``: an immutable dictionary
- ``mogrify``: in-place ``map`` for mutable containers
- ``timer``: a context manager for performance testing
- `s`: create lazy mathematical sequences. For example, `s(1, ...)`, `s(1, 2, ...)`, `s(1, 2, 4, ...)` and `s(1, 2, ...)**2` are now valid Python. Regular function, no macros.
- `m`: endow any iterable with infix math support. (But be aware that after that, applying an operation meant for general iterables drops the math support; to restore it, `m(result)` again.)
- The ``unpythonic.llist`` module now provides ``JackOfAllTradesIterator`` that understands both trees and linked lists (with some compromises).
- ``nb`` macro: a silly ultralight math notebook.

**Breaking changes**:

- ``dyn``: the ``asdict`` and ``items`` methods now return a live view.
- The mutable single-item container ``Box`` and its data attribute ``value`` have been renamed to ``box`` and ``x``, respectively.
- ``namedlambda`` macro: Env-assignments are now processed lexically, just like regular assignments. Added support for let-bindings.
- ``curry`` macro: The special mode for uninspectables is now enabled lexically within the ``with curry`` block. Also, manual uses of the ``curry`` decorator (on both ``def`` and ``lambda``) are now detected, and in such cases the macro now skips adding the ``curry`` decorator.

**Non-breaking improvements**:

- ``namelambda`` now supports renaming any function object, and also multiple times.
- The single-item special binding syntax is now supported also by the bindings block of the ``dlet``, ``dletseq``, ``dletrec``, ``blet``, ``bletseq`` and ``bletrec`` macros.

---

0.12.0

*What does "metamagical" mean? To me, it means "going one level beyond magic". There is an ambiguity here: on the one hand, the word might mean "ultramagical" - magic of a higher order - yet on the other hand, the magical thing about magic is that what lies behind it is always nonmagical. That's metamagic for you!*
--Douglas R. Hofstadter, *On Self-Referential Sentences* (essay, 1981)

**New**:

- Alternative, haskelly ``let`` syntax ``let[((x, 2), (y, 3)) in x + y]`` and ``let[x + y, where((x, 2), (y, 3))]``
- Supported by all ``let`` forms: ``let``, ``letseq``, ``letrec``, ``let_syntax``, ``abbrev``
- When making just one binding, can now omit outer parentheses in ``let``: ``let(x, 1)[...]``, ``let[(x, 1) in ...]``, ``let[..., where(x, 1)]``
- ``unpythonic.misc.Box``: the classic rackety single-item mutable container
- Many small improvements to documentation

**Breaking changes**:

- New, perhaps more natural ``call_cc[]`` syntax for continuations, replaces earlier ``with bind[...]``
- Conditional continuation capture with ``call_cc[f() if p else None]``
- ``cc`` parameter now added implicitly, no need to declare explicitly unless actually needed (reduces visual noise in client code)
- Local variables in a ``do`` are now declared using macro-expr syntax ``local[x << 42]``, looks more macropythonic
- Silly ``(lambda)`` suffix removed from names of named lambdas (to detect them in client code, it's enough that ``isinstance(f, types.LambdaType)``)

---

0.11.1

**Enhancements**:

- Create a proper decorator registry for the syntax machinery.
- Can now register priorities for custom decorators to tell the syntax system about their correct ordering (for ``sort_lambda_decorators``, ``suggest_decorator_index``).
- Register priorities for (some of) unpythonic's own decorators using this new system, replacing the old hardcoded decorator registry.
- Now lives in ``unpythonic.regutil``; used only by the syntax subsystem, but doesn't require MacroPy just to start up.
- Try to determine correct insertion index for ``trampolined`` and ``curry`` decorators in macros that insert them to ``decorator_list`` of ``FunctionDef`` nodes (using any already applied known decorators as placement hints, [like a programmer would](http://wiki.c2.com/?LazinessImpatienceHubris)).
- ``namedlambda``: recognize also decorated lambdas, and calls to ``curry`` where the last argument is a lambda (useful for ``looped_over`` et al.).

**Breaking change**:

- Remove the special jump target ``SELF``.
- Was always a hack; no longer needed now that v0.11.0 introduced the general solution: the ``withself`` function that allows a lambda to refer to itself anywhere, not just in a ``jump``.
- Now the whole thing is easier to explain, so likely a better idea ([ZoP](https://www.python.org/dev/peps/pep-0020/) §17, 18).

---

0.11.0

New:

- Add callwith: freeze arguments, choose function later
- Add withself: allow a lambda to refer to itself
- Add let_syntax: splice code at macro expansion time
- Add quicklambda: block macro to combo our blocks with MacroPy's quick_lambda
- Add debug option to MacroPy bootstrapper

Enhancements:

- prefix macro now works together with let and do

Bugfixes:

- detect TCO'd lambdas correctly (no longer confused by intervening FunctionDef nodes with TCO decorators)
- scoping: detect also names bound by For, Import, Try, With

Breaking changes:

- Rename dynscope --> dynassign; technically dynamic assignment, not scoping
- Rename localdef --> local; shorter, more descriptive
- scanr now returns results in the order computed (**CAUTION**: different from Haskell)
- simple_let, simple_letseq --> let, letseq in unpythonic.syntax.simplelet
- cons now prints pythonically by default, to allow eval; use .lispyrepr() to get the old output
- Remove separate dynvar curry_toplevel_passthrough; expose curry_context instead

Other:

- Reorganize source tree, tests now live inside the project
- Pythonize runtests, no more bash script
- Add countlines Python script to estimate project size

---

Page 2 of 7

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.