JInterface question

Ulf Wiger ulf@REDACTED
Tue Jun 21 06:51:33 CEST 2005

Den 2005-06-20 23:09:29 skrev Vlad Dumitrescu  

> If your data may contain strings or general lists, and you don't know  
> beforehand which one it is, then it's a little tricky. You have to  
> handle both cases.

On the Erlang side, one may perhaps borrow a page from the UBF book
(well, the feature was wholly undocumented, except for the code ;-)

-define(S(S), {'#S', S}).

s(Str) -> {'#S', S}.

Perfectly obvious, no?

The idea is that the ?S macro is used in pattern match as a
deconstructor, and the s/1 function is used as a constructor,
and all strings become wrapped in a tagged tuple.

handle_call({hello, ?S(S)}, State) ->
    S1 = s(lists:reverse(S)),
    {reply, {hello, S1}, State}.


More information about the erlang-questions mailing list