2016/02/09

Notes on studying LTN12

Background
Suppose you don’t know what LTN is, LTN stands for Lua technical note.
Below are notes dropped from LTN12 which is the 12th documents talking about filters, sink , source, chain and pump.
Source codes from the author is available here
Interpretations
XXX: My interpretations may or not may correct. Let me know if there are any misunderstands.
Functions accept successive chunks of input, and produce successive chunks of output.

Mathematically speaking,

Suppose f1, f2, ..., fn are filters s.t. F = f1 + f2 + ... + fn
Suppose x1, x2, ... xn are input s.t. X = x1 + x2 + ... + xn

F(x) == f1(x1) + f2(x2) + ... + fn(xn)
  • What is a chain?
A function combines two *similar* functions. By *similar*, I mean same function signatures and return data type.

Mathematically speaking,

Suppose f1, f2, ..., fn are functions s.t. C = f1 + f2 + ... + fn
Suppose x1, x2, ... xn are input s.t. X = x1 + x2 + ... + xn

C(x) == f1(x1) + f2(x2) + ... + fn(xn)
  • What are sources and sinks?
Filters form internal nodes inside an arbitrary *data flow*. *Data* in *data flow* means things shared between producer and consumer while *flow* means the direction of that things which is from *Producer* to *Consumer*

Given picture above, we can interpret *Sources* and *Sinks* as initial and final nodes of the *data flow*.
  • What is pump?
The driving force between internal nodes (filters)
  • Example application?
-- Goal: convert any input text ends with \r\n

-- source.file() returns a kind of filter
-- normalize() returns a kind of filter
-- source.chain() shows how to combine *similar* filters
-- input is a kind of *source*
input = source.chain(source.file(io.stdin), normalize("\r\n"))

-- sink.file() returns a kind of filter
-- output is a kind of *sink*
output = sink.file(io.stdout)

-- Driving force between input and output
-- Or, start the jobs
pump(input, output)

沒有留言:

張貼留言