首页 \ 问答 \ 如何在球拍中本地更改阅读规则?(How to locally change reading rules in racket?)

如何在球拍中本地更改阅读规则?(How to locally change reading rules in racket?)

我正在考虑在Racket中嵌入J ,并且因为我找到了一个现有的项目 ,所以我想在此基础上进行构建。 就像现在一样,通过将J程序字符串传递给Racket表单来进行评估:

> (j "4 * 1 + 4")
> 20


> (j 4 * 1 + 4)
> 20

这对应于评估Racket表单的cdr ,显然需要在本地更改阅读器 。 但是,当我尝试将评估功能更改为:

(define (j exp)
  (jeval #reader"jexp.rkt" exp))

我得到一个“未绑定的标识符”错误,因为输入端口'exp'被解释为litterally而不用'exp'替换它的值。 我该如何管理?

I am looking into embedding J in Racket, and since I found an existing project, I'd like to build upon that. As it is now, evaluation happens by passing a J program string to a Racket form:

> (j "4 * 1 + 4")
> 20

Since J makes use of quotes, double quotes, and other ASCII characters that require escaping when passed as a string, I would like to change the evaluation strategy to:

> (j 4 * 1 + 4)
> 20

which corresponds to evaluating the cdr of the Racket form, and apparently would require to locally change the reader. However, when I try to change the evaluation function to something like:

(define (j exp)
  (jeval #reader"jexp.rkt" exp))

I get an "unbound identifier" error, since the input-port ' exp' is interpreted litterally without substituting 'exp' for its value. How can I manage that?

更新时间:2019-12-13 07:38


像这样改变读者不是可以在解析过程的后期完成的事情。 在你给出的例子中,Racket如何知道嵌入式J程序何时结束?



Altering the reader like this is not something that can be done late in the parsing process. In the example you give, how is Racket supposed to know when the embedded J program ends?

I think you want to take a look at the "Creating a Language" portion of the Racket Guide:





如何减少android SQLite中的自动增量_id?(How to decrease the Auto increment _id in android SQLite?)

编辑:也许我应该说清楚只是插入具有正确id的行而不是操纵序列号肯定比下面的方法更好。 如果表中没有id = 3的行,则即使在AUTOINCREMENT表中也可以在id中插入固定值。 也就是说,如果您确定 ,可以使用自动增量值设置为任意值; UPDATE sqlite_sequence set seq=<next sequence no -1> where name=<table name>; 也就是说,如果你想在表'TableA'上的下一个插入中使用AUTOINCREMENT来生成5,那么你可



  • NumPy标量,广播和__iadd__方法(NumPy scalars, broadcasting and the __iadd__ method)
  • 快速排序算法输出错误(Getting wrong output for quicksort algorithm)
  • Rails管理员:没有Rails 4应用程序的编辑,显示或删除按钮(Rails Admin: No edit, show, or delete buttons for Rails 4 app)
  • 部分刷新问题触发两次(Issue with partial refresh triggered twice)
  • jsPlumb draggable element javascript函数(jsPlumb draggable element javascript function)
  • MVC4:ViewModel(带有radiobuttonlist)在HttpPost之后为空(MVC4: ViewModel (with radiobuttonlist) is empty after HttpPost)
  • 如何在同一帐户上设置“Dev repo”(在prod和团队之间)(How to set up a “Dev repo” (between the prod and the team) on the same account)
  • 如何在tcl中将eth0配置为发送方udp端口(how to configure eth0 as a sender udp port in tcl)
  • EF6.1 beta 1如何获得Tooling Consolidation功能?(EF6.1 beta 1 how to get the Tooling Consolidation feature?)
  • 适用于Windows和PHP 5.5的Phalcon(Phalcon for Windows and PHP 5.5)
  • 有没有办法忽略hg责任中的提交?(Is there a way to ignore a commit in hg blame?)
  • Desire2通过API学习访问学期的权限(Desire2Learn Permissions to Access Semesters Via API)
  • 从aspx将服务器的文件复制到另一台服务器(Copy a file of a server to another server from aspx)
  • 使用YSlow / Web Developer扩展程序确定页面大小(Figuring out page size with YSlow / Web Developer extension)
  • Select语句将字符串中的前7个字符与其他表中的其他7个字符进行比较(Select statement which compares first 7 chars in a string with other 7 chars in other table)
  • 检测对注册表的更改,防止更改等(Detect changes to registry, prevent changes, etc)
  • 用户的鼠标/键盘运动分析是否有特殊名称?(Does the analysis of mouse/keyboard motions of a user have a special name?)
  • 获取Rails中资源的路由列表(Get list of routes for a resource in Rails)
  • 用函数值除以数字(Divide a function value by a number)
  • 熊猫Python:如何从今天开始创建失效列?(Pandas Python: How to create lapse since today column?)
  • GDK Bug报告(GDK Bug Reports)
  • 困惑于在python中循环遍历列表(confused about looping through lists in python)
  • 'less'由'which'输出指定的文件('less' the file specified by the output of 'which')
  • 如何在ASP.NET中优化AJAX(How to optimize AJAX in ASP.NET)
  • 在文本文件中转换纪元时间(Convert epoch times in text file)
  • 表细胞伸展(Table cell stretching)
  • GridView控件(GridView Control)
  • 从构建定义文件控制pdb文件输出(Control pdb file output from build defintion file)
  • *将方法传递给类(*Passing a Method into a Class)
  • 如何在HttpReceiveHttpRequest()中使用HTTPS?(How to use HTTPS with HttpReceiveHttpRequest()?)