我试图使用球拍简单的qr库,并接受一个字符串的列表,这将是网站和创建每个项目的qr。
这就是我所拥有的:
#lang racket
(require simple-qr)
;;auto makes a qr for the main source of simple-qr
(qr-code "https://github.com/simmone" "gitSource.png")
;;asking the user to imput a string so that
;;they can create their own qr code
;;they can also name it themselves
(define (makeQRForME mystring namestring)
(qr-code mystring (string-append namestring ".png")))
(define count 0)
(define (addqrlist lst)
(if (null? lst) lst
(makeQRForME (car lst) (string-append "stringQR"(number->string(+ 1 count)))))
(addqrlist (rest lst)))我是个新手,很难编写这个迭代函数。
发布于 2016-03-11 03:06:43
下面是如何用Racket编写函数:
(define (make-qr-codes texts)
(for ((text (in-list texts))
(count (in-naturals)))
(qr-code text (format "stringQR~a.png" count))))但是,如果您想知道如何修复您的版本,我将这样做:
(define (addqrlist lst)
(let loop ((rest lst)
(count 0))
(unless (null? rest)
(makeQRForMe (car rest) (format "stringQR~a" count))
(loop (cdr rest) (add1 count)))))(您的版本混合了car和rest的使用,而不是car和cdr或first和rest。我将其更改为始终使用car和cdr。此外,使用format而不是string-append +number->string更易读。)
https://stackoverflow.com/questions/35931105
复制相似问题