infix reader macro from clisp to newLisp?

Started by HPW, October 19, 2002, 02:07:17 AM

Previous topic - Next topic

nigelbrown

#15
To allow full float syntax to be used by using the newLISP parser comment out this code:

;{ Get a Number }

;(define (GetNum , Value) (begin

;      (setq Value '())

;      (if (not (IsDigit Look)) (Expected "Number"))

;      (while (IsFloat Look) (begin

;      (push Look Value -1)

;      (GetChar)))

;      (SkipWhite)

;      (setq Value (join Value))

;      (if (!= 0 (find "^[0-9]+$|^[0-9]+.$|^[0-9]+.[0-9]*$" Value 0))

;          (Expected "float"))

;      Value))

and add:

(define (RestOfInput) (join (append (list Look) inputchars)))

(define (SkipChars n) (dotimes (x n) (GetChar)))



(define (GetNum , Value) (begin

    (if (not (IsDigit Look)) (Expected "Number"))

    (setq Value (first (parse (RestOfInput))))

    (SkipChars (length Value))

    (SkipWhite)

    Value))



now:

> (MYINFIX:doinfix "a=3+4")

7

> (MYINFIX:doinfix "a=3+4.2")

7.2

> (MYINFIX:doinfix "a=3+4.2E3")

4203

> (MYINFIX:doinfix "a=3+4.2E-3")

3.0042

>

Lutz

#16
Note that you don't need the 'begin' . 'define' can have various statements in the body.



Lutz

nigelbrown

#17
A throw-back to my ALGOL days - I'll try and kick the habit!

Lutz

#18
Good to know, I am not the only one here who learned ALGOL, who else?



Lutz

newdep

#19
Uhum.. No sorry my life started with Assembly 68000 ;-)
-- (define? (Cornflakes))