Hello,
I have a little question about the possibilities of map() with user defined functions.
If we use bach.mapelem we can actually put what ever "function" we want between the lambda out and in.
How do we do this in inside bell?
My goal is a user defined, global scaling function inside bell where the input is any kind of llll that will be scaled element wise. Like bach.scale but inside bell.
The simple version of it looks like this:
$scale = ($input, $inmin, $inmax, $outmin, $outmax ->(
((($outmax-$outmin)*($input-$inmin)) / $inmax-$inmin ) + $outmin));
$scale($x1:1,$x1:2,$x1:3,$x1:4,$x1:5)
I'd like to apply it inside a user defined function and combine it with map(). I couldn't figure out how to could bring in the arguments $inmin, $inmax, $outmin, $outmax
This could look like this:
Scale = ($input, $inmin, $inmax, $outmin, $outmax ->(
$scale = ($input, $inmin, $inmax, $outmin, $outmax -> (
((($outmax-$outmin)*($x-$inmin))/$inmax-$inmin)+$outmin
)
);
map($input,$scale)
)
)
This gives there following error: [function:0x2c7154a00]
I suppose I have to lift something...
Thanks for your help.
bell.map() arguments for the modification function
-
- Posts: 209
- Joined: Fri Dec 03, 2010 1:51 pm
Re: bell.map() arguments for the modification function
Hi,
What you need here are lifted variables. This one works:
I must admit that the documentation of lifting is a bit abstract though.
Btw, I fixed your function definition (changed into .
Also, it is totally normal that connecting bach.print to the bach.eval object containing the function definition above returns a message of the form [function:0x12345678], as the return value of the code when you evaluate is the function itself. This textual representation you get is totally useless, but you should not consider it an error message: and, indeed, if you retrieve the native representation itself --- that is, the actual function --- you may be able to do crazy and possibly useful stuff like this:
<pre><code>
----------begin_max5_patcher----------
437.3ocuTFsSBCCEF95tmhlFtPM.ocLPzK7EwXV51ZfRFcKcc3LDd2s6zU.E
IhxzaVy4zy1+470+tsAHRRQinhfeD+LFg1FfPPp1DntXDYMuIMmWAkQThWKR
VQF51xHZLP5Dd5xwkZox32pjaRWJUKh0hTiSA1jvwzg3vv4sKyXtfwT7Kcui
pdsTkKLfTrCIKpM9rztrxLPWauLZpWxJ9FQVrMkUwXtwnkI0F23g1ONHxFgt
RVnre2Dgtcy4TFcJr4tf.+ycAC6AjH1vywCZX2vn25qvMMl2JENrPH6Av4gF
a98vBM52PM1oTKx2NoEYPiP5ZS7ODmBKFyNRj9GvVYMEpyhuDtZw2fPlicO.
rKx+7JI3jCVcMesvHzwBEOIG5K5eiQZzSCZtK75bRSovBi0SNI1W3jb84+mU
BFARtT84+lAbnM+G4dUQsN0SstqC3CfHSTYjJtwJ8Q0L0UyWdxdo5vt.ch5A
clbA5vNQGGF4kkcbGDoUBqQcUg6.XHDJUtvIPnVrQ5qODxv0V6mwdbWqcdhl
Yt+3PVacIZUsDNmCZGNqjvk.k8VTUI2MGvckfcAuCDV+MhI
-----------end_max5_patcher-----------
</code></pre>
I hope this helps,
andrea
What you need here are lifted variables. This one works:
Code: Select all
Scale = ($input, $inmin, $inmax, $outmin, $outmax ->(
$scale = ($input -^ $inmin, $inmax, $outmin, $outmax -> (
((($outmax-$outmin)*($input-$inmin))/$inmax-$inmin)+$outmin
)
);
map($input,$scale)
)
)
Btw, I fixed your function definition (changed
Code: Select all
$x-$inmin
Code: Select all
$input-$inmin
Also, it is totally normal that connecting bach.print to the bach.eval object containing the function definition above returns a message of the form [function:0x12345678], as the return value of the code when you evaluate is the function itself. This textual representation you get is totally useless, but you should not consider it an error message: and, indeed, if you retrieve the native representation itself --- that is, the actual function --- you may be able to do crazy and possibly useful stuff like this:
<pre><code>
----------begin_max5_patcher----------
437.3ocuTFsSBCCEF95tmhlFtPM.ocLPzK7EwXV51ZfRFcKcc3LDd2s6zU.E
IhxzaVy4zy1+470+tsAHRRQinhfeD+LFg1FfPPp1DntXDYMuIMmWAkQThWKR
VQF51xHZLP5Dd5xwkZox32pjaRWJUKh0hTiSA1jvwzg3vv4sKyXtfwT7Kcui
pdsTkKLfTrCIKpM9rztrxLPWauLZpWxJ9FQVrMkUwXtwnkI0F23g1ONHxFgt
RVnre2Dgtcy4TFcJr4tf.+ycAC6AjH1vywCZX2vn25qvMMl2JENrPH6Av4gF
a98vBM52PM1oTKx2NoEYPiP5ZS7ODmBKFyNRj9GvVYMEpyhuDtZw2fPlicO.
rKx+7JI3jCVcMesvHzwBEOIG5K5eiQZzSCZtK75bRSovBi0SNI1W3jb84+mU
BFARtT84+lAbnM+G4dUQsN0SstqC3CfHSTYjJtwJ8Q0L0UyWdxdo5vt.ch5A
clbA5vNQGGF4kkcbGDoUBqQcUg6.XHDJUtvIPnVrQ5qODxv0V6mwdbWqcdhl
Yt+3PVacIZUsDNmCZGNqjvk.k8VTUI2MGvckfcAuCDV+MhI
-----------end_max5_patcher-----------
</code></pre>
I hope this helps,
andrea
Re: bell.map() arguments for the modification function
Dear Andrea,
Thanks for your quick and well explained answer. What a wonderful occasion to finally understand how the syntax of lifted variables works. (I was close but somehow tried the lifting on the wrong place.)
Also it is indeed highly interesting to know, that one can pass a function as a native element to another bach.eval. Not sure how I will use this but my intuition says me that it will be of interest sooner or later :–)
Kind regards,
micha
Thanks for your quick and well explained answer. What a wonderful occasion to finally understand how the syntax of lifted variables works. (I was close but somehow tried the lifting on the wrong place.)
Also it is indeed highly interesting to know, that one can pass a function as a native element to another bach.eval. Not sure how I will use this but my intuition says me that it will be of interest sooner or later :–)
Kind regards,
micha