hippiehunter ([info]hippiehunter) wrote,
@ 2008-12-18 09:46:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:fp, synergy

functional programming in Synergy/DE
Yes it is possible to do the basics of functional programming in Synergy. It is missing some of the conveniences of C++ or ML but still it works. sometime in the future I will explain how this is useful to the average user.

 
import System.Collections
 
namespace functor
;;; <summary>
    ;;; The main entry point for the application.
    ;;; </summary>        
main
record
al, @ArrayList
ii, int
proc
al = new ArrayList()
for ii from 0 thru 100
begin
data iii, @int
iii = (@int)ii
al.add(iii)
end
open(1, o, "tt:")
for_each.Call(al, new MyFunctor())
endmain
class for_each
public static method Call, void
al, @ArrayList
func, @SimpleIntFunctor
endparams
record
ii, int
proc
for ii from 0 thru al.Count - 1
begin
func.Call((int)al[ii])
end
endmethod
    endclass
abstract class SimpleIntFunctor
public abstract method Call, void
i, int
proc
endmethod
endclass
class MyFunctor extends SimpleIntFunctor
public override method Call, void
i, int
proc
   writes(1, %string(i))
endmethod
endclass
endnamespace
 



(7 comments) - (Post a new comment)


[info]granda
2008-12-18 09:24 pm UTC (link)
Now.. if only you didn't require a runtime with licensing restrictions running within it in order to do said functional programming.

(Reply to this)


[info]sterlingcamden
2008-12-18 11:12 pm UTC (link)
It's too bad you have to have a named class for each unique function object. Sure would be nice if we could do:

al.add(
function ,void
i, int
proc
writes(1, string(i))
end
)


(Reply to this) (Thread)


[info]sterlingcamden
2008-12-18 11:12 pm UTC (link)
... even if we had to say "new" in front of "function".

(Reply to this) (Parent)(Thread)


[info]hippiehunter
2008-12-19 12:40 am UTC (link)
I've been trying to think up terrible ways to get better syntax out of this.... I'm sure there must be something I can do with macros + defines + include files

(Reply to this) (Parent)(Thread)

#1 on my wish list
(Anonymous)
2008-12-19 08:10 pm UTC (link)
is multi-line macros, which would make this trivial:

declare_functor(classname, return_type)
;in req param1, int
...
proc
;code here
mreturn return_value
end_functor

(Reply to this) (Parent)(Thread)

Re: #1 on my wish list
[info]sterlingcamden
2008-12-19 08:14 pm UTC (link)
That was me, I wasn't logged in.

using .defines and .includes, about the best you could get would be

.define classname "MyFunctor"
.define returntype "int"
declare_functor ;which does a .include
in req param1, int
;...
proc
mreturn return_value
end_functor ;which does another .include

(Reply to this) (Parent)

I've kinda gone off-leash with this idea
[info]sterlingcamden
2009-08-05 07:27 pm UTC (link)
http://www.chipstips.com/?p=338

(Reply to this)


(7 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…