TeSLa - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

TeSLa

Description:

Dim WithEvents B As New Button() Sub OnClick(sender As Object, e As ... XHTML Literals (1998) ASP-style embedding. Translated to universal DOM representation ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 47
Provided by: erik224
Category:
Tags: tesla | xhtml

less

Transcript and Presenter's Notes

Title: TeSLa


1
research
product
TeSLa
2
Why The _at_! Visual Basic
Imports SySTem.STriNg Module Demo Public Sub
Main() Dim S Join(", ", "Hello",
"World") End Sub End Module
Case insensitive
Class imports
Static class
3
Why The _at_! Visual Basic
Class Dog Public Event Bark()End Class Dim
WithEvents D As New Dog() Sub OnBark() Handles
D.Bark Console.WriteLine("Call 911") End Sub
DeclarativeEvent Handling
"AOP"
4
Why The _at_! Visual Basic
Optional parameters
Function F(X As Integer, _ Optional
Flag As Boolean False) _ As String End
Function F (Flag True, X 4711)
Named arguments
5
Why The _at_! Visual Basic
Class Dog Public Event Bark() Public Default
Property Toys(Name As String) _ As Object
Get End Get Set (Value As
Object) End Set End PropertyEnd
Class
Line continuations
Indexed Properties
6
Why The _at_! Visual Basic
With Statement
Dim D As New Dog() With D .Toys("Bone") New
Bone() .Toys!Cat CatchNeighboursCat()
Console.WriteLine(.Toys("Ball").Color) End With
Late binding
Late binding
With Scope(Power is in the ".")
7
Late Binding
K J3 For I0 To 10 Console.WriteLine(I)Next
Dim X As String 4711 Function F(X) Return
X3End Function
Option Implicit
Implicit Explicit Conversions
Types Optional
8
Relaxed delegates
Dim WithEvents B As New Button()Sub
OnClick(sender As Object, e As EventArgs) _
Handles B.Click End Sub Sub RelaxedOnClick(send
er As Object, e As Object) _ Handles
B.Click End Sub
Can call it ? can handle it
9
Relaxed delegates
Delegate Function F(A As S) As T
Function G(B As P) As Q New F(AddressOf G) ? New
F(Function(A) CType(G(CType(A,P)),T)
Conversion stub
10
Why The _at_! Visual Basic
Extension Methods
ltRuntime.CompilerServices.Extension()gt _ Function
FindName(Source As Object, Name As String) As
Object On Error Resume Next If Source.Name Name
Then Return Source End If Dim Children As
Object Source.Children If Children IsNot
Nothing Then For Each Child As Object In
Children FindName FindName(Child, Name)
If FindName IsNot Nothing Then Return
FindName End If Next End If Return
Nothing End Function
Unstructured Exception Handling
Late binding
"AOP"
11
Late Binding!
Type Rule For Early-BoundMethod Invocation
G - e As S gt eG - a As T gt aSm(T) As R
gt f----------------------------------G -
e.m(a) As R gt f(e,a)
12
Late Binding!
Type Rule For Late-BoundMethod Invocation
G - e As Object gt eG - a As T gt aT lt
Object gt g-----------------------------G -
e.m(a) lt Object gt latecall("m", e, g(a))
13
Late Binding!
Operational Semantics For Late-Bound Call
s.GetType() ? S, t.GetType() ? TSm(T) lt R
gt fR lt Object gt h--------------------------
--latecall(m,s,t) ? h(f(s,t))
VB has multi-methods!
14
Late Binding
Class A Sub F(X As String)
WriteLine("F(String)") End Sub Sub F(X As
Object) WriteLine("F(Object)") End Sub
Sub Main() Dim A New A() Dim S As
Object "Hello" A.F(S) REM Early ?
F(Object) CObj(A).F(S) REM Late ?
F(String) End Sub End Class
Imports System.Console
Type Inference
15
Meta-circular interpreter
E AB Add(E A , E B ) E A.m(B)
Call(E m , E A , E B )
Self interpretation is litmus test for dynamic
language
16
Replace Constants By Variables
G - e lt Object gt eG - a lt T gt aT lt
Object gt f G - m lt String gt
m'-----------------------------------------------
-------G - e.(m)(a) lt Object
gt latecall(m', e, f(a))
Later binding
17
Later Binding
Class A Sub F(X As String)
WriteLine("F(String)") End Sub Sub F(X As
Object) WriteLine("F(Object)") End Sub
Sub Main() Dim A New A() Dim S As
Object "Hello" A.(Console.ReadLine())(S)
End Sub End Class
18
VB as the ultimate scripting language
Static Typing Where PossibleDynamic Typing Where
Necessary
19
Ruby
e 8 9 \ 10 d 4 5 6 7 def
options(a99, ba1) a,bend redirect_to
action gt 'show', id gt 4711
Line continuation
Smart "inference"
Default arguments
Named arguments via hashes
20
LINQ Project monad comprehensions in C VB
VB 9
C 3.0

StandardQueryOperators
DLinq(relational)
XLinq(xml)
LINQ Framework
21
The Origins of LINQ
Swartz, SETL 1970 Burstall and Darlington, NPL
1977 Turner, KRC 1981 . Haskell, Python,
Scala, Write programs using mathematical ZF
set comprehensions syntax. Wadler 1989 List
comprehensions are related to the relational
calculus. Wadler 1992 List comprehensions are a
special case of monad comprehensions.
22
HaskellDb Query Monad (1997)
SELECT X.FirstName, X.LastName FROM Authors AS
X WHERE X.City 'OakLand' oaklands do x
lt- table authors restrict (x!city ..
constant "Oakland") project ( au_fname
x!au_fname , au_lname x!au_lname
)
Query monad
intentional representation for expressions
23
Query Comprensions In C 3.0
var contacts from c in customers where
c.State "WA" select new c.Name, c.Phone
var contacts customers .Where(c
gt c.State "WA") .Select(c gt newc.Name,
c.Phone)
Type inference
Syntactic sugar over standard query operations
?-expression
24
Query Comprensions In Visual Basic 9
Dim Squares From N In Range(0,99) Select
NN Dim Pairs From N In Range(0,9)
From C In "ABCDEFGHIJ" Select N,
C Dim Evens From N In (0,99) Where
N Mod 2 0 Select N Dim ByDigit
From N In (0,99) Group By N Mod 10
Select Key, It
25
In Visual Basic 9
Dim Contacts From C In Customers Where
C.State "WA" Select C.Name, C.Phone Dim
Contacts _ Customers. Where(Function(C)
C.State "WA"). Select(New With .Name
C.Name, .Phone C.Phone )
26
Query Comprensions In Visual Basic 9
Dim MyCDs As IEnumerable(Of _ Title As
String , Artist As String ) _ From
CD In MyMusic Where CD.Genre IsNot Classic
Group By Genre CD.Genre Where Count(CD) gt 10
Select Group(CD.Title, CD.Artist)
Aggregate comprehensions
27
Query Comprehensions
Xs.SelectMany((X) _ F(X).Select((Y)_ New
X,Y))
X
From Y In F(X)
Compiled To Standard Query Operators
X,Y
Joined
28
Query Comprehensions
XYs.OrderBy((XY) _ F(XY.X, XY.Y))
X,Y
Order By F(X,Y)
X,Y
Sorted
29
Query Comprehensions
X,Y
XYs.Where((XY) _ P(XY.X, XY.Y))
Where P(X,Y)
X,Y
Filtered
30
Query Comprehensions
X,Y
projected
Select A F(X,Y), B G(X,Y)
A,B
XYs.Select((XY) _ New A F(XY.X, XY.Y), _
B F(XY.X, XY.Y) )
31
Query Comprehensions
XYs.GroupBy((XY) _ New A G(XY.X, XY.Y), _
B H(XY.X, XY.Y) )
X,Y
Group By A G(X,Y), B H(X,Y)
A,B,
grouped
X,Y
32
Extension Methods
static class Integer static void Times
(this int x, Actionltintgt f) for(var i 0
i lt x i) f(i) 3.Times((x) gt
Console.WriteLine(x)
33
Extension Methods
IEnumerableltCustomergt
var contacts customers .Where(c gt c.State
"WA") .Select(c gt newc.Name,
c.Phone) static class System.Query
public static IEnumerableltTgt WhereltTgt(this
IEnumerableltTgt src, FuncltT, boolgtgt
p)
Extension method for IEnumerableltTgt
34
In Visual Basic 9
Dim Contacts _ Customers.Where(P).Select(R)
Module MyExtensionsltRuntime.CompilerServices.Ex
tension()gt _ Function Where(Of T)( _ Me
As IEnumerable(Of T), _ P As Func(Of T,
Boolean)) _ As IEnumerable(Of T) End
Module
Just CA
35
Expression Trees
TableltCustomergt
var contacts customers .Where(c gt c.State
"WA") .Select(c gt newc.Name,
c.Phone) class TableltTgt IEnumerableltTgt
public TableltTgt Where(Expression
ltFuncltT, boolgtgt p)
Intensional representation of delegate
36
Expression Trees
Convert to expression tree by type
Dim F As Expr Function(X)X3Dim G
F.Compile()Dim Z G(5)
Compile to delegate
Execute
37
Anonymous types,Object initializers
var contacts from c in customers where
c.State "WA" select new c.Name, c.Phone
var Joe new Person Name Joe, Age
42, Address Street 1th St,
City Seattle
Anonymous types
Object Initializers
Initialize RO member
38
In Visual Basic 9
Dim Contacts As IEnumerable(Of _ Name As
String, Phone As Integer From c In
customers _ Where C.State "WA _ Select
c.Name, c.Phone Dim Joe As Person New With
_ .Name Joe, .Age 42, _ Address With
_ .Street 1th St, .City Seattle
Anonymous types
Syntax new
39
Nullable
Dim S1 As String? Nothing Dim S2 As String?
Hello Dim S3 S1S2
Null propagating
In VB Nothing is default
40
XML DOM
Dim PO As New XmlDocument Dim purchaseOrder As
XmlElement _ PO.CreateElement("purchaseOrder"
) PO.AppendChild(purchaseOrder) Dim orderDate As
XmlAttribute PO.CreateAttribute("orderDate"
) orderDate.Value "1999-10-20" purchaseOrder.Att
ributes.Append(orderDate) Dim shipTo As
XmlElement PO.CreateElement("shipTo") purchaseOr
der.AppendChild(shipTo) Dim country As
XmlAttribute PO.CreateAttribute("country") count
ry.Value "US" shipTo.Attributes.Append(country)
What does this program do?
41
XLinq API
Functional (expression-based) construction
Dim Item _New XElement("item", _ New
XAttribute("partNum", "926-AA"), _ New
XElement("productName", "), _ New
XElement("quantity", 1), _ New
XElement("price", 39.98), _ New
XElement("shipDate", "1999-05-21"))))
Context-free (no document scope)
Simple
42
Haskell Server Pages XHTML Literals (1998)
table TABLE table ltTABLE border"1"gt
lt mkRows cells gt lt/TABLEgt cells
(Int,Int) cells (x,y) x lt- 1..16
y lt- 1..16 mkRows (Int,Int) -gt
TR mkRows map \cs -gt ltTRgtlt mkColums cs
gtlt/TRgt mkColumns (Int,Int) -gt
TD mkColums map \c -gt ltTD bgcolor(color
c)gtlt c gtlt/TDgt
Translated to universal DOM representation
ASP-style embedding
43
Dim PO ltpurchaseOrder orderDate(System.DateTime
.Today)gt ltshipTo country"US"gt
ltnamegtAlice Smithlt/namegt ltstreetgt123 Maple
Streetlt/streetgt ltcitygtMill Valleylt/citygt
ltstategtCAlt/stategt ltzipgt90952lt/zipgt
lt/shipTogt lt BillTo gt ltitemsgt
lt Select ltitem partNumlt O.PartID
gtgt ltproductNamegt lt O.Product
gt lt/productNamegt
ltquantitygt lt O.Quantity gt
lt/quantitygt ltpricegt lt O.Price
gt lt/pricegt lt/itemgt From O In
Orders Where O.Name "Robert Smith"
gt lt/itemsgt lt/purchaseOrdergt
Translated to XLinq constructor calls
ASP-style embedding
Includes full namespace support
44
Late binding over XML
Child axis BillTo.ltstreetgt ?
BillTo.Elements(street) Attribute axis
BillTo._at_country ? BillTo.Attributes(country)
Descendants axis PO...ltitemgt ?
PO.Descendants(item)
45
Tesla
  • Tools IDE
  • Type system Language extensions
  • Runtime Library support
  • Transactions everywhere

46
Conclusion
VB IsNot C VB static typing where possible,
dynamic typing where necessary.
Write a Comment
User Comments (0)
About PowerShow.com