FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Next: 省略可能引数と初期値付き引数を追加 by FineArchs · Pull Request #475 · aiscript-dev/aiscript · GitHub

Next: 省略可能引数と初期値付き引数を追加 - #475

Merged
FineArchs merged 17 commits into
aiscript-dev:aiscript-nextfrom
FineArchs:args
Jun 8, 2024
Merged

Next: 省略可能引数と初期値付き引数を追加#475
FineArchs merged 17 commits into
aiscript-dev:aiscript-nextfrom
FineArchs:args

Conversation

FineArchs commented Nov 18, 2023
edited
Loading

Copy link
Copy Markdown
Member

一応破壊的変更なのでnextに入れます。

関数の引数定義において、各引数名に?を後置できるようにします。
?付きの引数は省略可能となり、省略された場合nullを格納します。
また、引数に=式を後置することで引数の初期値を設定できるようにします。
いずれでもない引数が省略された場合エラーを発生させます。

FineArchs changed the title next: ?付き引数を追加 next: 省略可能引数と初期値付き引数を追加 Nov 18, 2023

Copy link
Copy Markdown
Member

デフォルト値の定義時に評価して使い回す方式ですかね
説明に書いておいた方がいいかも

Copy link
Copy Markdown
Member Author

とりあえずsyntax.mdに追加しました

Comment thread src/parser/syntaxes/common.ts Outdated
Comment thread src/node.ts Outdated
Comment thread src/parser/visit.ts
if (result.args[i]!.default) {
result.args[i]!.default = visitNode(result.args[i]!.default!, fn) as Ast.Fn['args'][number]['default'];
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

この処理のiはindexではないと思います

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

for-inなのでindexで間違いないと思いますが…

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

for-inなので対象がオブジェクトだと勘違いしてました..
配列にもfor-inって使えるんですね
一般的な用法なんでしょうか

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

一般的かどうかはわからないです

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

for-ofの方が推奨されているようです

for(let value of array)
for(let index of array.keys())
for(let [index, value] of array.entries())

FineArchs Apr 1, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

for...inはプロトタイプから継承したものも列挙してしまうそうですね。
for(let index of array.keys())を使った形に修正しました。

marihachi changed the title next: 省略可能引数と初期値付き引数を追加 Next: 省略可能引数と初期値付き引数を追加 Mar 9, 2024
FineArchs requested review from ikasoba, marihachi and syuilo June 4, 2024 07:35
Comment on lines +29 to +38
let optional = false;
if ((s.getKind() as TokenKind) === TokenKind.Question) {
s.next();
optional = true;
}
let defaultExpr;
if ((s.getKind() as TokenKind) === TokenKind.Eq) {
s.next();
defaultExpr = parseExpr(s, false);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@f(arg? = defaultValue) {}のような冗長な書き方は出来ないほうがいいかな~思いました。
?=を一つのシンボルとして扱って、デフォルトを指定する場合でも?を必須にするでもいいかもしれない?

FineArchs Jun 4, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

あー確かに 両方つくケースのことは失念していました

?=を一つのシンボルとして扱って、デフォルトを指定する場合でも?を必須にするでもいいかもしれない?

これちょっと迷いますね
JavaScriptのnull合体代入を連想させる書き方ですが、実際やってることはnull合体代入に似ていますしアリではありますね

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@uzmoi
@f(arg? = defaultValue) {}を禁止する方向にしました。(迷った結果Typescriptに合わせました)

Copy link
Copy Markdown
Member Author

条件を満たしたのでマージします。

FineArchs merged commit a3e4dad into aiscript-dev:aiscript-next Jun 8, 2024
FineArchs deleted the args branch June 8, 2024 03:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL