Old 10-08-2019, 09:43 AM   #1
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 495
Default 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?
Alkamist is offline   Reply With Quote
Old 10-08-2019, 10:00 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,238
Default

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. )
Lokasenna is offline   Reply With Quote
Old 10-08-2019, 10:16 AM   #3
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 495
Default

Quote:
Originally Posted by Lokasenna View Post
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!
Alkamist is offline   Reply With Quote
Old 10-08-2019, 10:57 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,913
Default

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...
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 10-08-2019, 11:08 AM   #5
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 495
Default

Quote:
Originally Posted by Xenakios View Post
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.
Alkamist is offline   Reply With Quote
Old 10-08-2019, 11:13 AM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,238
Default

Quote:
Originally Posted by Xenakios View Post
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.
Lokasenna is offline   Reply With Quote
Old 10-08-2019, 01:47 PM   #7
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,623
Default

I'm totally up for reading a nice rant too!
snooks is offline   Reply With Quote
Old 10-09-2019, 05:29 AM   #8
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,913
Default

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.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 10-10-2019, 12:36 PM   #9
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 284
Default Hassle Nurface

Submit a feature request for a Reascript/Haskell ;-)
toddhisattva is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:43 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.