Skip to content

Instantly share code, notes, and snippets.

@yloiseau
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yloiseau/c9e5c816e8cd04e4c3ea to your computer and use it in GitHub Desktop.
Save yloiseau/c9e5c816e8cd04e4c3ea to your computer and use it in GitHub Desktop.
yet another macro use case for golo

Yet another macro use case for golo

actual working code...

module SomeFunctions

function bar = |somethingWithV, a, b| -> somethingWithV: v() + a + b
module SomeTypes

struct Foo = {v}

function foo = |aFoo, a, b, x| -> aFoo: bar(a, b) + " " + x

&augmentWithFunctions(SomeTypes.types.Foo.class, ^SomeFunctions::bar, ^foo)
module Test

import SomeTypes

function main = |args| {
  let f = Foo(1)
  println(f: foo(2, 3, ":)"))
}
$ golo golo --files functions.golo types.golo test.golo
6 :)

The macro actually expand to

augment SomeTypes.types.Foo {

  function foo = |this, args...| -> ^foo: bindTo(this): invoke(args)

  function bar = |this, args...| -> ^SomeFunctions::bar: bindTo(this): invoke(args)
}
@jponge
Copy link

jponge commented May 5, 2015

🆒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment