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

Prog Challenge, Easy!

Name: sage 2012-12-29 5:13

Implement https://dis.4chan.org/read/prog/1356634826/25 more elegantly.


(defun 3ml-cgi-decode ()
  (let ((stream (if (string-equal "get" request-method)
            (make-string-input-stream query-string)
          *standard-input*))
    (symbols ()))
    (with-open-stream (output (make-string-output-stream))
      (loop for char = (read-char stream nil nil)
      do (case char
           (#\= (push (intern (string-upcase (get-output-stream-string output)))
              symbols))
           ((nil #\&) (when symbols
                (setf (symbol-value (first symbols)) (get-output-stream-string output))))
           (#\+ (write-char #\space output))
           (#\% (let* ((nib1 (read-char stream nil nil))
               (nib2 (read-char stream nil nil))
               (code (+ (* 16 (digit-char-p nib1 16))
                    (digit-char-p nib2 16))))
              (write-char (code-char code) output)))
           (t (write-char char output)))
      while char))
    (setf *cgi-variables* symbols)))

Name: Anonymous 2012-12-30 7:33

>>18
I guess it's just to keep the syntax closer to relations. Rather than writing y = f(x), you'd write f(X,Y), and rather than writing y = f(g(x)), you'd write g(X,T), f(T,Y). I forgot to mention variables need to start with capital letters. I suppose in this form it's more intuitive to look at when the relations match with multiple values. And in some cases it's actually possible for prolog to give you the preimage of a value, like in f(X,3), although that generally doesn't work out.

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