Menu

#214 getchar / FIX?

closed
nobody
Lisp Core (457)
5
2006-02-09
2003-01-16
Anonymous
No

The getchar function is broken. it's a very minor bug; I
wasn't able to find any code in src that uses getchar.

(C1) getchar(unk,1);

(D1) ^@

(C2) getchar(unk,2);

(D2) ^@

Here's my build info and what getchar should
do

(C3) build_info();
Maxima version: 5.9.0rc3
Maxima build date: 6:58 1/13/2003
host type: i686-pc-linux-gnu
lisp-implementation-type: CMU Common Lisp
lisp-implementation-version: 18d

(D3)
(C4) describe("getchar");
- Function: GETCHAR (a, i)
returns the ith character of the quoted string or
atomic name a.
This function is useful in manipulating the LABELS
list.

Also, getchar doesn't compile cleanly under CMUCL:
-----------------------------------------------------
In: DEFMFUN $GETCHAR
(CHAR-CODE N)
Warning: Lisp error during constant folding:
Type-error in KERNEL::OBJECT-NOT-BASE-CHAR-
ERROR-HANDLER:
0 is not of type BASE-CHAR

==>
N
Warning: This is not a (VALUES &OPTIONAL BASE-
CHAR &REST T):
0
-------------------------------------------------------

It's clear that getchar is broken:

(DEFMFUN $GETCHAR (X Y)
(LET ((N 0))
(COND ((NOT (SYMBOLP X))
(MERROR "1st argument to GETCHAR
not a symbol: ~M" X))
((OR (NOT (FIXNUMP Y)) (NOT (> Y 0)))
(MERROR "Incorrect 2nd argument to
GETCHAR: ~M" Y))
;((char= (SETQ N (GETCHARN
(FULLSTRIP1 X) Y)) 0) NIL)
((char= (GETCHARN X 1) '#\&)
(IMPLODE (LIST #\& N)))
((ASCII-NUMBERP N) (f- (char-code N)
(char-code '#\0)))
(T (IMPLODE (LIST #\$ N))))))

Is there something wrong with the simple replacement?

(defun $getchar (a i)
(cond ((not (symbolp a))
(merror "The first argument to getchar must
be symbol or a string"))
((or (not (fixnump i)) (not (> i 0)))
(merror "The second argument to getchar
must be a positive integer"))
(t
(cond ((<= i (length (setq a (string (fullstrip1
a)))))
(char a (decf i)))
(t nil)))))

With the new definition

(C7) getchar(unk,1);

(D7) u
(C8) getchar(unk,3);

(D8) k
(C9) getchar(unk,4);

(D9) FALSE
(C10) alias(robert,bob);

(D10) [robert]
(C11) getchar(bob,4);

(D11) e

Discussion

  • Stavros Macrakis

    Logged In: YES
    user_id=588346

    The proposed definition of $getchar returns a Common Lisp
    character (e.g. #\a). It should return a Maxima string (e.g.
    &a).

    Since getchar has been completely broken since the
    current version was first checked in on 8 May 2000, and no
    one noticed until January 2003, I think we can simplify its
    semantics, and always return a Maxima string (not a string,
    symbol, or number depending on the case), and give an error
    rather than NIL for falling off the end.

    Here is the revised code.

    (defmfun $getchar (x y)
    (let ((stripped))
    (cond ((not (symbolp x))
    (merror "1st argument to getchar not a symbol:
    ~M" x))
    ((or (not (fixnump y)) (not (> y 0)))
    (merror "Incorrect 2nd argument to getchar: ~M"
    y))
    ((> y (length (symbol-name (setq stripped
    (fullstrip1 x)))))
    (merror "Getchar(~M,~M) fell off end of string" x
    y))
    (t (implode (list #\& (getcharn stripped y)))))))

     
  • Robert Dodier

    Robert Dodier - 2006-02-09
    • status: open --> closed
    • labels: --> Lisp Core
     
  • Robert Dodier

    Robert Dodier - 2006-02-09

    Logged In: YES
    user_id=501686

    Closing this report as "won't fix": there exists a working
    replacement with the same purpose (namely charat) in
    share/contrib/stringproc. The stringproc library contains a
    variety of string and character processing functions aside
    from charat, there is documentation for it, and it works.

     

Log in to post a comment.