Comments (23)
@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.
from faustlibraries.
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.
from faustlibraries.
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.
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.
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.
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.
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.
Read: https://faustdoc.grame.fr/manual/syntax/#environment-expressions and https://faustdoc.grame.fr/manual/syntax/#environment-expression
from faustlibraries.
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.
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.
An environment contains a collections of definitions, some of them can be functions:
- you can "pass" parameters in the env with the
env(x,y,z) = environment{...}
syntax and usex,y,z
inside the{...}
scope. - the definitions inside
environment{...}
can possibly be functions.
from faustlibraries.
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.
We cannot do that: what is the need ?
from faustlibraries.
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.
I still don't understand why it can't be written with the current model...
from faustlibraries.
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.
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.
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.
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.
from faustlibraries.
Merged: https://faustlibraries.grame.fr/libs/basics/#batabulatend
from faustlibraries.
Related Issues (20)
- Feature request: allow si.bus(0) HOT 1
- Error in moogLadder filter algorithm HOT 7
- Add links to source code from libraries docs pages HOT 2
- co.RMS_compression_gain_mono causes core dump HOT 4
- Deprecated examples documentation ?
- Can the enable primitive become a fully supported feature? HOT 1
- backwards compatibility strategy / library versioning HOT 7
- DX7 Library is incomplete
- compilation of Max 8 externals for Apple ARM64 -> ok HOT 1
- Naming conventions for amplitude analysis functions HOT 18
- Strange behaviour of ba.if with fractional conditions < 1. HOT 1
- add edge detection to signal library HOT 1
- I want to help HOT 1
- oscillators.lib : 488 : ERROR : syntax error, unexpected IDENT HOT 6
- invalid links in inline documentation HOT 2
- hoa encoder3D HOT 4
- typo "quantizer.lib" in stdfaust.lib HOT 1
- Make the behaviour of si.smoo SR-independent. HOT 3
- pm.flute_ui_MIDI is not in tune
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faustlibraries.