Skip to content

Provides a simple macro to make readable anonymous functions in Julia

License

Notifications You must be signed in to change notification settings

MasonProtter/LegibleLambdas.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LegibleLambdas

Build Status

Legible Lambdas for Julia.

Installation

In julia v1.0+, type ] to enter package mode, and:

pkg> add LegibleLambdas

Introduction

LegibleLambdas.jl provides a macro (and an alias @lambda) for defining a type of anonymous function which is printed in a nicer form than the relatively uninformative gensyms of traditional anonymous functions.

Compare the printing of

julia> f = x -> x + 1
#1 (generic function with 1 method)

with

julia> using LegibleLambdas

julia> g = (x -> x + 1)
(x -> x + 1)

This 'just works' inside most closures too!

julia> D(f, ϵ=1e-10) = (x -> (f(x+ϵ)-f(x))/ϵ)
D (generic function with 2 methods)

julia> D(sin)
(x -> ((sin)(x + 1e-10) - (sin)(x)) / 1e-10)

julia> D(sin, 0.01)
(x -> ((sin)(x + 0.01) - (sin)(x)) / 0.01)

License

MIT License