Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 26 additions & 35 deletions crates/typst-library/src/foundations/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ use crate::foundations::{
cast, func, repr, scope, ty, Array, Dict, FromValue, IntoValue, Repr, Str, Value,
};

/// Captured arguments to a function.
/// 関数にキャプチャーされた引数。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// 関数にキャプチャーされた引数
/// 関数に渡された引数

Copy link
Contributor

Choose a reason for hiding this comment

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

キャプチャーは私が指摘してそのように変更してもらったのですが、キャプチャーだと不適切でしょうか?

Copy link
Member

Choose a reason for hiding this comment

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

以前の議論を見落としていました。
他のテクニカルタームと比べると「キャプチャー」は日本語の技術文書において浸透度が低く感じたため、和訳する修正提案をさせていただきましたが、あまり強い自信はありません。

Copy link
Contributor

@ultimatile ultimatile Sep 16, 2025

Choose a reason for hiding this comment

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

キャプチャーされた関数外の変数はis_mutating_methodを除いて関数内で変更できないので、通常の変数の渡し方とは違いを意識する必要はあると思いますが、「関数にキャプチャーされた引数。」でどれくらい伝わるかは微妙な気がしています。「キャプチャ(ー)」は一般的な機能・用語なので個人的にはそこまで違和感はないです。相対的にマイナーなタームと言われるとそうかもしれないです。

Copy link
Member

Choose a reason for hiding this comment

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

@gomazarashi @kimushun1101 こちらの件について意見があれば伺いたいです。

Copy link
Member

Choose a reason for hiding this comment

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

他のテクニカルタームと比べると「キャプチャー」は日本語の技術文書において浸透度が低く感じたため、和訳する修正提案をさせていただきましたが、あまり強い自信はありません。

ここに関しては同じ感想をいだきました。私の界隈でもメジャーではありません。

キャプチャーされた関数外の変数はis_mutating_methodを除いて関数内で変更できないので、通常の変数の渡し方とは違いを意識する必要はある

これは..sinkで関数が可変長の引数を受け取る形式のことを指していますかね?is_mutating_methodがあまりわかっていないのですが、なにか違いがあるんだろうなぁくらいに雰囲気で感じている程度の理解度です。そのために「渡す」という訳を使わないというのはわかります。一方でこれを伝えたいため「キャプチャー」という訳にするというのは、目的に一致していない印象です。
両者を取るという意味では、たとえば、「取り込む」や「保持する」などの別の言葉に置き換えるという案もありそうです。

いずれにしても個人的にはそこまで強いこだわりはありません。

Copy link
Contributor

Choose a reason for hiding this comment

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

キャプチャーされた関数外の変数はis_mutating_methodを除いて関数内で変更できない

is_mutating_methodは細かい例外なので一旦忘れても良いと思います(入力された配列にpopは可能、が例です)が、言いたいことは関数は純粋関数なので入力値に対して変更を加える副作用は(原則)許されないという話です。
キャプチャー渡しにすると入力値に変更ができなくて純粋性を保証する機能の一つになっているという感じです。foundations/functionで純粋関数に関する説明はあるので、無理に毎回キャプチャー渡しを強調する必要もない気がします。ただわざわざfoundations/argumentsを読みにきた読者に対して隠蔽して良い内容なのかという気持ちもあります。

キャプチャーの機能そのものは一般的で現代的な言語は基本的に実装されている一方で、キャプチャーというテクニカルタームがあまり一般的ではないのは、おそらくC++(だけ?)がユーザーにどうキャプチャーするかの選択の余地があり、その存在が意識されるのだと思います。Typstにおいては原則キャプチャー渡しになるので、ユーザーは意識する必要はないという観点に立つと「渡された」に戻すのが妥当かと思いました。

Copy link
Contributor

@gomazarashi gomazarashi Sep 19, 2025

Choose a reason for hiding this comment

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

個人的には「渡された」のほうがしっくり来るように思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

みなさまありがとうございました。

@sbtseiji 「キャプチャー」は使わない方針になったので、申し訳ないですが「渡された」に戻してもらえますか?

///
/// # Argument Sinks
/// Like built-in functions, custom functions can also take a variable number of
/// arguments. You can specify an _argument sink_ which collects all excess
/// arguments as `..sink`. The resulting `sink` value is of the `arguments`
/// type. It exposes methods to access the positional and named arguments.
/// # 引数シンク
/// 組み込み関数と同様に、カスタム関数も可変個の引数を受け取れます。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// 組み込み関数と同様に、カスタム関数も可変個の引数を受け取れます
/// 組み込み関数と同様に、カスタム関数も可変長引数を受け取れます

/// 余分にある引数をすべてまとめて受け取る _引数シンク_ (キッチンシンクのようにさまざまなものが流れ込む先)は、`..sink`の形で指定できます。このとき生成される`sink`の値は`arguments`型になります。この型は、位置引数と名前付き引数の両方にアクセスするためのメソッドを提供しています。
///
/// ```example
/// #let format(title, ..authors) = {
Expand All @@ -29,9 +27,8 @@ use crate::foundations::{
/// #format("ArtosFlow", "Jane", "Joe")
/// ```
///
/// # Spreading
/// Inversely to an argument sink, you can _spread_ arguments, arrays and
/// dictionaries into a function call with the `..spread` operator:
/// # 引数の展開
/// 引数シンクとは逆に、`..spread`演算子を使うと、関数呼び出しにおいて引数や配列、辞書を展開して渡すことができます。
///
/// ```example
/// #let array = (2, 3, 5)
Expand All @@ -43,15 +40,14 @@ use crate::foundations::{
#[derive(Clone, Hash)]
#[allow(clippy::derived_hash_with_manual_eq)]
pub struct Args {
/// The callsite span for the function. This is not the span of the argument
/// list itself, but of the whole function call.
/// 関数呼び出し箇所のスパン。これは引数リスト自体のスパンではなく、関数呼び出し全体のものです。
pub span: Span,
/// The positional and named arguments.
pub items: EcoVec<Arg>,
}

impl Args {
/// Create positional arguments from a span and values.
/// スパンと値から位置引数を作成します。
pub fn new<T: IntoValue>(span: Span, values: impl IntoIterator<Item = T>) -> Self {
let items = values
.into_iter()
Expand All @@ -64,20 +60,20 @@ impl Args {
Self { span, items }
}

/// Attach a span to these arguments if they don't already have one.
/// 引数にスパンがアタッチされていない場合はアタッチします。
pub fn spanned(mut self, span: Span) -> Self {
if self.span.is_detached() {
self.span = span;
}
self
}

/// Returns the number of remaining positional arguments.
/// 残りの位置引数の個数を返します。
pub fn remaining(&self) -> usize {
self.items.iter().filter(|slot| slot.name.is_none()).count()
}

/// Insert a positional argument at a specific index.
/// 指定したインデックスに位置引数を挿入します。
pub fn insert(&mut self, index: usize, span: Span, value: Value) {
self.items.insert(
index,
Expand All @@ -89,7 +85,7 @@ impl Args {
)
}

/// Push a positional argument.
/// 位置引数をプッシュします。
pub fn push(&mut self, span: Span, value: Value) {
self.items.push(Arg {
span: self.span,
Expand All @@ -98,7 +94,7 @@ impl Args {
})
}

/// Consume and cast the first positional argument if there is one.
/// 最初の位置引数がある場合、それを取り出してキャストします。
pub fn eat<T>(&mut self) -> SourceResult<Option<T>>
where
T: FromValue<Spanned<Value>>,
Expand All @@ -113,7 +109,7 @@ impl Args {
Ok(None)
}

/// Consume n positional arguments if possible.
/// 可能ならn個数の位置引数を取り出します。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// 可能ならn個数の位置引数を取り出します
/// 可能ならn個の位置引数を取り出します

pub fn consume(&mut self, n: usize) -> SourceResult<Vec<Arg>> {
let mut list = vec![];

Expand All @@ -133,10 +129,9 @@ impl Args {
Ok(list)
}

/// Consume and cast the first positional argument.
/// 最初の位置引数を取り出してキャストする。
///
/// Returns a `missing argument: {what}` error if no positional argument is
/// left.
/// 位置引数が残っていなければ、`missing argument: {what}`エラーを返します。
pub fn expect<T>(&mut self, what: &str) -> SourceResult<T>
where
T: FromValue<Spanned<Value>>,
Expand All @@ -147,7 +142,7 @@ impl Args {
}
}

/// The error message for missing arguments.
/// 引数が足りない場合のエラーメッセージ。
fn missing_argument(&self, what: &str) -> SourceDiagnostic {
for item in &self.items {
let Some(name) = item.name.as_deref() else { continue };
Expand Down Expand Up @@ -295,9 +290,9 @@ impl Args {

#[scope]
impl Args {
/// Construct spreadable arguments in place.
/// 展開可能な引数をその場で生成します。
///
/// This function behaves like `{let args(..sink) = sink}`.
/// この関数は、`{let args(..sink) = sink}`のように動作します。
///
/// ```example
/// #let args = arguments(stroke: red, inset: 1em, [Body])
Expand All @@ -306,27 +301,23 @@ impl Args {
#[func(constructor)]
pub fn construct(
args: &mut Args,
/// The arguments to construct.
/// 作成する引数。
#[external]
#[variadic]
arguments: Vec<Value>,
) -> Args {
args.take()
}

/// Returns the positional argument at the specified index, or the named
/// argument with the specified name.
/// 指定したインデックスの位置引数、または指定した名前の名前つき引数を返します。
///
/// If the key is an [integer]($int), this is equivalent to first calling
/// [`pos`]($arguments.pos) and then [`array.at`]. If it is a [string]($str),
/// this is equivalent to first calling [`named`]($arguments.named) and then
/// [`dictionary.at`].
/// キーが[整数型]($int)の場合、それはまず[`pos`]($arguments.pos)メソッドを呼んでから、次に[`array.at`]を呼ぶのと同等です。キーが[文字列型]($str)である場合、まず[`named`]($arguments.named)メソッドを呼び、次に[`dictionary.at`]を呼ぶのと同等です。
#[func]
pub fn at(
&self,
/// The index or name of the argument to get.
/// 取得する引数のインデックスまたは名前。
key: ArgumentKey,
/// A default value to return if the key is invalid.
/// キーが無効な場合に返すデフォルト値。
#[named]
default: Option<Value>,
) -> StrResult<Value> {
Expand All @@ -336,7 +327,7 @@ impl Args {
.ok_or_else(|| missing_key_no_default(key))
}

/// Returns the captured positional arguments as an array.
/// キャプチャーした位置引数を配列の形で返します。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// キャプチャーした位置引数を配列の形で返します
/// 渡された位置引数を配列の形で返します

#[func(name = "pos", title = "Positional")]
pub fn to_pos(&self) -> Array {
self.items
Expand All @@ -346,7 +337,7 @@ impl Args {
.collect()
}

/// Returns the captured named arguments as a dictionary.
/// キャプチャーした名前つき引数を辞書の形で返します。
#[func(name = "named")]
pub fn to_named(&self) -> Dict {
self.items
Expand Down
2 changes: 1 addition & 1 deletion website/translation-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"/docs/reference/scripting/": "translated",
"/docs/reference/context/": "translated",
"/docs/reference/foundations/": "untranslated",
"/docs/reference/foundations/arguments/": "untranslated",
"/docs/reference/foundations/arguments/": "translated",
"/docs/reference/foundations/array/": "untranslated",
"/docs/reference/foundations/assert/": "untranslated",
"/docs/reference/foundations/auto/": "untranslated",
Expand Down
Loading