c42f / MagicUnderscores.jl

Convenient function argument placeholders for julia

Repository from Github https://github.comc42f/MagicUnderscores.jlRepository from Github https://github.comc42f/MagicUnderscores.jl

MagicUnderscores

A prototype implementation for underscore notation in julia. See JuliaLang/julia#24990 (comment).

Build Status

Quick Start

Here's an example, showing how _ can be used as a placeholder when using the @_ macro from this package.

julia> using MagicUnderscores

julia> @_ map(sqrt(abs(_)) + 1, [-1,4])
3-element Array{Float64,1}:
 2.0
 3.0

In this case, this is just slightly shorter syntax for the following

julia> map(x->sqrt(abs(x)) + 1, [-1,4])
3-element Array{Float64,1}:
 2.0
 3.0

The interesting thing about the approach taken in this package is that the tightness of the _ binding may be tight or loose, depending on the implementation of MagicUnderscores.ubind for your particular function. For example, filter is bound loosely on the second argument so that filter(f, _) means x->filter(f,x), whereas filter(_>2, a) means filter(x->x>2, a). This can be very useful in piping, for example:

julia> @_ [1,2,3,4] |> filter(_>2, _)
2-element Array{Int64,1}:
 3
 4

julia> @_ [1,2,3,4] |> filter(_>2, _) |> length
2

About

Convenient function argument placeholders for julia

License:Other


Languages

Language:Julia 100.0%