Skip to content

Julia functions with easier interaction with a given type and its fields

License

Notifications You must be signed in to change notification settings

fcard/SelfFunctions.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SelfFunctions

Installation

  Pkg.clone("https://github.com/fcard/SelfFunctions.jl")

Introduction

This package allows the creation of functions that have easier interaction with a given type, by having an instance of it as an implicit argument and having access to its fields directly.

Usage

Use preexisting type

  using SelfFunctions

  type MyType
    x::Int
  end
  @selftype self MyType

Define and then use type

  using SelfFunctions

  @selftype self type MyType
    x::Int
  end

Usage of the generated macro

  @self function inc()
    x += 1
  end

  @self function inc2()
    inc()
    inc()
  end

  const mt = MyType(0)

  inc(mt)  # mt.x: 0 -> 1
  inc2(mt) # mt.x: 1 -> 3

TODO

  • Add utilities.

About

Julia functions with easier interaction with a given type and its fields

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages