Cómo incluir funciones específicas en lugar de un script completoHola,
¿Hay alguna forma de importar solo funciones específicas de un archivo JSL?
Por ejemplo, en python puede escribir: "from pandas import read_csv" para importar solo la función read_csv. Actualmente, en JMP, siempre importo un archivo JSL completo con muchas funciones definidas, y creo que sería mejor importar solo las funciones que necesito en aras de la claridad (y tal vez el rendimiento).
Gracias
Ricardo
Acceso a los datosRe: Cómo incluir funciones específicas en lugar de un script completoEfectivamente funciona, muchas gracias!Re: Cómo incluir funciones específicas en lugar de un script completoLo siento, mi error, se necesita una función name expr (cuando se copia la función.Aquí hay un ejemplo revisado:
incluido.jsl:
f = function({x,y}, x + y);Script para cargar la función:
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: Cómo incluir funciones específicas en lugar de un script completoGracias por su ayuda, esto definitivamente funciona para funciones sin ningún argumento.
Desafortunadamente me encuentro con un error cuando trato de importar una función con dos argumentos, el error dice que no doy ningún argumento cuando la función requiere 2 de ellos (lo cual es cierto). Aquí está el código de ejemplo:
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);¿Sabes dónde está el error? Intenté especificar argumentos al copiar las funciones, pero no parece resolver el problema.
Gracias
Ricardo
Re: Cómo incluir funciones específicas en lugar de un script completoTampoco conozco nada tan sencillo como las ofertas de Python, pero aquí hay dos opciones que hacen el trabajo:
Considere un archivo llamado incluido.jsl:
a = function({}, 1);
b = function({}, 2);Para cargar la función directamente en el contexto de su script:
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();
O, para mantener la función en un espacio de nombres separado:
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: Cómo incluir funciones específicas en lugar de un script completoNo conozco ninguna forma de incluir solo un subconjunto de un archivo de inclusión.