Preserving the entered integer format


#1

One nice feature about uLisp is that you can list the functions you have defined, such as by using (pprintall). However, when you read in a function, the number base you used for representing an integer is lost.

For example, if you define:

(defun nibbles (word)
  (list
   (ash (logand word #xf000) -12)
   (ash (logand word #x0f00) -8)
   (ash (logand word #x00f0) -4) 
   (logand word #x000f)))

it’s pretty clear that this is a function to split a 16-bit number into a list of 4-bit nibbles:

> (nibbles #x1234)
(1 2 3 4)

However, if you list it using (pprintall) this meaning’s lost:

(defun nibbles (word)
  (list
    (ash (logand word 61440) -12)
    (ash (logand word 3840) -8)
    (ash (logand word 240) -4)
    (logand word 15)))

This has slightly bugged me since the original version of uLisp, and I’ve now thought of a solution to it, but there would be a (slight) performance penalty.

Has anyone else noticed this, and would it be a worthwhile improvement?

Note that I wouldn’t attempt to preserve the format of other constants, such as floating-point numbers.


#2

Is the performance penalty to pprintall only or to the whole system? If it’s pprintall only I’d say do it, but I don’t think its worth it if it slows down other stuff


#3

It’s a penalty to the whole system. Here are the differences between the latest ARM version and the test version:

Version GC tak q2
4.8c 1.3 ms 11.5 s 25.4 s
4.8 test 1.3 ms 11.6 s 25.7 s

David


#4

I apologize for only just reading this… I think pprint with a saved format would be more advanced and technically elegant. The performance difference is about 1%, not much.

There’s one more issue that gave me trouble. When I was writing a list-editor, I couldn’t get the following construct to display correctly:

(defun Func () ...)

As a result, it always displayed:

(defun Func nil ...)

If i created an empty list () and then filled it in the editor, it also displayed as nil. I made peace with this because I found a solution: create a list with at least one element, such as “(dummy)”. After that I could go into it and edit, add or delete items. There may be some solutions that I don’t know.
So I’m inclined to think that having convenient pprint and other output functions is useful.


#5

I think pprint (and pprintall) could easily show

(defun func () ...

rather than:

(defun func nil ...

because there’s no situation when you would want to put nil there rather than (). It already shows:

(defun test (x) (print 'a))

rather than:

(defun test (x) (print (quote a)))

I’ll do that next release, and think more about the integer format.


#6

David, its possible i have older version uLisp:

45266> (pprint '(defun xxx () 'xxx))
(defun xxx nil 'xxx)

Here 'xxx is working correctly. The “()” is printed as “nil” .
The format function gives following

45266> (format  t "~s" '(defun xxx () 'xxx))
(defun xxx nil (quote xxx))
nil

I was try Portacle CL:

CL-USER> (pprint '(defun xxx () 'xxx))

(DEFUN XXX () 'XXX)
; No value

Here “()” and Quote marks are printed. princ gives too

CL-USER> (princ '(defun xxx () 'xxx))
(DEFUN XXX () 'XXX)
(DEFUN XXX () 'XXX)

and
format: here both () and NIL is printed as () :

CL-USER> (format t "~s" '(defun xxx () 'xxx))
(DEFUN XXX () 'XXX)

CL-USER> (format t "~s" '(defun xxx nil 'xxx))
(DEFUN XXX () 'XXX)

But in another example:

CL-USER> (format t "~s" '(defun xxx nil nil))
(DEFUN XXX () NIL)

and
CL-USER> (format t “~s” '(defun xxx () '()))
(DEFUN XXX () 'NIL)

It’s clear that it’s dark. And very complex.
Is it advisable to standardize it? After all, it could make the ulisp fatter… and take time to work on.