Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ROAD TO PROGRAMMING EXPERTISE

Name: Anonymous 2010-02-20 8:39

Do I need to learn functional programming and LISP ()())())))))))))))))))))))) to be an EXPERT DEVELOPER ?

Name: 27 2010-02-21 18:56

>>29
Since you posted code, I decided to write a solution in CL, which does not have the issues of your version, but it's still not ideal (does not account for future readtable changes - I could make it work, but would require more elaborate work, and it'd be much mor slower):

(defconstant +magic-keyword+ "Sunn O")
(defconstant +magic-keyword-char+ (aref +magic-keyword+ 0))
(defconstant +magic-keyword-rest+ (subseq +magic-keyword+ 1))
;; this is actually not perfect, but should be enough for this hack
(defvar *original-readtable*)

(defun read-string (stream length)
  (let ((string (make-string length)))
    (read-sequence string stream :end length)
    string))

(defun SunnO-reader (stream char)
  (assert (char= char +magic-keyword-char+)) 
  (let ((string (read-string stream (length +magic-keyword-rest+))))
    (let ((*readtable* *original-readtable*))
      (read           
       (make-concatenated-stream
        (make-string-input-stream
         (if (string= string +magic-keyword-rest+) "((("
             (concatenate 'string  (string +magic-keyword-char+) string)))
        stream)
       t nil t))))

(eval-when (:compile-toplevel :load-toplevel :execute) 
  (setq *original-readtable* (copy-readtable))
  (set-macro-character #\S #'SunnO-reader))

;CL-USER> 'Sunn O this is stupid and useless but at least it's a half-clever hack)))
;(((THIS IS STUPID AND USELESS BUT AT LEAST IT 'S A HALF-CLEVER HACK)))
;CL-USER> (STRING 'sup-/prog/)
;"SUP-/PROG/"
;^ shows that other strings starting with S are not affected

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List