早上好
我的列表与此类似:[(1-4), (2-4), (3-4)]
。我只想写圆括号的第一/第二/第三部分。我写了一个函数:
write_list([]).
write_list([Head|Tail]) :-
write(Head), nl,
write_list(Tail).
它只写整圆括号:
1-4
2-4
3-4
我希望我的输出成为圆括号的第一个元素:
1
2
3
我会感激任何帮助:D
答案 0 :(得分:0)
你在这里:
var string =
'<p>Hi, my name is Tim!</p> <div class="xyz">This is a div</div> <p>Javascript is fun!</p> <p>Hope you can help!</p>';
var div = document.createElement("div");
div.innerHTML = string;
var paragraphs = Array.prototype.filter
.call(div.childNodes, function(e) {
return e.tagName === "P";
})
.map(function(p) {
return p.outerHTML;
});
console.log(paragraphs);
// ["<p>Hi, my name is Tim!</p>", "<p>Javascript is fun!</p>", "<p>Hope you can help!</p>"]
查询:
let string = `<p>Hi, my name is Tim!</p> <div class="xyz">This is a div</div> <p>Javascript is fun!</p> <p>Hope you can help!</p>`;
let div = document.createElement("div");
div.innerHTML = string;
let newString = Array.from(div.querySelectorAll("p"), p => p.outerHTML);
console.log(newString);
// ["<p>Hi, my name is Tim!</p>", "<p>Javascript is fun!</p>", "<p>Hope you can help!</p>"]
void move() {
double slope = (y - mouseY)/(x-mouseX);
double atanSlope = atan(slope);
if (slope < 0 && mouseY < y ) {
x += cos(atanSlope)*(speed);
y += sin(atanSlope)*(speed);
} else if (slope >= 0 && mouseY < y) {
x -= cos(atanSlope)*(speed);
y -= sin(atanSlope)*(speed);
} else if (slope > 0) {
x += cos(atanSlope)*(speed);
y += sin(atanSlope)*(speed);
} else {
x -= cos(atanSlope)*(speed);
y -= sin(atanSlope)*(speed);
}
}
只是write_list([]).
write_list([(A-_)|Tail]) :-
writeln(A),
write_list(Tail).
,后跟?- write_list([(1-4),(2-4),(3-4)]).
1
2
3
true
。
答案 1 :(得分:0)
您真的不想 http {
...
perl_modules perl/lib;
...
perl_set $uri_decode 'sub {
my $r = shift;
my $uri = $r->uri;
$uri = perl_magic_to_decode_the_url;
return $uri;
}';
...
server {
...
location /your-protected-urls-regex {
rewrite ^(.*)$ $scheme://$host$uri_decode;
}
结果,而是将它们作为参数提供。 Prolog的许多初学者都被困在这一点上。此外,将相同的逻辑应用于每个列表元素是一种常见的模式,Prolog有一个名为write
的谓词用于为您完成工作:
maplist
你会这样称呼它:
first_subterm(A-_, A). % First subterm of `A-_` is `A`
first_subterms(PairList, FirstSubTerms) :-
maplist(first_subterm, PairList, FirstSubTerms).
长手递归形式与其他答案中给出的类似:
| ?- first_subterms([(1-4), (2-4), (3-4)], FirstSubTerms).
FirstSubTerms = [1,2,3]
yes
| ?-
请注意,“圆括号”是括号,在Prolog中,在此上下文中仅执行该术语的分组。事实证明first_subterms([], []). % The list of first subterms of [] is []
first_subterms([(A-_)|Pairs], [A|SubTerms]) :-
first_subterms(Pairs, SubTerms).
此处的行为与[(1-4), (2-4), (3-4)]
相同,因为[1-4, 2-4, 3-4]
的优先级低于列表符号中的,
。所以这也是行为:
-