3 ms·
(define (get) (get1 (quote ()) (read)))(define (get1 b r) (if (eof-object? r) (reverse b) (get1 (cons r b) (read))))(define (put) (put1 (quote ()) (read-char)))
by siqu 7y ago
(define (get) (get1 (quote ()) (read)))(define (get1 b r) (if (eof-object? r) (reverse b) (get1 (cons r b) (read))))(define (put) (put1 (quote ()) (read-char)))(define (put1 b r) (if (eof-object? r) (list->string (reverse b)) (if (char=? #\) r) (put1 (cons #\. (cons #\. (cons r b))) (read-char)) (put1 (cons r b) (read-char)))))(define (final lis) (if (null? lis) lis (final1 (car lis) (cdr lis))))(define (final1 f r) (if (and (pair? f) (pair? (cdr f)) (eqv? (quote quote) (car f))) (cons f (final (cdr r))) (if (list? f) (final2 f (gather (count (car r)) (cons (quote ()) (final (cdr r))))) (if (or (vector? f) (pair? f) (eq? #\) f)) (cons f (final (cdr r))) (cons f (final r))))))(define (final2 f g) (cons (append (final f) (car g)) (cdr g)))(define (count s) (- (string-length (symbol->string s)) 2))(define (gather c lis) (if (= c 0) (cons (reverse (car lis)) (cdr lis)) (gather (- c 1) (cons (cons (cadr lis) (car lis)) (cddr lis)))))(for-each write (final (with-input-from-string (put) get)))
- jtms 7y agoNice try bot, whatever it is you were trying to do
- Lowkeyloki 7y agoYou have to at least give credit that the bot was apparently written in lisp.
- username223 7y agoScheme, actually, since it uses "define" instead of "defun." I formatted it reasonably, but it still looked like a pain to untangle.
- knolax 7y agoIt's more likely to be a human testing something than a bot. TBF, this comment and the replies were more interesting than any of the on topic comments or the article itself.
- Lowkeyloki 7y agoSeems legit.
- ququ 7y agolobster
- tomatotomato37 7y agoI'm bored and we are on a site called hacker news; anyone want to join me on de-obfuscating this code?
- Nadya 7y agoIt's a self-hosting compiler written in Scheme: https://ideone.com/dvhScJ https://ideone.com/dvhScJ
- LukeShu 7y agoHere's the best I could do at formatting and reading/commenting it, so far: ;; Usage: (get) ;; Parse the entirety of stdin as a sequence of s-expressions. Return ;; that list of expressions. ;; ;; The definition of this function is a little contrived, because in ;; lisp it's simpler to prepend to a list than to append to it, which ;; would be the natural thing to do. So instead, we build the list ;; such that it is backwards, then we call (reverse LIST) on it when ;; we read EOF. (define (get) (get1 (quote ()) (read))) ;; Usage: (get CURRENT-BUFFER JUSt-READ-EXPRESSION) (define (get1 b r) (if (eof-object? r) (reverse b) (get1 (cons r b) (read)))) ;; Usage: (put) ;; ;; Read the entirety of stdin as a sequence of characters, perform the ;; global string substitution ")" -> ")..", then return the result as ;; a string. ;; ;; The definition of this function is a little contrived, because in ;; lisp it's simpler to prepend to a list than to append to it, which ;; would be the natural thing to do. So instead, we build the list ;; such that it is backwards, then we call (reverse LIST) on it when ;; we read EOF. (define (put) (put1 (quote ()) (read-char))) ;; Usage: (put CURRENT-BUFFER LAST-READ-CHAR) (define (put1 b r) (if (eof-object? r) (list->string (reverse b)) (if (char=? #\) r) (put1 (cons #\. (cons #\. (cons r b))) (read-char)) (put1 (cons r b) (read-char))))) ;; Usage: (final LIST) ;; ??? (define (final lis) (if (null? lis) lis (final1 (car lis) (cdr lis)))) ;; Usage: (final1 FIRST REST) (define (final1 f r) (if (and (pair? f) (pair? (cdr f)) (eqv? (quote quote) (car f))) (cons f (final (cdr r))) (if (list? f) (final2 f (gather (count (car r)) (cons (quote ()) (final (cdr r))))) (if (or (vector? f) (pair? f) (eq? #\) f)) (cons f (final (cdr r))) (cons f (final r)))))) ;; Usage: (final2 f g) (define (final2 f g) (cons (append (final f) (car g)) (cdr g))) ;; Usage: (count SYMBOL) (define (count s) (- (string-length (symbol->string s)) 2)) ;; Usage: (gather c lis) (define (gather c lis) (if (= c 0) (cons (reverse (car lis)) (cdr lis)) (gather (- c 1) (cons (cons (cadr lis) (car lis)) (cddr lis))))) ;; 1. Use (put) to read stdin as a string and perform the ")" -> ").." ;; global string replacement. ;; 2. Feed that resulting string to (get), which parses it in to a ;; sequence of s-expressions. ;; 3. Feed that list of expressions to (final), which does something ;; to it and returns a list. ;; 4. (write) each item that (final) returns. (for-each write (final (with-input-from-string (put) get)))