tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,39 @@
|
|||
link printf
|
||||
|
||||
procedure main()
|
||||
fsf1 := partial(fs,f1)
|
||||
fsf2 := partial(fs,f2)
|
||||
every s := [ 0, 1, 2, 3 ] |
|
||||
[ 2, 4, 6, 8 ] do {
|
||||
printf("\ns := %s\n",list2string(s))
|
||||
printf("fsf1(s) := %s\n",list2string(fsf1(s)))
|
||||
printf("fsf2(s) := %s\n",list2string(fsf2(s)))
|
||||
}
|
||||
end
|
||||
|
||||
procedure partial(f,g) #: partial application of f & g
|
||||
@( p := create repeat {
|
||||
s := (r@&source)[1] # return r / get argument s
|
||||
r := f(g,s) # apply f(g,...)
|
||||
}
|
||||
) # create and activate procedure p
|
||||
return p
|
||||
end
|
||||
|
||||
procedure fs(f,s) #: return list where f is applied to each element of s
|
||||
every put(r := [], f(!s))
|
||||
return r
|
||||
end
|
||||
|
||||
procedure f1(n) # double
|
||||
return n * 2
|
||||
end
|
||||
|
||||
procedure f2(n) #: square
|
||||
return n ^ 2
|
||||
end
|
||||
|
||||
procedure list2string(L) #: format list as a string
|
||||
every (s := "[ ") ||:= !L || " "
|
||||
return s || "]"
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue