スクリプト全体ではなく特定の関数を含める方法こんにちは、
JSL ファイルから特定の関数のみをインポートする方法はありますか?
たとえば、Python では、「from pandas import read_csv」と記述して、read_csv 関数のみをインポートできます。 現在、JMP では、常に多くの関数が定義された JSL ファイル全体をインポートしていますが、明確さ (およびおそらくパフォーマンス) のために、必要な関数だけをインポートする方がよいと考えています。
ありがとう
リチャード
データアクセスRe: スクリプト全体ではなく特定の関数を含める方法確かにそれはうまくいきます、ありがとう!Re: スクリプト全体ではなく特定の関数を含める方法申し訳ありませんが、私の間違いです。関数をコピーするときは、名前 expr( 関数が必要です。修正された例を次に示します。
含まれる.jsl:
f = function({x,y}, x + y);関数をロードするスクリプト:
names default to here(1);
//load the new file in a local here namespace
Eval( Eval Expr( local here(
include("included.jsl");
//Reference the original script's here namespace in this new here namespace
//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
//outside of this 'local here' context.
//from the other.
ns = Expr( namespace("here") );
//copy and functions you want to keep
ns:f = Name expr( here:f );
) ) );
//Now functions are in here namespace
f(1,2);Re: スクリプト全体ではなく特定の関数を含める方法ご協力ありがとうございます。これは引数なしの関数に対して確実に機能します。
残念ながら、2 つの引数を持つ関数をインポートしようとするとエラーが発生しました。関数に 2 つの引数が必要な場合に引数を指定しないとエラーが表示されます (これは本当です)。 サンプルコードは次のとおりです。
names default to here(1);
MyRejet = 1;
Lot_nom = "G123456";
//load the new file in a local here namespace
Eval( Eval Expr( local here(
Include("include.jsl");;
//Reference the original script's here namespace in this local here namespace
//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
//outside of this 'local here' context.
ns = Expr( namespace("here") );
print(ns);
//copy and functions you want to keep
ns:DataExtraction = here:DataExtraction;
) ) );
//Now functions are in this namespace
DataExtraction(Lot_nom, MyRejet);どこにエラーがあるか分かりますか? 関数をコピーするときに引数を指定してみましたが、問題は解決しないようです。
ありがとう
リチャード
Re: スクリプト全体ではなく特定の関数を含める方法Python が提供するほど単純なものは知りませんが、仕事を完了するための 2 つのオプションを次に示します。
include.jsl というファイルについて考えてみましょう。
a = function({}, 1);
b = function({}, 2);スクリプトのコンテキストで関数を直接ロードするには:
names default to here(1);
//load the new file in a local here namespace
Eval( Eval Expr( local here(
include("included.jsl");
//Reference the original script's here namespace in this local here namespace
//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
//outside of this 'local here' context.
ns = Expr( namespace("here") );
//copy and functions you want to keep
ns:a = here:a;
) ) );
//Now functions are in this namespace
a();
または、関数を別の名前空間に保持するには、次のようにします。
names default to here(1);
//create namespace to hold functions you want to keep from included file
ns = new namespace();
//load the new file in a local here namespace
Eval( Eval Expr( local here(
include("included.jsl");
//Reference the ns namespace in this new here namespace
ns = Expr( ns );
//pick and choose any functions you want to keep
ns:a = here:a
) ) );
//Now either call the functions from the ns namespace
ns:a();
//or copy them to the here namespace
a = ns:a;
a();
Re: スクリプト全体ではなく特定の関数を含める方法インクルード ファイルからサブセットのみをインクルードする方法はわかりません。