|
|
|
10-08-2019, 09:43 AM
|
#1
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Is anyone doing functional programming in ReaScript?
I've been doing some research on functional programming, and it seems like an interesting concept.
I'm interested in exploring if it's something I want to do. Unfortunately Lua isn't by default a functional programming language, so you have to implement that ability if you want to use it.
Implementing something I barely have a grip on seems like a bad idea. So do any of you currently use functional programming in Lua? If so, could you link me to some resources for implementing it myself so I can give it a try?
|
|
|
10-08-2019, 10:00 AM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Lua can be very functional if you feel like working that way. We have first-class functions, closures, lazy evaluation of conditionals, recursion (and particularly tail recursion)... all it's missing is filter/map/reduce in the standard library, but those are straightforward to implement.
https://pragprog.com/magazines/2013-...duction-to-lua
Lua doesn't have any concept of immutability by default, though you can make some things immutable if you really need to with a bit of work, and having dynamic typing can make things a little messy sometimes, but it's really just up to you to know what you're trying to do.
If you want, post some code and I'd be happy to offer more specific pointers.
(Incidentally, I'm almost ready with v3 of my GUI library and it will add a bunch of table functions for more functional approaches. )
|
|
|
10-08-2019, 10:16 AM
|
#3
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
Lua can be very functional if you feel like working that way. We have first-class functions, closures, lazy evaluation of conditionals, recursion (and particularly tail recursion)... all it's missing is filter/map/reduce in the standard library, but those are straightforward to implement.
https://pragprog.com/magazines/2013-...duction-to-lua
Lua doesn't have any concept of immutability by default, though you can make some things immutable if you really need to with a bit of work, and having dynamic typing can make things a little messy sometimes, but it's really just up to you to know what you're trying to do.
If you want, post some code and I'd be happy to offer more specific pointers.
(Incidentally, I'm almost ready with v3 of my GUI library and it will add a bunch of table functions for more functional approaches. )
|
Thanks for the info! At the moment I am still very new to this functional programming thing, so I'm still trying to wrap my head around it. I know some of the basic functions that are used, but I don't know much about the advanced stuff. I don't have any specific examples I'm looking at, I'm just more searching for the building blocks to make it work so I can experiment.
Speed is a concern for me, and with something like this, if it's done wrong it can be very slow I'm assuming. There's this implementation which seems like the creator knew what he was doing. I might try and implement this and mess around with it. The source code is currently beyond my comprehension, but maybe that will change eventually.
I look forward to your release of v3! I'm currently using your library for my pitch correction script and it is fantastic. I can't wait to migrate it over to your new version and clean it up!
|
|
|
10-08-2019, 10:57 AM
|
#4
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
I don't see any immediate benefits for trying to program in a purely functional style with Lua. The language just wasn't designed for that purpose. But for example higher order functions are possible to do and can be useful.
I could on for a longer rant about functional programming in general, but maybe I won't go there now...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
10-08-2019, 11:08 AM
|
#5
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Xenakios
I don't see any immediate benefits for trying to program in a purely functional style with Lua. The language just wasn't designed for that purpose. But for example higher order functions are possible to do and can be useful.
I could on for a longer rant about functional programming in general, but maybe I won't go there now...
|
I wouldn't mind hearing a rant about it. I'm interested in all viewpoints regarding it. It's just something that I've heard about and seems interesting, so I'm doing research to see if it's a plausible and effective thing to do.
|
|
|
10-08-2019, 11:13 AM
|
#6
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Quote:
Originally Posted by Xenakios
I don't see any immediate benefits for trying to program in a purely functional style with Lua. The language just wasn't designed for that purpose. But for example higher order functions are possible to do and can be useful.
I could on for a longer rant about functional programming in general, but maybe I won't go there now...
|
It's definitely a choice to be made rather than something everyone should always do, but IMO starting from "try to write small, pure functions", if nothing else, will almost always make your life better.
FP certainly adds performance costs that can be significant depending on what you're doing - for instance, long chains of .sort().map().filter(), but that's often something that can be avoided with a basic understanding of what the functions are doing and what you're actually trying to accomplish.
My position: functional when it makes sense, OO when it makes sense, Imperative when it makes sense. Different problems call for different solutions.
|
|
|
10-08-2019, 01:47 PM
|
#7
|
Banned
Join Date: Sep 2015
Posts: 1,650
|
I'm totally up for reading a nice rant too!
|
|
|
10-09-2019, 05:29 AM
|
#8
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
I guess I'd need to think about it a bit further, but it just has looked like to me GUI and audio just are not that great to deal with functional programming, especially if the programming language isn't completely functionally oriented and optimized to deal with that. There are special languages like Faust for audio, but I haven't found those particularly attractive to use. Roli's in-development SOUL language for audio didn't take a functional approach, which might suggest they haven't found functional programming to be a feasible paradigm either.
My own recent experience is mostly with C++ and while that does allow a functional approach, it's very difficult to do that both flexibly and efficiently for something like audio.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
10-10-2019, 12:36 PM
|
#9
|
Human being with feelings
Join Date: Jun 2008
Location: Austin
Posts: 289
|
Hassle Nurface
Submit a feature request for a Reascript/Haskell ;-)
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:54 PM.
|