aqua/aqua-src/closure.aqua

70 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

2021-11-04 16:22:57 +00:00
module Closure declares *
2022-03-15 11:52:43 +00:00
import "builtin.aqua"
2021-11-04 16:22:57 +00:00
2022-03-15 11:52:43 +00:00
export closureOut2, closureIn, closureOut, closureBig, closureOut3
service MyOp("op"):
identity(s: string) -> string
service LocalSrv("local_srv"):
2021-11-04 16:22:57 +00:00
inside: -> ()
withNums: i64 -> i64
2021-11-04 16:22:57 +00:00
2022-03-15 11:52:43 +00:00
func closureOut2():
on HOST_PEER_ID:
closure = () -> Info:
p2Id <- Peer.identify()
<- p2Id
closure()
func closureIn(peer1: string) -> string:
variable = "const"
co on peer1:
p1Id <- MyOp.identity("co on")
closure = (s: string) -> string:
if s == "in":
LocalSrv.inside()
p2Id <- MyOp.identity(s)
<- p2Id
p <- closure("in")
<- p
func closureOut3(peer2: string) -> Info:
on peer2:
closure = (s: string) -> Info:
if s == "in":
LocalSrv.inside()
p2Id <- Peer.identify()
<- p2Id
p2Id <- closure( ( closureIn("on") ) )
2022-03-15 11:52:43 +00:00
<- p2Id
func closureOut(peer2: string) -> Info:
closure = func (s: string) -> Info:
if s == "in":
LocalSrv.inside()
p2Id <- Peer.identify()
<- p2Id
on peer2:
p2Id <- closure("on")
LocalSrv.withNums(3+5 * 2)
2022-03-15 11:52:43 +00:00
<- p2Id
func closureBig(peer1: string, peer2: string) -> string, string:
2021-11-04 16:22:57 +00:00
variable = "const"
2022-03-15 11:52:43 +00:00
co on peer1:
p1Id <- MyOp.identity("co on")
closure = func (s: string) -> string:
p2Id: *string
if s == "in":
p2 <- MyOp.identity(s)
p2Id <<- p2
else:
p2Info <- Peer.identify()
p2Id <<- p2Info.external_addresses!0
<- p2Id!
p <- closure("in")
on peer2:
p2Id <- closure("on")
<- p, p2Id