[Openmcl-devel] Mark Kantrowitz infix.lisp easter egg?
ralex at cs.colorado.edu
Sat Dec 3 06:32:19 UTC 2011
On Dec 2, 2011, at 7:08 PM, Joshua TAYLOR wrote:
> On Fri, Dec 2, 2011 at 8:56 PM, Alexander Repenning
> <ralex at cs.colorado.edu> wrote:
>> Using Mark Kantrowitz old but very handy infix we noticed some peculiar
>> pattern of errors where very basic expressions do not correctly convert
>> infix expressions into prefix ones. The version I just tried was this
>> one: http://www.cliki.net/infix
>> in => pre, red for incorrect
>> "a + 1" => (+ A 1)
>> "s + 1" => S+1
>> "s - 1" => S-1
>> "s * 1" => (* S 1)
>> "a + 1.5" => (+ A 1.5)
>> "s + 1.5" => (+ S 1.5)
>> "s + s" => (+ S S)
>> "s + 1 + 1" => (+ S+1 1)
>> "s + 1e1" => (+ S 10.0)
>> Can somebody see a pattern here? AFAIK, the combination of the one letter
>> variables names that are characters D, E, F, L, or S followed by "+" or "-"
>> and then followed by an int does not work.
> Didn't look into the code, but those letters are special…
> CL-USER 15 > (list 1.0d+0 1.0d-0
> 1.0e+10 1.0e-10
> 1.0f+0 1.0f-0
> 1.0l+0 1.0f-0
> 1.0s+0 1.0s-0)
> (1.0D0 1.0D0 1.0E10 1.0E-10 1.0 1.0 1.0D0 1.0 1.0S0 1.0S0)
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Yes, it does appear to be a genuine bug which confuses simple expressions such as "e + 1" with floating point literals. Bad floating point literal parsing going on here:
1) floating point numbers representations require the exponent marker to be preceded by at least a digit
2) do not allow spaces between the exponent marker, the exponent sign and exponent digits.
I found this function in infix.lisp which appears to be the culprit:
(defun fancy-number-format-p (left operator stream)
(when (and (symbolp left)
(find operator '(+ -) :test #'same-operator-p))
(let* ((name (symbol-name left))
(length (length name)))
(when (and (valid-numberp (subseq name 0 (1- length)))
;; Exponent, Single, Double, Float, or Long
(find (subseq name (1- length))
'("e" "s" "d" "f" "l")
(let ((right (peek-token stream)))
(cond ((integerp right)
;; it is one of the fancy numbers, so return it
(let ((*readtable* *normal-readtable*))
(read-from-string (format nil "~A~A~A"
left operator right))))
;; it isn't one of the fancy numbers, so unread the token
(push operator *peeked-token*)
;; and return nil
Just making it return nil will fix the conversation of expression such a "e + 1" to be (+ e 1) but of course will also ruin the capability to recognize real float literals. Does anybody have the energy to fix this? Time to go to bed...
Still surprised this bug has not surfaced before.
Prof. Alexander Repenning
University of Colorado
Computer Science Department
Boulder, CO 80309-430
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Openmcl-devel