Code Monkey home page Code Monkey logo

Comments (23)

sletz avatar sletz commented on June 19, 2024 1

@josmithiii you actually helped improve the documentation of tabulate and tabulate_chebychev ((-;
@magnetophon better add the new tabulateNd in basics.lib and as always better have the cleanest and simplest code that can be written..

from faustlibraries.

josmithiii avatar josmithiii commented on June 19, 2024

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

I assumed it was going into basics.lib, since that is where tabulator lives, but I don't really care where it ends up.

from faustlibraries.

josmithiii avatar josmithiii commented on June 19, 2024

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

Currently, the code has (simplified):

process = tabulateNd(params);
tabulateNd(params) =
  calc.lin
with {
  calc =
    environment {
// do the work here
  };
};

When I change it to:

process = tabulateNd(params).lin;
tabulateNd(params) =
  environment {
// do the work here
};

I get: maths.lib : -1 : ERROR : an environment can't be used as a function : closure[environment, genv = {}, lenv = {}].

What does that error mean?

Here is the actual code change: magnetophon/lamb@master...broken

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

I cleaned up the code as far as I could: https://github.com/magnetophon/lamb/blob/eb7c4baabcbf6bb7de5b278811a9b7ae79328122/lamb.dsp#L23-L192
but I still need to get rid of the with mentioned in the above comment.

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

I found a minimal example to reproduce the error:

env = environment {
        part=1+_;
        };

process =
  env(1).part;

I would expect this to output 2.
Instead, I get:

lamb.dsp : -1 : ERROR : an environment can't be used as a function : closure[environment, genv = {}, lenv = {}]

Is that a bug or a feature? ;)

This works, but is not applicable to tabulateNd, since the number of parameters should be variable:

env(x) = environment {
       part=1+x;
       };

process =
 env(1).part;

from faustlibraries.

sletz avatar sletz commented on June 19, 2024

How can the message be more clear ? With the first env(1) syntax you are using the environment as if it where a function, which is not. In the second way env(x), the x parameter is usable in the environment {...} scope.

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

Why can you not use an environment as if it's a function?
Does it help the faust user?
If yes, how?
If no, is it possible to change?

from faustlibraries.

sletz avatar sletz commented on June 19, 2024

Read: https://faustdoc.grame.fr/manual/syntax/#environment-expressions and https://faustdoc.grame.fr/manual/syntax/#environment-expression

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

I'm sorry, most of that goes over my head.
Or, to put it in another way: "I know some of those words!" 🤣

Faust is a lexically scoped language. The meaning of a Faust expression is determined by its context of definition (its lexical environment) and not by its context of use.

What is lexically scoped?
What is meant by "context of definition" and "context of use"?
What is a lexical environment?

To keep their original meaning,

What do you mean by an expression "keeping it's meaning"?

Faust expressions are bounded to their lexical environment in structures called closures.

What is bounded? What is a closure?

In any case, I don't think the manual explains why you cannot use an environment as if it's a function.
Would it be possible and/or desirable to change the compiler to allow that?

from faustlibraries.

sletz avatar sletz commented on June 19, 2024

Try to Google that first, like: https://www.techtarget.com/whatis/definition/lexical-scoping-static-scoping#:~:text=Lexical%20scoping%2C%20also%20known%20as,in%20which%20it%20is%20defined.
https://en.wikipedia.org/wiki/Closure_(computer_programming)#:~:text=In%20programming%20languages%2C%20a%20closure,function%20together%20with%20an%20environment.

from faustlibraries.

sletz avatar sletz commented on June 19, 2024

An environment contains a collections of definitions, some of them can be functions:

  • you can "pass" parameters in the env with theenv(x,y,z) = environment{...} syntax and use x,y,z inside the {...} scope.
  • the definitions inside environment{...} can possibly be functions.

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

Thanks. I understand how it works and what the constraints are, more or less.
The manual explains that you cannot use an environment as if it's a function.

What I would like to know: does it have to be this way?
Would it be possible and/or desirable to change the compiler to allow that?

Sorry for repeating the question, but you seem to miss it every time.

from faustlibraries.

sletz avatar sletz commented on June 19, 2024

We cannot do that: what is the need ?

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

The need is cases like mine:
You have a couple of related functions, in this case val, lin and cub, that need a lot of other functions to work, but the functions take a variable amount of paramters.

Why do you ask for the need if you cannot change it though? :)

from faustlibraries.

sletz avatar sletz commented on June 19, 2024

I still don't understand why it can't be written with the current model...

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

How would you do it?
I guess I could make another parameter, 0 for val, 1 for lin and 2 for cub, but ideally it would work the same as regular tabulate.

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

As always, in hindsight it was easy: just declare tabulateNd(N,C,expression,parameters) and put parameters: as the first line of the val, lin and cub functions.

I'll get started on the PR now! :)

Thanks for your patience @sletz!

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

That solution does have the downside that you need to call it with extra brackets around the parameters, so they become one entity.
Like so:

tabulateNd(3,1,threeDfunction,   ( sizeX,sizeY,sizeZ,rx0,ry0,rz0,rx1,ry1,rz1,x,y,z ) ).lin

Does anyone know a more elegant solution?
Otherwise: How should I explain in the docs of this function why the brackets are needed?

I barely understand it myself, so I'm not in a good position to explain it to others.
Ideally we'd have an explanation that is understandable to both computer scientists and audio engineers,.
In other words: please do use the proper jargon, but try to also include a simple version.

My best shot at the simple version would be:

In Faust, when you declare an environment, you need to either declare it without specifying any parameters at all, or you need to specify the correct number of parameters. (TODO: explain why this is)
Since we need both named parameters and a variable number of parameters, we need to turn the variable number of parameters into one parameter by putting brackets around them in the function call.

Is that more or less correct?

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

I made some docs. They don't explain the whole thing, but at least they give an overview.
https://gist.github.com/magnetophon/4b6db0aa32ab6983fa931c6d2454d91f

Please give me feedback.

  • Is everything clear?

  • Is it too much detail, not enough?
    I imagine it's both depending who is reading and on which part of the docs we are talking about.
    For example: a computer scientist would have summarized the whole "Storage method" section in a few jargon terms, but then I wouldn't understand it myself, at least not the me before I wrote all this! 😄

  • Am I using correct English?

I particularly hope Julius can have a look, being both a domain expert and a native English speaker.

from faustlibraries.

josmithiii avatar josmithiii commented on June 19, 2024

from faustlibraries.

magnetophon avatar magnetophon commented on June 19, 2024

Merged: https://faustlibraries.grame.fr/libs/basics/#batabulatend

from faustlibraries.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.