如何在Julia中创建用于创建符号的宏 [英] How to create a macro for creating a symbol in Julia

查看:132
本文介绍了如何在Julia中创建用于创建符号的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建字符串文字宏在Julia中创建symbol,因此s"x":x相同.它不起作用:

I am trying to create a string literal macro in Julia to create a symbol, so that s"x" is the same as :x. It does not work:

julia> macro s_str(p)
           symbol(p)
       end

julia> s'x'
ERROR: s not defined

julia> s"x"
ERROR: x not defined

推荐答案

原因是这很容易阅读,或者做得更复杂但等效.

which is easy to read, or do the more complicated but equivalent.

macro s_str(p)
  esc(:(symbol($p)))
end

这篇关于如何在Julia中创建用于创建符号的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆