Accessing one expression library functions from another expression lib


I have a use case where I am looking forward to access methods of one library(expression file) from another library (expression file 2).

Is their a way to achieve this?

You should be able to reference the other library through the lib variable. Is that not working?

For example, if you this as the library helper.expr:

    chefify: x => x + ' bork! bork! bork!'

You should be able to reference it from another library, like so:

    msg: () => lib.helper.chefify('Hello, World!')

Note that if the references are not in functions, but directly in the top-level expression, you’ll need to ensure the libraries are listed in the right order in the pipeline properties.

I found a better way to achieve what i was look for.

But thanks for highlighting this.@tstack

I have a use case where a child pipeline has multiple expr files.

I want to pass a value to the child pipeline using which my chiled pipeline would choose one of the expression library.
is there a way to do it ?

Is there a way to declare methods with global scope in expression library.
Is nesting multiple libraries together a good preactice ?

In the child pipeline properties, add a parameter that you’ll use to specify the library to load. Then, in the “Expression Libraries” section, add a path that uses the parameter you just created. You’ll probably also want to set the name of the imported library using the “As” column. In the screenshot below, the parameter is config and defaults to the library file dev.expr and the library can be referenced via lib.conf in expressions:

In the parent pipeline, you’ll pass the config parameter with the library paths that you want. In the screenshot below, there are two documents entering the PipeExec with “dev.expr” and “prod.expr” as the paths. So, the child will execute first with the “dev” library and then with the “prod” library.

Do you mean without the lib.libname prefix? No, libraries are always imported under the lib object.

I’m not sure what you mean by this, can you give an example?

lib1 is used by lib2 and then libe2 is used by lib3

referencing multiple library through the lib variable

I think it’s fine to reference one library from another.

Do we expect some slowness ?

No, why would you think that’s the case?

The libraries should be cached in the Snaplex node memory, so having more than one should not affect performance greatly. If you are seeing a performance issue, that might be a bug that needs to be fixed.

Thanks for the help @tstack

@Kulashekharan FYI

Hi @tstack by global scope in my query. I meat I have a expression file where we can decalre a function on top level which could be accessed from anywhere in the object(same expression file) using something like globalthis Or this (basically " this context" which would resolve at any herarical level throughout the file)

I think I understand now… Take a look at the Object Literal documentation where it mentions some of the variables that you can use to reference other parts of a nested literal. I think probably want to use __root__ for your situation.

Maybe something like the following (I haven’t tried it out):

    value: 42,
    child: {
        adder: x => __root__.value + x

thanks @tstack .This was the exact use case.

Also do we have a total number of libraries we can add to a pipeline ?
Do we have a standerd IDE to write expressions ?
or if you can suggest any extension for VS code.

I don’t think so.

The expression language is mostly a subset of JavaScript, so I would just use an editor with support for that. The main difference is that expression language is just expressions, not statements. Don’t try to use things like if or function(), you need to stick to arrow functions (e.g. (x, y) => x + y). One addition to the e-lang that is not in JavaScript is the match operator. You might find that useful if you have to do a lot of conditionals.

Thanks @tstack

This helped me a lot.