チャンク構文

シングルチャンク

構文:

chunk 番号 of 式

チャンク式の表し方には、すべての種類のチャンクに共通した複数のやり方があります。シングルチャンク要素の記述方法:

put item 17 of scores into quiz3

put word 4 of "Mary had a little lamb" -- "little"

負の番号を使うと、元のテキストの後ろから数えることができます。-1が指すのは一番後ろのチャンク要素、-2が指すのは後ろから2番目のチャンク要素、といった具合になります。

get item -2 of "apple,banana,pear,orange" -- "pear"

注:この構文記述(以降も同様)では、あらゆる種類のチャンク(character(省略形char)、word、line、item、text itemまたはlist item)を表すのにchunkという語を使用しています。同様に、chunksはこれらの用語の複数形を表します。番号は正または負の番号の決定要素、はそのチャンクのソースまたは参照先の値です。「of」の位置には、常に「of」か「in」のいずれかを用いることができます。その文脈で自然に見える方を使用して構いません。

順序チャンク

構文:

{the} 順序 chunk of 式

チャンク要素は、序数(first、second、...、 millionth)によって参照することもできます。

get the third item of (9,12,13,42) -- 13

Last、Penultimate、Middle、Any

序数以外にも、lastpenultimatemiddle(またはmid)およびanyの4つの「特殊な順序表現」を使うことができます。Lastは最後のチャンク要素(-1を指定する場合に同じ)を特定します。Penultimateは最後から2番目のチャンク要素(-2を指定する場合に同じ)を特定します。Middleは、その種類のチャンク要素の合計数に基づいて、中央に最も近い要素を選択します。Anyは、指定された種類の全要素の中からランダムに要素を選択します。

例:

put any item of "cow,ant,moose,goat,donkey,elephant"

例:

get the middle character of "serendipity" -- "d"

例:

put the penultimate word of "Peace is its own reward." -- "own"

例:

put the last line of gettysburgAddress into finalParagraph

チャンク範囲

構文:

chunks 初めの番号または順序 to 終わりの番号または順序 of 式

chunks 範囲 of 式

{the} first 個数 chunks of 式

{the} last 個数 chunks of 式

チャンク式では、チャンク要素の範囲を参照することもできます。チャンク範囲には、指定した初めの要素と終わりの要素、さらにその間のすべての要素が含まれます。

例:

put characters 3 to 5 of "dragon" -- "ago"

例:

put words 1 to 2 of "Alas, poor Yorick!" -- "Alas, poor"

例:

put items middle to last of (1,2,3,4,5,6,7) -- (4,5,6,7)

例:

put the second to penultimate items of (1,2,3,4,5,6)-- (2,3,4,5)

例:

put items -3 to -1 of (1,2,3,4,5,6) -- (4,5,6)

チャンクの範囲には、範囲値を使ってアクセスすることもできます。

例:

put chars 4..6 of "incredible" -- "red"

例:

set fruitRange to 7..10

例:

put chars fruitRange of "now appearing" -- "pear"

値の初めまたは終わりの範囲の場合、「first n」個または「last n」個のチャンク要素を指定することも可能です。

例:

put the last three items of (1,2,3,4,5,6) -- (4,5,6)

例:

get the first 4 characters of "abracadabra" -- "abra"

マルチチャンク(チャンクのリスト)

構文:

chunks インデックスリスト of 式

順序を示したチャンク番号のリストを指定すると、元の値の個別チャンクにリストとしてアクセスすることができます。

例:

put items (1,3,5,7) of scores into oddResults

例:

put words (4,1,2,-1) of "Mary had a little lamb" -- (little,Mary,had,lamb)

マルチチャンクへのアクセス結果は常にリストになります。負の番号や特殊な順序表現(middle、anyなど)も使用可能です。

例:

get items (-2,"middle") of "apple,banana,pear,orange,peach" -- (orange,pear)

 

This topic was last updated on 2月 01, 2019, at 11:13:23 午前.

Eggplant icon Eggplant.io | Documentation Home | User Forums | Support | Copyright © 2019 Eggplant