Основные элементы языка программирования Icon: Учебное пособие

  • View
    220

  • Download
    7

Embed Size (px)

Transcript

  • . ..

    ..

    Icon

    - 2004

    2

    519.682 32.973-01873

    188

    -

    :

    . .-. , .. , . .-. , ..

    .. 188 Icon:

    . : - , 2004. 55 . ISBN 5-7779-0523-4 ,

    , -- Icon. - Thomas W. Christopher Icon Programming Language Hand-book, . ; .

    .

    519.682 32.973-01873

    .., 2004 ISBN 5-7779-0523-4 , 2004

  • 3

    ......................................................................................................... 5 1. , , ............................................ 11 2.

    2.1. Every, to, every do............................................................................. 13 2.2. !e ................................................................. 15 2.3. & and ............................................................................. 15 2.4. Backtracking .................................................................... 15 2.5. &null ............................................................................ 16 2.6. | .................................................................................. 16 2.7. .

    .................................................................................... 17 2.8. Coevaluation ..................................................... 17 2.9. ............... 18

    3. 3.1. if......................................................................................................... 19 3.2. case of ................................................................................................ 19 3.3. while do ............................................................................................. 19 3.4. until do ............................................................................................... 20 3.5. repeat . ............................................ 20

    4. 4.1. ............................................... 21 4.2. ? any ..................... 21

    5. ..................................................................................................... 22 5.1. ......................................................................................... 22 5.2. ............................................... 23 5.3. ............................................... 23 5.4. ......................................................... 24 5.5. ......................... 27

    6. 6.1. ............................................................................. 29 6.2. ........................... 29 6.3. ..................................................................... 29 6.4. .................................................. 30 6.5. ........................................................ 30

    7. ................................................................................................... 31 7.1. .......................................................................... 32 7.3. ............................................................ 33

    8. ............................................................................................... 34 9. ....................................................................................................... 35

    4

    10. 10.1. ............................................................................. 36 10.2. ...................................................................... 38

    11. ..................................... 39 12. coexpression .......................................... 41 13.

    13.1. ............................................................................... 44 13.2. ................................................ 46 13.3. ........................................................................................... 47 13.4. ............................................................................... 48 13.5. ...................................................... 50

    .................................................................................................. 51 ........................................................ 52 .......................................................... 54

  • 5

    , -

    [1], . : - - . , , , , - . - , - , , .

    Icon, , - SNOBOL, 60-. , iconoclastic () [1], .

    Icon. -, , - . Icon . , , - -, . . , , , - .

    , - Icon , - . , , -. Christopher [2] : Icon' , -

    6

    Icon' . - , .

    : procedure main() L:=["mmm","nnnnn","oooooo"] # every writes(" ",! L) end : mmm nnnnn oooooo Icon ( -

    , ). , . .

    Icon : - , , , 2 (- ), . - -. , . - . . - . . (- (?)).

    Icon' (first class values, - , ).

    Icon (co-expression) , , - .

    Icon . Icon - -

    . ,

    Icon' , . : Prolog'?! ( Icon ( !) -

  • 7

    (exe ), - PDC Visual Prolog.)

    : procedure main() # f:=open("x.txt","r")|stop("cannot open x.txt") f2:=open("y.txt","w")|stop("cannot open y.txt") # while s:=read(f) do write(f2,s) close(f) close(f2) end Icon' -

    every write(f2,!f) link graphics procedure main() # : WOpen("size=400,300") | stop("can't open window") Font("Times New Roman,18") # L:=[" 1"," 2"," 3"] case SelectDialog(" ",L,L[1]) of { "Okey": { GotoRC(1,1) WWrite(dialog_value) # WDone() } "Cancel": {} } end , , Icon',

    (- ). Cristophera [2, . 41]:

    8

    "The vertical bar, "|", read "or", looks like a binary operator but does not behave like one".

    : "\" "\x" "|(z to y)\x" ( , x, - ).

    Icon . f:=open(__,rt)

    icon_prog.exe __ procedure main(args)) f:=open(args[1],rt) . end , -

    .

    , -:

    allRus:=''

    : allLetters:= &ascii++allRus ..

    Icon ( - ). , . - . .

    : * / % (5%2=1) + -

  • 9

    , (*), - , .

    , http://www.cs.arizona.edu/icon. - Icon ( !). ( .icn) .

    , icn-, -:

    wicont c .icn : wicont .icn icn- procedure main() -

    link : link .icn link .icn . procedure main() end procedure p1() end procedure pn() end pdf-

    http://www.cs.arizona.edu/icon/books.htm. - -, . [2], : online- Icon Programming Language Handbook ( pdf-) Icon

    10

    Idol (- Icon. ..), - . -, "" , - - .

  • 11

    1. , ,

    , , Icon . - , (;). :

    every {writes(" ",1 to 5);writes(" ",6 to 10)} every { writes(" ",1 to 5) writes(" ",6 to 10) }

    . , , if {} then {} else .

    [] , , (L[3] ). coavaluation. - procedure, main(...), (p1,...,pn) .

    "end". . - .

    , . , - (naMe name, Name ).

    local , - - (local x,y).

    static , - - (static x,y).

    12

    global , (global x,y).

    procedure -.

    record () , (record r(x,y,z)).

    link , .

    invocable - - ("f"(x)).

    global, record, link, invocable ( ), - .

    , , Christopher', - e ei, i , .

  • 13

    2.

    ( ), - . -, , :

    -, - ;

    -, , -, , .

    . - , - . , . , . , , , , p:

    p:-fact1(_,_,X,_),fact2(_,Y,_), X

  • 15

    2.2. !e

    e , !e , - .

    : L:=[1,2];every writes(" ",!L).#: 1 2 s:="cat";every writes(" ",!s).#: c a t , : every writes(" ",5 to 6)+(10 to 20)) 15 25 16 26 2.3. & and

    e1&e2

    . every i:=|seq(1,2)\3 & j:=|seq(2,2)\3 & i~= j & writes(" ",i+j) : 3 5 7 5 7 9 7 9 11 2.4. Backtracking

    , , . , - 12345 ( write("12345")): every writes (1 to 5).

    , Icon &fail, -.

    write (1 to 5) + &fail. write("\n","O'key") +

    , . . "-".

    : procedure main() S:="tak pit hochetsa, chto perenochevat negde\n" (sim:=!S, writes(sim),sim=="\n") write("O'key")

    16

    end : S O'key .

    , - (sim:=!S) -. S, O'key.

    2.5. &null

    \ , -, &null, / , . . -

    if \x & \y then...". x , if

    ~x, if /x . 2.6. |

    |, , , . -:

    e1 | e2 e1, e2.

    procedure main() local x,y,z L:=["Vera","Manja","Tanja"] x:=1 if (\x | \y) then z:=10 (writes(" ",!L) | write(" ",z)) every (writes(" ",!L) | write(" ",z)) #while (writes(" ",!L)) | write(" ",z)) end : Vera Vera Manja Tanja 10 end,

    Vera.

  • 17

    2.7. . -

    |e e, - .

    , - : |e\n.

    : every |(writes(7))\7 7777777, , every (writes(|7\7)), every i:=1 to 7 do writes(7). seq()

    seq() 1,2,3,............. seq(i) i,i+1,i+2........ seq(i,j) i+j,i+2j,i+3j.. every writes(" ",seq(2,2)\5) 2 4 6 8 10 every writes(" ",seq(2,2))\5 2.8. Coevaluation

    :

    e0(e1,e2,...,eN),

    e0 , -, , , - , - . .

    : (e1,e2,...,eN) N(e1,e2,...,eN) (e1&e2&...&eN). : procedure main() K:=1 S:="qwertyu" ever