Problema
Hai una JSL che può essere utilizzata in più di un progetto, con piccole modifiche, e vuoi conservare una copia per renderla più facile da mantenere.
Soluzione
Utilizzare un file separato e includerlo in un programma principale. Utilizzare gli spazi dei nomi per mantenere le variabili isolate da altri moduli. Costruisci gli spazi dei nomi in modo che il programma principale possa aggiungere personalizzazioni.
// "example.jsl" reusable, extensible module
example = New Namespace( "example" ); // namespace to hold the reusable code
example:aaa = 1; // a variable in the namespace
// this represents the extensible part of the module
example:uuu = Function( {p}, Return( p ) ); // no transform by default
// this represents the reusable part of the module
example:fff = Function( {p}, // do something amazing
example:aaa += 1;
Return( example:uuu( p ) * example:aaa );
);
// "mainprog.jsl" uses the example code, and extends it
Include( "example.jsl" );
// this function replaces the default
example:uuu = Function( {p},
Return( Sqrt( p ) )
);
// use the amazing code from the package
p = example:fff( 16 );
q = example:fff( 9 );
r = example:fff( 4 );
Show( p, q, r );
Discussione
Potresti voler aggiungere un esempio: init (parametri) funzione che si chiama dopo l'inclusione per eseguire una sola volta l'installazione. Oppure, se non ci sono parametri, puoi eseguire la configurazione unica nel file example.jsl.
Guarda anche
L'indice di scripting descrive numerosi parametri aggiuntivi.