Rosetta Code/Find bare lang tags: Difference between revisions

→‎{{header|Racket}}: Add extra-extra credit
(→‎{{header|Racket}}: Explain bogosity of results.)
(→‎{{header|Racket}}: Add extra-extra credit)
Line 92:
 
(define (get-text page)
(define ((get k) x) (hashdict-ref x k))
((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 "~ano bare language tags\n" (apply + (map cdr bare)))
(for ([b bare]) (begin (printf " ~a inbare ~alanguage tags\n" (cdrapply b)+ (carmap b)))]cdr bare)))
(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}}==