Page 3 of 5
Re: it is about time...
Posted: Mon Jan 23, 2017 10:13 pm
by 110
since std:: isnt available and math:: doesnt have it, it seems that
is the only way to go.
is that best practice? it is really hard to read for me, i know it as
max(0, 5)plus i think an array creates at least a namespace in memory, if not more troublesome stuff.
Re: it is about time...
Posted: Mon Jan 23, 2017 10:18 pm
by RJHollins
just following along with your posts 110.
I noticed RUBY ERRORs in this last example. It seems the 'period' after a number is throwing an error.
I removed the 'dot', and the calculations show. [i've not verified the correctness of the calculation].
Anyway, just thought I'd mention, as I look to learn every chance I get.
thanks for your posts !

Re: it is about time...
Posted: Mon Jan 23, 2017 10:33 pm
by 110
i know that the one or other is following and wonders how to help. it is probably not so obvious what i exspect.

so i just share my experience, better than nothing.
Re: it is about time...
Posted: Mon Jan 23, 2017 10:41 pm
by 110
which period, that 69. in the rightmost module?
yes, thats also coming from maxmsp-expr where this dot indicates that the number is a float and should also be used like that.
while it is valid to write
expr $f1*69 in max and returns a float (because the variable $f1 is of type float), you will run into trouble when you try to do
expr $f1/69 - because the division will now be performed in int, so if you send a 17 in this thing it will return 0. float.
unlike in pure data, we know int and float in max and in most situations using a float matters (expr is actually one of the few exceptions), and we may write 69. for 69.0 .
i guess if i take all these things into account for automatic conversion of my expressions, my max-to-ruby max-patch will be more complicated in the end than my most complicated expression is.

Re: it is about time...
Posted: Mon Jan 23, 2017 11:27 pm
by KG_is_back
110 wrote:since std:: isnt available and math:: doesnt have it, it seems that
is the only way to go.
is that best practice? it is really hard to read for me, i know it as
max(0, 5)plus i think an array creates at least a namespace in memory, if not more troublesome stuff.
not really. When you call [a,b,c].max what happens is array is created, max method is called upon it and array gets discarded. If you had function like max(a,b,c) what would ruby do is create array [a,b,c] and pass that array to the max(*p) method. it is effectively the same thing happening. If you really want to use traditional max/min method you can easily create one:
Code: Select all
def max(*p)
p.max
end
def min(*p)
p.min
end
Re: it is about time...
Posted: Tue Jan 24, 2017 1:05 am
by 110
interesting!

so i know two working methods now to choose from.
here is the next issue. for noise with chi distribution i need to trigger this
((Math.sqrt(-2.0*Math.log(1.0-(rand))))*(Math.cos((rand)*6.283185307))**2.0)
for n times and accumulate the result.
no idea how to do that in ruby - and no idea how to make 5 consecutive triggers from 1 outside the ruby object.
both would be a good exercise.
Re: it is about time...
Posted: Tue Jan 24, 2017 1:29 am
by 110
it seems i could do
where i need
to output 0 and 1.
but it looks a bit strange and converting that programatically will be more work then to type it by hand.
Re: it is about time...
Posted: Tue Jan 24, 2017 1:34 am
by RJHollins
110 wrote:which period, that 69. in the rightmost module?

Yes ... for that example, I just added a '0' after the period ---> 69.0
It seems SYNTAX is particular about this.
Same thing [i believe] with examples like: 0.123456 It seems the 0 in front of the decimal point is required.
Re: it is about time...
Posted: Tue Jan 24, 2017 1:39 am
by 110
right, there were more errors like that, they just didnt show up as errors as inputs were missing and stuff.
so now here...
Code: Select all
output (Math.log(@f1))
def Math.log(*p)
log(*p)
end
output (log(@f1))
nice try, 110, but "stack level too deep". hmpf.
Re: it is about time...
Posted: Tue Jan 24, 2017 2:40 am
by 110
...