質問編集履歴

3

追記

2022/05/11 12:03

投稿

mightyMask
mightyMask

スコア143

test CHANGED
File without changes
test CHANGED
@@ -44,3 +44,4 @@
44
44
  eval stdin.readLine.len
45
45
  ```
46
46
  こう書くとコンパイルエラーになってしまいます。
47
+ 引数が1つ増えちゃうのもちょっと嫌です。

2

修正

2022/05/11 12:01

投稿

mightyMask
mightyMask

スコア143

test CHANGED
File without changes
test CHANGED
@@ -17,13 +17,6 @@
17
17
  `continue` とかが for文の中でだけ使えるのと同じようなノリで。
18
18
 
19
19
  ```Nim
20
- template COUNT(eval:untyped, body:untyped) :int =
21
- proc exec(eval:proc()) = body
22
- var ans = 0
23
- exec do () -> void:
24
- ans.inc
25
- ans
26
-
27
20
  template MAX(eval:untyped, body:untyped) :int =
28
21
  proc exec(eval:proc(x:int)) = body
29
22
  var ans = int.low
@@ -31,5 +24,23 @@
31
24
  if x > ans:
32
25
  ans = x
33
26
  ans
27
+
28
+ let ans = MAX eval:
29
+ for i in 0..<10:
30
+ eval stdin.readLine.len
34
31
  ```
32
+ これだといけるのですが、
33
+ ```Nim
34
+ template MAX(eval:untyped, body:untyped) :int =
35
+ proc exec(eval:proc(x:int)) = body
36
+ var ans = int.low
37
+ exec do (x:int) -> void:
38
+ if x > ans:
39
+ ans = x
40
+ ans
41
+
42
+ echo MAX eval:
43
+ for i in 0..<10:
44
+ eval stdin.readLine.len
45
+ ```
35
- の2つのテンプレートを同時に使うとコンパイルエラーになってしまいます。
46
+ こう書くとコンパイルエラーになってしまいます。

1

追記

2022/05/11 11:58

投稿

mightyMask
mightyMask

スコア143

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,21 @@
15
15
 
16
16
  `eval` は MAX文の中でだけ使える予約語みたいな。
17
17
  `continue` とかが for文の中でだけ使えるのと同じようなノリで。
18
+
19
+ ```Nim
20
+ template COUNT(eval:untyped, body:untyped) :int =
21
+ proc exec(eval:proc()) = body
22
+ var ans = 0
23
+ exec do () -> void:
24
+ ans.inc
25
+ ans
26
+
27
+ template MAX(eval:untyped, body:untyped) :int =
28
+ proc exec(eval:proc(x:int)) = body
29
+ var ans = int.low
30
+ exec do (x:int) -> void:
31
+ if x > ans:
32
+ ans = x
33
+ ans
34
+ ```
35
+ この2つのテンプレートを同時に使うとコンパイルエラーになってしまいます。