[erlang-questions] Should erlang have macro FUNCTION_ARGS ?
Richard A. O'Keefe
ok@REDACTED
Mon Aug 7 23:18:27 CEST 2017
On 7/08/17 8:22 PM, Zhongzheng Liu wrote:
>> I don't think this *CAN* work in the presence of maps.
> I think it can work with temporary variable.
>
> foo(X, [a,b,c], 42) ->
> ?FUNCTION_ARGS.
>
> will become:
>
> foo(X=__TEMP_1__, [a,b,c]=__TEMP_2__, #{ b := Y }=__TEMP_3__) ->
> [__TEMP_1__, __TEMP_2__, __TEMP_3__] .
>
> It will work with maps.
OK, but now you are asking for something other than a macro.
One key thing about a macro is that expanding a macro
invocation has no effect whatsoever on the token sequence
outside that invocation.
It seems to me that if you really want this feature,
you should use the machinery that already exists for
the purpose. That is, you should write a parse
transform. Parse transforms can pretty much rewrite
anything to anything, and you don't have to wait for
anyone else to change the Erlang system, you can just
plug in your own parse transform any time you want.
More information about the erlang-questions
mailing list