我正在尝试使用racket simple-qr库并接收一个字符串列表,这些字符串将成为网站并为每个项目创建qrs。
这就是我所拥有的:
#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)))
我对球拍很陌生,并且在编写这个迭代函数时遇到了麻烦
答案 0 :(得分:2)
以下是我在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
更易读。)