常见的口齿不清:输入数学表达式有没有那么痛苦的方法? [英] Common lisp: is there a less painful way to input math expressions?
问题描述
我喜欢普通口齿不清,但有时输入
I enjoy common lisp, but sometimes it is really painful to input simple math expressions like
a(8b^2+1)+4bc(4b^2+1)
(当然,我可以转换它,但是有点慢,我先写(+()()),然后在每个方括号中加上(*()())...)
(Sure I can convert this, but it is kind of slow, I write (+ () ()) first, and then in each bracket I put (* () ())...)
我想知道这里是否有人知道更好的输入方式.我当时正在考虑编写数学宏,其中
I'm wondering if anyone here knows a better way to input this. I was thinking about writing a math macro, where
(math "a(8b^2+1)+4bc(4b^2+1)")
扩展到
(+ (* a (1+ (* 8 b b))) (* 4 b c (1+ (* 4 b b))))
但是对于名称很长的变量,解析是一个问题.
but parsing is a problem for variables whose names are long.
有人有更好的建议吗?
推荐答案
有用于此目的的阅读器宏.
There are reader macros for this purpose.
请参阅: http://www.cliki.net/infix
例如:
CL-USER 17 > '#I(a*(8*b^^2+1)+ 4*b*c*(4*b^^2+1) )
(+ (* A (+ (* 8 (EXPT B 2)) 1)) (* 4 B C (+ (* 4 (EXPT B 2)) 1)))
'
是通常的引用. #I( some-infix-expression )
是阅读器宏.
'
is the usual quote. #I( some-infix-expression )
is the reader macro.
这篇关于常见的口齿不清:输入数学表达式有没有那么痛苦的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!