Rosetta Code/Find bare lang tags: Difference between revisions
Content deleted Content added
→{{header|Racket}}: Explain bogosity of results. |
→{{header|Racket}}: Add extra-extra credit |
||
Line 92: | Line 92: | ||
(define (get-text page) |
(define (get-text page) |
||
(define ((get k) x) ( |
(define ((get k) x) (dict-ref x k)) |
||
((compose1 (get '*) car (get 'revisions) cdar hash->list (get 'pages) |
((compose1 (get '*) car (get 'revisions) cdar hash->list (get 'pages) |
||
(get 'query) read-json get-pure-port string->url format) |
(get 'query) read-json get-pure-port string->url format) |
||
Line 110: | Line 110: | ||
[(list _ #f) (loop lang (dict-update bare lang add1 0))] |
[(list _ #f) (loop lang (dict-update bare lang add1 0))] |
||
[(list _ lang) (loop lang bare)] |
[(list _ lang) (loop lang bare)] |
||
[#f (printf " |
[#f (if (null? bare) (printf "no bare language tags\n") |
||
(begin (printf "~a bare language tags\n" (apply + (map cdr bare))) |
|||
(for ([b bare]) (printf " ~a in ~a\n" (cdr b) (car b)))))]))) |
|||
(find-bare-tags "Rosetta Code/Find bare lang tags") |
(find-bare-tags "Rosetta Code/Find bare lang tags") |
||
Line 123: | Line 124: | ||
1 in Tcl |
1 in Tcl |
||
</pre> |
</pre> |
||
===Extra-extra credit=== |
|||
Add the following code at the bottom, run, watch results. |
|||
<lang racket> |
|||
(define (get-category cat) |
|||
(let loop ([c #f]) |
|||
(define t |
|||
((compose1 read-json get-pure-port string->url format) |
|||
"http://rosettacode.org/mw/api.php?~a" |
|||
(alist->form-urlencoded |
|||
`([list . "categorymembers"] [cmtitle . ,(format "Category:~a" cat)] |
|||
[cmcontinue . ,(and c (dict-ref c 'cmcontinue))] |
|||
[cmlimit . "500"] [format . "json"] [action . "query"])))) |
|||
(define (c-m key) (dict-ref (dict-ref t key '()) 'categorymembers #f)) |
|||
(append (for/list ([page (c-m 'query)]) (dict-ref page 'title)) |
|||
(cond [(c-m 'query-continue) => loop] [else '()])))) |
|||
(for ([page (get-category "Programming Tasks")]) |
|||
(printf "Page: ~a " page) |
|||
(find-bare-tags page)) |
|||
</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |