Racket(Scheme) 中是否有一些函数可以给我元素,在列表中应用给定函数后产生最小值。类似于(apply min (map f list))但在应用 f 之前返回元素。例如:
(define lst '((1 . 3) (3 . 8) (5 . 6))
(define (f pair)
(- (cdr pair) (car pair)))
(minimum f lst)
Run Code Online (Sandbox Code Playgroud)
这应该给'(5 . 6).
至少在没有直接函数的情况下,应该有一个具有更高阶函数的单行衬里(因为我必须填写一行才能获得这种行为)。有任何想法吗?
这就是我的另存为的工作方式 - 它复制当前文件的行,直到它到达第一个图形,然后我使用我的打印方法打印图形的信息,然后关闭标签。
std::ofstream newFile(filePath1_fixed, std::ios::app);
std::fstream openedFile(filePath);
std::string line1;
while (std::getline(openedFile, line1)) {
if (line1.find("<rect") != std::string::npos
|| line1.find("<circle") != std::string::npos
|| line1.find("<line") != std::string::npos)
break;
newFile << line1 << std::endl;
}
figc.printToFile(newFile);
newFile << "</svg>\n";
Run Code Online (Sandbox Code Playgroud)
我的问题是如何保存对当前文件的更改?我试过这样的事情:
std::ifstream openedFile(filePath);
std::ofstream newFile(filePath, std::ios::app);
std::string line1;
std::string info_beg[100];
int t = 0;
while (std::getline(openedFile, line1)) {
std::cout << "HELLYEAH";
if (line1.find("<rect") != std::string::npos
|| line1.find("<circle") != std::string::npos
|| line1.find("<line") != std::string::npos)
break;
info_beg[t++] = line1;
}
for (int i = 0; …Run Code Online (Sandbox Code Playgroud)