Paste: compiler bug with ?at

Author: erg
Mode: factor
Date: Sun, 24 Oct 2010 19:16:39
Plain Text |
USING: assocs http.client json.reader kernel namespaces
sequences ;
IN: google.translateCONSTANT: google-translate-url "http://ajax.googleapis.com/ajax/services/language/translate"
: parameters>assoc ( text from to -- assoc )
    "|" glue [
        [ "q" set ]
        [ "langpair" set ] bi*
        "1.0" "v" set
] { } make-assoc ;

: assoc>query-response ( assoc -- response )
    google-translate-url http-post nip ;

ERROR: invalid-response response ;
ERROR: no-translated-text assoc ;

: query-response>text ( response -- text )
    json>
    "responseData" ?at [
        "translatedText" ?at [
            no-translated-text
        ] unless
    ] [
        invalid-response
    ] if ;

: translate ( text from to -- text' )
    parameters>assoc
    assoc>query-response
    query-response>text ;

New Annotation

Summary:
Author:
Mode:
Body: