Re: GETF Speedup?
"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
I did initially try patching SBCL READ-TOKEN, but that didn’t work. I think #’SB-IMPL::READ-TOKEN is compiled in at the calling site and does not go through the symbol lookup, which lookup is needed to make Advice work. But READ-TOKEN is sitting right down there in the source, next to what I did patch, which was READ-MAYBE-NOTHING. That much is for the SBCL patching. ——————— The LW patching might actually be the same, I don’t know. My LW patch was developed a few years ago, and I stumbled onto the patches shown. > On Oct 11, 2025, at 14:56, David McClain <[email protected]> wrote: > > Not a reader macro, although I do have one for #N which refers to a large variety of number formats - sexagesimal notation, SSN’s and Phone Numbers, Dates with mm/dd/yyyy format, etc. That reader macro relies heavily on Edi’s PPCRE. > > But for allowing embedded underscores in Lisp numbers you have to patch the internal’s of LW and SBCL. But this seems to follow an established convention, at least in part, as seen in comparing against SBCL sources. > > ;; ------------------------------------------------------------------- > ;; Handle default Reader ops > > #+:LISPWORKS > (progn > (defadvice (sys::read-token underscore-skipper :around) > (&rest args) > (let* ((ans (multiple-value-list (apply #'call-next-advice args))) > (val (car ans)) > name) > (cond ((and (symbolp val) > (find #\_ (setf name (symbol-name val)))) > (let ((namex (remove #\_ name))) > (multiple-value-bind (ans2 end) > (read-from-string namex nil nil) > (if (and (numberp ans2) > (eql end (length namex))) > (progn > (unintern val (symbol-package val)) > (apply #'values ans2 (cdr ans))) > (values-list ans)) > ))) > (t > (values-list ans)) > ))) > > ;; ---------------------------------------------------- > ;; Handle #X, #B, #O, #R formats > > (defvar *in-sharp-r* nil) > > (defadvice (sys::sharp-r underscore-skipper :around) > (&rest args) > (let ((*in-sharp-r* t)) > (apply #'call-next-advice args))) > > (defadvice (sys::new-read-extended-token underscore-skipper :around) > (&rest args) > (let* ((ans (multiple-value-list (apply #'call-next-advice args))) > (val (car ans))) > (cond ((and *in-sharp-r* > (stringp val)) > (apply #'values (remove #\_ val) (cdr ans))) > (t > (values-list ans)) > )))) > > ;; -------------------------------------------- > > #+:SBCL > (sb-ext:with-unlocked-packages (:sb-impl) > (cl-advice:make-advisable 'sb-impl::read-maybe-nothing) > (cl-advice:add-advice :around 'sb-impl::read-maybe-nothing > (lambda (next-fn &rest args) > (multiple-value-bind (flag result) > (apply next-fn args) > (case flag > (0 > (values flag result)) > (t > (let (name) > (cond ((and (symbolp result) > (find #\_ (setf name (symbol-name result)))) > (let ((namex (remove #\_ name))) > (multiple-value-bind (ans end) > (read-from-string namex nil nil) > (if (and (numberp ans) > (eql end (length namex))) > (progn > (unintern result (symbol-package result)) > (values flag ans)) > (values flag result)) > ))) > (t > (values flag result)) > ))) > ))) > )) > > >> On Oct 11, 2025, at 08:38, Yuri Davidovsky (as work at disclosure dot ie) <[email protected]> wrote: >> >> >> >>> On 11 Oct 2025, at 16:08, David McClain <[email protected]> wrote: >>> >>> I have my Lispworks and SBCL both accepting embedded #\_ in numbers, for improved readability. >> >> Could you show the reader macro for that? I was wondering how to do that just recently, didn’t actually think it was possible. Are you treating underscores as spaces after a digit, or which way does it work? >> >> _______________________________________________ >> Lisp Hug - the mailing list for LispWorks users >> [email protected] >> http://www.lispworks.com/support/lisp-hug.html >