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: 26 2010-02-21 16:26

Unfortunately we don't have a portable reader syntax (are you surprised?), and not even all Schemes have a modifiable reader. PLT does, and has some kind of readtables (see below). Ikarus, as far as I can tell, doesn't allow you to modify the reader. It does have two syntax modes, #!ikarus and #!r6rs, one of which has a few additional niceties, like graph syntax. I don't usually use other Schemes, so if you use a different implementation you'll have to do your own research ;)

Here is a bad first attempt at the "Sunn" reader macro which should be replaced with "(((". I can never remember how to use PLTs readtables, so this is just me working off the docs as best as I can. For portabilities sake, don't use PLT I'd probably write a parser and read a text file, but here goes...

(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


Obviously, this is a quick 5 minute hack, as you wouldn't want that buggy behaviour with an Enterprise Quality Sunn Macro. If anyone actually gives a toss, I could finish this off, but I'm not really fussed. Syntax-rules and syntax-case are fine for me 99% of the time and the other 1% I could just write a parser.

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