# Type and methods info in macro

**URL:** <https://discourse.julialang.org/t/type-and-methods-info-in-macro/38199>\
**Category:** General Usage\
**Tags:** macros, type\
**Created:** [April 25, 2020, 4:40pm UTC](https://discourse.julialang.org/t/type-and-methods-info-in-macro/38199 "2020-04-25T16:40:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bpou/32/14320_2.png) [@bpou](https://discourse.julialang.org/u/bpou)\
**Post date:** [April 25, 2020, 4:40pm UTC](https://discourse.julialang.org/t/type-and-methods-info-in-macro/38199/1 "2020-04-25T16:40:01Z")

</div>

Hello,

I’ve been attempting to implement a simple APL in julia. Something similar has been done here: [https://github.com/shashi/APL.jl](https://github.com/shashi/APL.jl), but that is an interpreter. I wanted to do it as a syntax transformation to use as much existing julia code as possible.

The problem I’m having is parsing lines like `+ reduce v` where v is an Array. The trouble is, this could be parsed in two ways:

- `( + )( ( reduce )( v ) )` if both `+` and `reduce` takes a single argument
- `( reduce )( +, v )` if (correctly) `reduce` takes two arguments, a function and an Array

The second option is correct in this case, as `+ reduce v` is equivalent to `reduce(+, v)`. However, another input could be `- abs x`, which is equivalent to `-(abs(x))` if x is a number and should thus be parsed at `( - )( ( abs )( x ) )`.

My initial pipeline was a string macro doing something like

1. Tokenize string
2. Convert symbols like `+`, `reduce` and `v` to `Symbol`s
3. Use a `@generated` function to extract types from those `Symbols`
4. Use a disambiguation scheme to parse the resulting list of types
5. Convert the parsed tree from 4 into a julia `Expr` to return

My immediate problem is that `typeof(reduce)` isn’t really informative, but this is what I get in a `@generated` function. Ideally, I want to be able to use something like `applicable` but on the type level. This way, I could simply write

@generated function is\_applicable(f, x, y)  
type\_applicable(f, x, y)  
end

I haven’t been able to find anything like this.

My second concern is that splitting the string, converting to `Symbol`s and unquoting those into the expression seems kind of roundabout. Is there a better way to do what I’m going for?

Best regards and thanks in advance

- Andreas
