方案:更改复数的定义以接受向量 [英] Scheme: Changing the definition of complex numbers to accept vectors

查看:83
本文介绍了方案:更改复数的定义以接受向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想做的是更改复数的定义,以便可以在Scheme中表示向量.我希望能够编写不带引号的"i + j + k"之类的东西,并且不要让程序完全发疯.我知道复数可以用"1 + 2i"之类的东西表示,所以我希望通过简单的覆盖就可以完成.

Basically what I am trying to do is change the definition of complex numbers so I can represent vectors in Scheme. I want to be able to write something like "i+j+k" without the quotes and not have the program go entirely crazy. I know complex numbers can be represented by something like "1+2i" so I was hoping a simple overwrite could accomplish this.

我认为要覆盖综合楼吗?定义可能有效,但似乎没有效果.我不确定我需要影响的代码在哪里.任何帮助都将是惊人的.谢谢.

I thought overwriting the complex? definition might work, but it seems to have no effect. I am unsure of where the code I need to affect even is. Any help would be amazing. Thanks.

推荐答案

简而言之:您无法使用简单覆盖"来完成所需的操作. 数字的语法包括用于读取/写入复数的+,但是 读者会直接将2 + 3i转换为数字,而不会进行任何替代.

In short: You can not with a "simple overwrite" accomplish what you want. The syntax for numbers include a + used to read/write complex numbers, but the reader converts 2+3i into a number directly with no option of any overriding.

如果要在程序中使用中缀符号,则需要更换阅读器.在Racket中可以做到这一点,但它比简单的覆盖更为复杂.

If you want to use infix notation in your program you'll need to replace the reader. This is possible in Racket but it is more complicated than a simple overwrite.

也许您可以在Racket中将现有的库用于中缀符号?

Maybe you can use an existing library for infix notation in Racket?

您可能要尝试:

https://github.com/soegaard/this-and-that/blob/master/readtable/test2.rkt

它将{}中的任何内容解析为中缀表达式.

which parses anything in {} as infix expressions.

这篇关于方案:更改复数的定义以接受向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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