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:
(define (get-text page)
(define ((get k) x) (
((compose1 (get '*) car (get 'revisions) cdar hash->list (get 'pages)
(get 'query) read-json get-pure-port string->url format)
Line 110:
[(list _ #f) (loop lang (dict-update bare lang add1 0))]
[(list _ lang) (loop lang bare)]
[#f (if (null? bare) (printf "
(for ([b bare]) (printf " ~a in ~a\n" (cdr b) (car b)))))])))
(find-bare-tags "Rosetta Code/Find bare lang tags")
Line 123 ⟶ 124:
1 in Tcl
</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}}==
|