Name: Anonymous 2010-02-20 8:39
Do I need to learn functional programming and LISP ()())())))))))))))))))))))) to be an EXPERT DEVELOPER ?
(define sunn-reader
(letrec ((current (current-readtable))
(sunn (case-lambda ((ch port) ;;required because read/syntax is different that read
(sunn ch port #f #f #f #f))
((ch port src line col pos)
(parameterize ((current-readtable unn-reader))
(read port)))))
(unn-reader (make-readtable current
#\u #\( current
#\n #\( current)))
(make-readtable current #\S 'non-terminating-macro sunn)))
;What I'm doing is just dropping the first S (which has to beat the start of a symbol) and reading the rest with new readtable where u and n count as open parentheses. Yes, that would be a bug, but fuck it, it's a toy example.
(parameterize ((current-readtable sunn-reader))
(read (open-input-string "Sunn )))")))
((()))
;which is what we expected
(parameterize ((current-readtable sunn-reader))
(read (open-input-string "Sunn i hate yor mothers white ass )))")))
(((i hate yor mothers white ass)))
;Again, correct output
(parameterize ((current-readtable sunn-reader))
(read (open-input-string "Sunn i hate your mothers white ass )))")))
. read: expected a `)' to close `u'
;Can you see where the bug?
(parameterize ((current-readtable sunn-reader))
(read (open-input-string "Sunn i hate your mothers white ass ))))")))
(((i hate yo (r mothers white ass))))
;There it is ;)
(parameterize ((current-readtable sunn-reader))
(read (open-input-string "aSunn i hate your mothers white ass ))))")))
aSunn
; This is also correct
(parameterize ((current-readtable sunn-reader))
(read (open-input-string "Sunn i hate your mothers white ass Sunn )))))))")))
(((i hate yo (r mothers white ass S ((()))))))
; Inner Sunns don't work, the readtable would need to be improved
(parameterize ((current-readtable sunn-reader)
(current-input-port (open-input-string "Sunn i hate your mothers white ass )))) unn)))")))
(list (read) (read)))
((((i hate yo (r mothers white ass)))) unn)
; at least the inner readtables don't leak out