??goto?????? - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

??goto??????

Description:

Title: 11 Author: 301 Last modified by: dunianabing Created Date: 11/13/1998 8:01:12 AM Document presentation format – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 51
Provided by: 30192
Category:
Tags: goto | radix | tree

less

Transcript and Presenter's Notes

Title: ??goto??????


1
?5? ?????????
  • ??????????????????, ????????????????????
  • ????????????????????
  • ??goto??????
  • ??????????
  • ??????????

2
  • ???????????(Mutability)????(Sequencing)
  • Backus?????????????????????????????????????????
    ????????????

3
5.1 ??????????
  • (1)?????????
  • ?????????????,?????????????????
  • ???? ???????????????????????
  • ????????????

4
???????? int sf_fun(int x) static int
z 0 //???????? return x (z)

sf_fun(3) 3 4 5 6 7
//???????,????????????
5
(2)?????????
  • ?????????, ??, ??????????????????????????????????,
    ???????????????????
  • ???????????????
  • ???????
  • ????, ????????, ???????????????????? ????????????
    ???????, ???????????????????, ????????????
  • ?????????????????????????

6
5.2 ???
  • ?????????????, ??????????, ????????????????
  • ?????????????,????????????????
  • Church?????, ??????????, ??????????,
    ??????????????????????

7
  • ???????????,???????????????????
  • ???????????????? ???????x.E, ??????(?x.E)(a)?
  • ?????????????????(??)???????x.C(C???)?????

8
???????
x ?????????? (?x.((y)x)) ??,
??????? (?z.(y(?z.x))) ??, ??????,
??????? ((?z.(z y))x)
?????? ?x.?y.?z.(x ?x.(u v)w) ?????
9
????????????????????? ???????????????? T
?x.?y.x //???? F ?x.?y.y
//???? 1 ?x.?y.x y //?1 2
?x.?y.x(x y) //?2 zerop ?n.n(?x.F)T
//???? ?zerop??F?T?????????
10
????
??????????, ?????????, ?????????? ????? lt?-???gt
lt??gt ?lt??gt.lt?-???gt
(lt?-???gtlt?-???gt)
(lt?-???gt) lt??gt lt??gt
11
????
  • TRUE ?FALSE?????
  • T ?x.?y.x
  • F ?x.?y.y
  • ???????
  • 0?x.?y.y
  • 1?x.?y.x y
  • 2?x.?y.x(x y)
  • n?x.?y.x(x((x y))
  • n?

12
  • ??????
  • not?z.((zF)T)?z.((z?x.?y.y)(?x.?y.x))
  • and?a.?b.((ab)F) ?a.?b.((ab)?x.?y.y))
  • or ?a.?b.((aT)b) ?a.?b.((a ?x.?y.x)b)

??????????? add ?x.?y.?a.?b.((xa)(ya)b)
multiply ?x.?y.?a.((x(ya))) sqr
?x.?y.(yx) identity ?x.x
//???? succ ?n.(?x.?y.nx(x y))
//???? zerop ?n.n(?x.F)T
?n.n(?z.?x.?y.y)(?x.?y.y) //??
??

13
?34??add 3 4, add 3???3?????4?????7????? (?x.
?y.?a.?b.((x a)(y a) b )) (?p.?q.(p(p(p
q)))(?s.?t.(s(s(s(s t))) ??a.?b.(a(a(a(a(a(a(a
b)))))))
14
?????
???????????????, ?????????????????? ????1???
(succ 1) gt (?n.(?x.?y.n x(x y))1) gt
(?x.?y.1 x(x y)) gt (?x.?y.(?p.?q. p q)
x(x y)) gt (?x.?y.(?q. x q)(x y))
gt (?x.?y.x(x y))2 ?succ?1????(1????),?????n
???n?1??? ???, x??p, (xy)??q, ??????????, ?????,
???2?
15
  • (1)ß??ß???????????????(?x.M N),
    ??????????????,??????????ß???????????????M????????
    ???????,???N/X,M???(?x.M N)???(???)?
  • ????????????????????????,?
  • ((?x.x(?x.(xy)))(zz))
  • gt(zz)(?x.((zz)y)) //??,??x???????
  • gt(zz)(?x.(xy)) //??

16
?5-5 ?????ß??
  • (?n.add n n) 3
  • gt add 3 3 //3??n????n
  • gt 6
  • (?f.?x.f(f x)) succ 7
  • gt ?x.succ (succ x) 7
  • gt succ (succ 7)
  • gt succ (8) 9
  • ?add,3, succ, 7, 9???????
  • ??????????

?ß?????????, ?(?x.xx)(?x.xx),????????,
?????????????? ????????????????
17
  • (2)??????????????x.Fx gt F
  • (3)a??????????????, ?????(???????), ??????????
    ??
  • (?x. (?y.x)) (z y) //(zy)?y?????
  • gt ?y.(zy) //??(zy)?y????, ??!
  • gt (?x.(?w.x))(zy) //?(?y.x)????
  • ?y, ???
  • gt ?w.(zy) // ??!

18
  • (4)????
  • ?????????????????????, ??????????
  • ?????????(?a???)??????????????,???????????
  • ?????????????,
  • ?? x x,(y (?x.z))??????????
  • ??????????, ???????????????????????,
  • ?pred ?n.(subtract n 1)

19
  • (5) ????????????32
  • 32(3)(2)
  • ?x.?y.(y x)(3)(2)
  • gtß(?y.(y 3))(2)
  • gtß((2)3)
  • (?f.?c.f ( f c ) ) (3)
  • gtß?c.(( 3 ( 3 c ) )
  • ?c.(?f.?c.(f(f(f(c)))))(3 c))
  • // ?c????c
  • gta?c.(?f.?z.(f (f (f (z)))))(3 c)
  • gtß?c.(?z.((3 c)((3 c)((3 c)(z)))))
  • // ??3

20
?c.?z.((( ?f.?c.(f(f(f(c)))c)((3c)((3c)(z)))) gta?
c.?z.((( ?f.?w.(f( f(
f(w)))c)((3c)((3c)(z)))) gtß?c.?z.(((?w.(c(c(c(w)))
)((3c)((3c)(z)))) //???????c,???c ?c.?z.(((?w.(c(
c(c(w))))(( ?p.(c(c(c(p)))))((
?q.(c(c(c(q)))))(z)))) gtß?c.?z.(((?w.(c(c(c(w))))(
( ?p.(c(c(c(p)))))(((c(c(c(z)))))) gt
ß?c.?z.(((?w.(c(c(c(w))))((
(c(c(c(c(c(c(z))))))))))) gtß ?c.?z.(c(c(c(c(c(c(c(
c(c(z)))))))))) 9
21
?????
??????????????????????,?????????,?????????,???????
?,????????if_then_else?????if_then_else
?p.?m.?n.p m n,?p?'?'?, ??m???n?????????? ??????
????if_then_else????? (if_then_else) T M N gt
(?p. ?m. ?n. p m n) T M N gt (?m.?n. ( T m n))M
N gt (?m. ?n. (?x.?y.x) m n) M N gt (?m. ?n.
(?y.m) n) M N gt (?m. ?n. m) M N gt (?n. M) N gtM
22
  • if???
  • ?????if-then-else??
  • (if_then_else) E1 E2 E3 if E1 then E2
  • else E3
  • ??E1, E2, E3??????

23
  • Let/where???
  • ???????
  • (?n. multiply n (succ n)) (add i 2 )
  • gt multiply (add i 2) (succ (add i 2))
  • //n ? add i 2?????
  • gt multiply n (succ n) // let n add i 2 in
  • let a b in E (?a. E) b E where ab
  • (?f. E2) (?x.E1) let f ?x.E1 in E2
  • let f x E1 in E2
  • ????f?x.E1??x. ??????f x E1 ? ?
  • sqr ?n. multiply n n //?????????
  • sqr n multiply n n //?????????
  • let????ML. LISP?????, Miranda?where?????????,
    let??E??????????Miranda????where???E??.

24
  • ?????
  • ?????n???p(x1,x2,xn), ???p????
  • let f(x1,x2,xn)E1 in E2
  • let fpE1 in
  • let x1first p in
  • let x2second p in
  • .
  • .
  • .
  • let xnn_th p in E2

25
5.3 ?????????????????
  • 5.3.1 ????
  • ???????????????? ????
  • ???????????
  • 1 ??????????????
  • 2 ??????????
  • 3 ?????????
  • 4 ????????(???????)?

26
????
  • 1?????????(???)??????
  • 2????????????,??????
  • ?????where???????
  • 3??????????????, ????
  • ???????????? ???????
  • ??????? ????????? ??
  • ????????????????????
  • ??????3, ???????????

27
  • 4???????????????????,??????????????????

A
A
B
C
B
C
E
D
F
F
J
I
H
G
28
5.3.2 ?????while_do
  • ?????????????????????? ?????????????,
    ?????????then??, ???????else??,
    ?????????????(else)?

5.3.3 ????
????????????, ??????????(????????????????)
29
5.3.4????????????
?pascal?? cab ssin(c c) ?
write(a,b, c, s) //????????????
//????????? LISP ?? (print (let ((c( a b)))
let ((s (sin ( c c))))
list a b c s )))) //????????
//????????????????? Miranda?? Answere a b
(a b c s ) where
s sin (c c) c ab //????,
??????
30
  • ????????
  • ????????????

Miranda?????? gcd a b gcd (a-b) b, agtb
gcd a (b-a), altb a,
ab LISP????? (define GCD (a b) (cond
(( greaterp a b) (GCD ((diference a b ) b)))
((Lessp a b) (GCD (a (diference b a ))))
( T a )))
31
5.3.5 ????
  • ?????????????
  • ??????????, ?????????(??????)??????????????Mirand
    a???????????
  • ??????????, ??????, ???????, ?????????, ???
    ???????????, ???????, ???????????,
    ??????????????????
  • ??????????????, ?????????????????????????,
    ???????????

32
5.4 ?????Miranda
???Miranda?? Miranda
??? sq n n n sq ?n.
n n zsq x/sq y z/(sq
x)(sq y)
Miranda????????(char??, ???????), ??(bool??,
??True?False)??(num ??, ???????), ??????????,
?????
11.4.1 ????
  • ??(tuple)
  • ?????
  • tree Leaf Integer Node tree tree
    1
  • leaf1 (Leaf 3)
    2
  • tree1 (Node leaf1 (Node (Leaf 17) (Leaf 49)))
    3

33
tree 1
leaf 1
3
3
leaf 1
?2????
17
49
?3????
????????? ??? max_tree ?????????
max_tree (Leaf ldata) ldata
1 max_tree (Node n1 n2) max1, max1 gt
max2 2 max2,
max2 gt max1 3 max1,
otherwise where
max1 (max_tree n1)
4 max2 (max_tree
n2) 5
???? (max_tree leaf1) //????3,
leaf1??? (max_tree tree1) //????49,tree1???
34
?(list)
  • Miranda?????
  • //??
  • 1..n //1?n,???
  • odd_number 1,3,..100 //1?100????,?????????
  • eleven_up 11... //10??, ?????
  • evens 10,12...100 //10??????100,?????????
  • evens_up 12,14... //10???????,
  • week _days Mon,Tue,Wed,Thur,Fri
  • //??????

35
5.4.2 ????? Miranda???????????(?-??/?div?mod)???
??????????????????? L1 L2 //
?L2????L1??? itemList // ??item???List???
List ! n // ??List????n? L1 -- L2 //
??L1???L2?? List //???List??(?)?
36
5.4.3 ????
Miranda????????(equation)? ? ??????????,
?????????? Fibonacci n 1,
n0 1, n1
Fibonacci (n-1)Fibonacci (n-2) ngt1
????????????????, ???otherwise?
37
? ??where????? quadroot a b c error complex
roots,delta lt 0 term1
, delta 0 term1
term2,term1 - term2,
delta gt0 where
delta bb - 4ac
radix sqrt delta term1
-b/(2a) term2 radix /(2a)
38
Miranda????????,??????????,???????, ??????????,
??????????, ????????????, ???????Curry??? ?
??????????? hypotenuse a b sqrt (a a b
b) ??? hypotenuse 3 4 //5 ????
(hypotenuse 3 ) 4 ? f 4 Miranda????
f 4 where f hypotenuse 3 //fsqrt(9
bb)? Curry ???
39
? Miranda????????????? type row_typearray0..9
of Integer function Reduce(functionf(xInteger,y
Integer)Integer
arrow_type)Integer//??f?????? var
sum,kInteger begin sumar0 for k1
to 9 do sumf(sum,ark)
reducesum end function MyOp(sInteger,yInteger
)Integer //?????????? begin
MyOpabs(x)abs(y) end function
MySum(arrow_type)Integer begin
MySumReduce(MyOp,ar) end
40
????? Reduce???????????????????????Miranda???,??3?
????????????????????????????,????????? reduce
f n n
1 reduce f(a x) n f a (reduce x n)
2 ??????????,??reduce??? reduce(num?num?n
um) //????f?????(?
??),?????? ?num
//?????,????num?? ? num
//???????,???num. ? num
//????????num??? 2??(ax)???a???x,??????????????
???1??????? n ?????? n ????
41
5.4.4 ???
?????????????(??)?????? ltZF???gtlt?gtlt??
??gt lt????gtlt???gtlt???gtlt???gt
lt???gtlt??gt?lt?_???gt lt???gtlt?????gt lt?gt
lt?_???gt
42
????? ZF ??? ?? n2
n?2,4,6,8,10 4,8,12,16,20 1 nn
n ?1,2,... 1,4,9,... 2 xy
x? 1..3 y?3,7 4,5,6,8,9,10 3 xy
x ?1..3 y?1..3xgty1,2,4,3,6,9 4
1????????, ??2,4,6,8,10???n??2???2????????????
,3?4???????, 4???????, ??????9???
43
? ?Miranda?????? sort
1 sort (pivotrest) sort
y y ? rest yltpivot 2
pivot 3
sort z z ? rest ygtpivot 4
1?????sort????????????(??????),
?????????1?? ?????sort?????2????????,
?????????, ????pivot?rest??,???????
???????????????????????
44
5.4.5 ???
  • ??????????? ?????, ??????????, ???????,
    ?????????????????????, ??????, ????????????

45
5.5 ?????
  • (1) ??????
  • (2) ??????
  • ?????????????200-1000?????3-5?, ????
  • ????????, ????????????(heap)???, ????????,
    ??????????
  • ???(?LISP)?????????,???????(?ML,
    Miranda)?????????, ??????????????????????????
  • ??????
  • ?????????????
  • ???????, ??????????! ??????

46
(3) ??? ????????????????????????, ??????????,
??????????????????????? ????????????
????????????????????????????? ???????????????????
???????, ???????????????? ???????????????????????
?
47
Haskell ??
Haskell???????,??????????,????????????????????
??????Haskell Brooks Curry,???????????????????????
??????Haskell?,?????????????????,??????????Haskell
???1990??????Miranda????????,??????(Lambda-Calculu
s)????????????????????????????????Haskell???????
???(Lambda)??????????
48
Scheme ??
Scheme ??? Lisp ??????????,???1975?,? MIT ?
Gerald J. Sussman and Guy L. Steele Jr.
??????lisp????,scheme?????????? ?
Scheme???????,????50?,???Common Lisp
???????????,??????????????????????????? Lisp
???????????,????????
49
Clojure ??
Clojure ?????? Java ???? Lisp
??,????????????Java???????????????????????,?????
Java ??????,?????? Lisp ?????
??Lisp??,Clojure????????????,?????????????Lisp????
??,?????????,????Java??????????????????
50
Scala ??
Scala????????????,?????????????,???????JVM????
?????Scala?????,???????????,??Scala???????????????
??? Scala?Java?????????????,?????????????????
?,???C?Scala?????????,???????????????????,C???
????????????????Scala????,?????,???????????????,Sc
ala?????,???Java?????,Scala??????
Write a Comment
User Comments (0)
About PowerShow.com