RosettaCodeData/Task/Function-composition/Transd/function-composition.transd

30 lines
952 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#lang transd
MainModule: {
// Make a short alias for a function type that takes a string and
// returns a string. Call it 'Shader'.
Shader: typealias(Lambda<String String>),
// 'composer' function takes two Shaders, combines them into
// a single Shader, which is a capturing closure, аnd returns
// this closure to the caller.
// [[f1,f2]] is a list of captured variables
composer: (λ f1 Shader() f2 Shader()
(ret Shader(λ[[f1,f2]] s String() (exec f1 (exec f2 s))))),
_start: (λ
// create a combined shader as a local variable 'render'
locals: render (composer
Shader(λ s String() (ret (toupper s)))
Shader(λ s String() (ret (+ s "!"))))
// call this combined shader as a usual shader with passing
// a string to it, аnd receiving from it the combined result of
// its two captured shaders
(textout (exec render "hello")))
}