symbol concatenation in a macro?

1,389 views
Skip to first unread message

Steven G. Johnson

unread,
Dec 21, 2012, 11:42:29 PM12/21/12
to juli...@googlegroups.com
Simple question here, I just couldn't find it in the manual.

How do you concatenate symbols, e.g. make :ab from :a and :b? "*" works
for strings but not for symbols.

More specifically, I want to do this in a macro:

for f in (:a,:b,:c)
@eval begin
$(f) = ...
$(f * :_2) = ...
end
end

and have it define a, b, c and also a_2, b_2, and c_2.

Thanks!

John Myles White

unread,
Dec 22, 2012, 12:06:10 AM12/22/12
to juli...@googlegroups.com
One cheap way to do this is by converting to strings, doing concatenation, then converting to symbols again:

symbol(string(:a) * string(:b))

-- John
> --
>
>
>

Isaiah Norton

unread,
Dec 22, 2012, 12:09:37 AM12/22/12
to juli...@googlegroups.com
Convoluted, but:

julia> for f in (:a,:b,:c)
         @eval begin
           $(f) = 111
           $(symbol(string(f, :_2))) = 222
         end
       end





--




Steven G. Johnson

unread,
Dec 22, 2012, 12:35:56 AM12/22/12
to juli...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages