Wednesday, May 26, 2010

PLT Scheme is easy

Lots of nice frameworks too. A friend showed me some code he was working to use the Twitter APIs over http to look at people's tweets (if they're not protected).

I thought this was cool, it was 7 lines of code. So I thought I'd wrap it up in a GUI.

Keep in mind I'm NOT a GUI programmer by trade, and that this was my very first venture into PLT GUI programming. It's easy to pick up, and now I've got something hideous that works.

#lang scheme/gui (require net/url xml)
(define (u screenname) (string->url (string-append "\
user_timeline.xml?screen_name=" screenname)))
(define (f v) (match v (`(text ,_ . ,v) `(,(string-append* v)))
(`(,_ ,_ . ,v) (append-map f v)) (else '())))
(define g (compose f xml->xexpr document-element read-xml))
;(call/input-url (u "omgjkh") get-pure-port g)

(define dialog (new dialog%
[label "Twitter Screen Name Activity Grabulatrixatronulator"]
[width 600]
[height 100]))

(define textfield (new text-field% [parent dialog] [label "Enter a Screen Name"]))
(send textfield set-value "omgjkh")
(display (send textfield get-value))

(define newframe (new frame%
[label "Results"]
[width 1000]
[height 600]
(define tf (new text-field% [parent newframe] [label ""] [min-height 500]))

(define (appender los)
(cond ((null? los) "")
(else (string-append (car los) "\n" (appender (cdr los))))))

(new button% [parent dialog]
[label "GITERDUN"]
[callback (lambda (button event)
(let ((text (appender (call/input-url (u (send textfield get-value)) get-pure-port g))))
(display text)
(send tf set-value text)
(send dialog show #f)
(display "here")(newline)
(send newframe show #t)
(display "here2")(newline)))])

(send dialog show #t)

No comments:

Post a Comment