DAC.BY NE - i hie L.S.Baraz, E.V.Boravikov, N.G.Glagoleva, P.A.Zemtsav, E.V.Nalimov, V.A.Tsikoza RAPIRA PROGRAMMING LANGUAGE 4) @ GLIMPSE THROUGH EXAMPLES « 24.99.87 ) The Rapire programming languageli, p.199-2053 was designed by G.A.Zvenigorodsky as a bridge from the educational language Robicti2 tp the standard programming languages. That version of the language was implemented as an interpreter within the programming system "Shkolnitsa" ("Schoolgirl") an the “agat“ computer £23. ‘The experience in its usage has enabled to begin a new vergion. A programming system for it is being implemented on “Yamaha” and “Korvet" computers. This article provides an overview of the new version. The examples of small programs and their work show the mein features of Rapira. (The mark “# indicates program output). In fact, the examples illustrate mainly object processing. The statements of Rapira are those typical for the procedure-oriented languages, therefore they are introduced almost without comments. (A comment in Rapira begins with 7\7 symbol and spreads upto to the end of the line. The comments below, explaining the algorithm, but not the language features are marked with °m7). Dialog with Rapira system In fact, there are no Rapira programs when working witn the system. There are definitions of procedures and functions and there are single statements being executed immediately in current environment. The current environment is initialized when system starts and may be saved at any mament. In particular, it includes ail the global variables with their values. Lexics Rapira has Russian lesics. But two more variants were developed: Engliah and Moldavian. Here the English variant for new Rapira version is described with the Russian equivalents for keywords and standard names. Objects and operations Objects: logical (yes, no), integer and real cumbers, texts, sequences, the empty obsect (empty). Procedures, functions, modules and devices ere also objects. For all objects operations Legical: yes, no. Logical operations: and, or, not. and /= are defined. Number ss 125 \ integer 330.84 \ real 1.98-8 \ real Numeric aperations: + and — (unary: and binary), 4, XX (exponentiation), // and /% (integer division and remainder - for integer numbers), >, <, 2=, <=. oe Example 1. fun PRIME (ND Is N @ prime number 7 if NK2 then return no \ return a function velue #4 for M from Z to sqrtiNi+9.5 do if N /4M = @ then return no fi od return yes end eutputs PRIME (2093) © yes Texts: “Could we have some butter for The Rayal slice of bread?” \ empty text 2e2-11" Operations for texte: ® (length, + (concatenation), % (multiplication by non-negative integer), £2 (select a symbol in the text), [13 (subtext slice). prac FRAME (ND \@ output 2 frame: Nox N output: "a" EN \ eeeee repeat (N-2) do outputs "8" +" END) + \ ee od output: | "@" EN \ eawee end call FRAME (5) © saeee oe @ ee 6 oe @ * aacee Example 3. proc VICE_VERSA Q \@ output reversed text output: "Enter a text ” \a prompt for input input text: PHRASE \ PHRASE will be = “case” REVERSED:= "" \ empty text for K to #PHRASE do \ from 1 \ # cas: =a REVERSED:= PHRASECK] + REVERSED [23 = "a" oa gutput: REVERSED end cali VICE_VERSAG © Enter a text case esac -3 Example 4. proc TEXT_BY_WORDS (PHRASE? Ma output text by words PHRASE:= PHRASE + " Ma - that ts for MB last word processing while PHRASE /= "" do t= index (" ", PHRASE \ first entry number \" “in PHRASE (ar @) af K /= 1 then output: PHRASEC: K-12 \ “ab ed e"f:27 = “ab" PHRASELIC#L 2 1 \ “ab cd e"f4:3 = “ed e* od end So “abcd e"f4:52 = “ed TEXT_BY_woORDS: 2--I711 go and tell The cow Now Before she goes to bed. 2011 ga and tell The cow Now Before she goes Seer eereoes 7, Ly ’ "i", "one 441, 4, 46, 7, 9 >, 1, 448, 70, 99 OP Sequence is an ordered set of objects. Any Rapira abject may be an element of a sequence (including the other sequence) . The sequence construct operation 4 » builds a sequence. Sequential operations: (length), + (concatenation), % (multiplication by non-negative integer), (3 {element select an the sequence). [21 (subsequence slice). Example 5. fun TEXT_TO_WORDS (PHRASE) A divide text to words PHRASE:= PHRASE +" " WORDS:= 4 > \ empty sequence while PHRASE /= "" do Kr= index(" “, PHRASE? if K /= 1 then WORDS:= WORDS + 4 PHRASEL:K-17 > \ 4 "ab" ee #4 \ 4 "ab", "cd", PHRASE: = PHRASELK+1: 7 od return WORDS end DE TF 4 WORDS_SEGUENCE:= TEXT_TO_WORDS ("...many people nowadays Like marmelade Instead. ") output: WORDS_SEQUENCE ¢ 4 %...many", "people", "nowadays", "Like", "marmelade", “Ins @ tead.” > Example 6. Proc SORT ( <=NUMBERS > Md sort @ sequence of numbers \ <=NUMBERS ~ in-out-parameter 4> NUMBERS /= 4% ao = NUMBERS(E13; IND:= 1 \ 45, 31, Botr2 = 5 for K from 2 to #NUMBERS do N45, 31,8> = if NUMBERSEKI Labs anes ase NUMBERSC IND: 1NDI:= 4 > \ other ways od \ NUMBERS i= NUMBERSL:1ND-11 + NUMBERSCIND+i:7 NUMBERS: = NEW \ 45, 31, 990522 = 45, 31> \ 45, 31, @oC213 = 451, o> \ 45, 31, @pct212 = «5p end DAYS:= 45 repeat 19 do DAYSi= DAYS + ¢ int_rana(Sip > ad \ int_rand - integer random number generator output: DAYS % 422, 1, 26, 3, 26, 17, 31, 6, 29, 24% SORT (<=DAYS) \ <=DAYS - actual in-out-parameter output: DAYS 41, 3, 6, 17, 22, 24, 26, 26, 29, 51> Example 7. fun SIEVE (N) MM prime numbers from 2 to N PRIME:= 4 yes > * N \ dyes eos \ 4 yes, yes, yes, yes, yes P for K fram 2 to sqrt (N+0.5 do if PRIMELKI then for J from K+K to M step K do PRIMECJI:= no \ 4 yes, yes, yes,no,yes » ad fi od PRIME NUMBERS: = <> for K from 2 to N do if PRIMED] then \ 4 yes, yes, yes, no, yes >14) \ = no PRIME_NUMBERS: = PRIME_NUMBERS + «xk» \ 42, 3h + 45> = ft \ 12,3, 3 od return PRIME_NUMBERS end 42,3, 5 AIT NG outputs SIEVE (S) 2 42,3, 5% output: SIEVE (290) 42, 3, 5, 7, 11, 13, 17, 19, 23, 29, St, 37, 41, 45, 47, 53 + 59, 61, 67, 71, 73, 79, 83, 89, 97, 191, 105, 107, 109, 11 3, 227, 131, 137, 159, 149, isi, 157, 163, 147, 173, 179, 18 1, 191, 195, 197, 199 > eeee Variables Any object may act as the value of 4 variable. Example 8. Game: # person thinks of an animals computer tries to guess it asking questions, for ‘yes’ and ‘no’ answers only. [f the animal is unknown, computer asks the help thus enriching its knowledg Algoritha. The following tree represents knowledge: questian 150% yess \ no ’ N question abi NS \ yes / 0 \ ne animal wow animal .. animal Computer asks a question and chooses the left or the right subtree depending on the answer; and it does so until it reach a leaf with an animal name: a animal Then computer asks, if this animal is thougnt of. If not, computer gives up, asks for that animal and)s question to distinguish them beth. As a result, the leaf is replaced by the subtree: question or question yes / \ 00 yes 7 \ no ea rN animal asked asked animal animal animal Realization. The tree is represented by the sequence KNOWLEDGE 4 question, subtree for ‘yes’, subtree for ’no’ > Each subtree is a similar sequence or a text (animals name). When subtree is chasing, the ATTEMPT variable value is @ sequence or a text, depending upon the descend depth. Lb -720 proc ANIMALS ( ¢=KNOWLEDGE ) i game: computer gues: Ma an animal cutput: KNOWLEDGEEL2, “(yes,no)" \— ask a question input: ANSWER \ input of an object af ANSWER then Nee 2 else a= 3 4 ATTEMPT: = KNOWLEDGELNI \a@ reduction variants if is_seq(ATTEMPT) then \i there is a choice stii1 ANIMALS (<=ATTEMPT) else \@ one animal left qutput: “Is it a “, ATTEMPT, "?(yes,no)” input: ANSWER if ANSWER then \B animal is guessed output: “I?ve guessed!” else AM the animal is unknown \l computer enriches its knowledge output: “I give up. What animal are you thinking of ?* input text: BEAST qutput: “Type in a question to disitinguish’ qutput: “a “, BEAST, “ and a ", ATTEMPT, input text: QUESTION “What will be an answer for a", BEAST, “7* ANSWER ATTEMPT: = 4 GUESTION, BEAST, ATTEMPT > else ATTEMPT:= 4 QUESTION, ATTEMPT, BEAST > + #1 fa KNOWLEDGEDNI:= ATTEMPT end PLL_ANIMALS:= 4 “Does it live in water?", “fish”, “ostrich” atin (<=ALL_ANIMALS) ed Does it Live in water?(yes, no) a'Ta tt @ ostrich?tyea,no) 4° give up. What animal are you thinking of7 turtle @ Type in 2 question te disitinguish * 2 turtle and a ostrich: Has it wings? @ What will be an enswer for a turtie? no # Does it live in water?iyes,no) ng @ Has it wings?(yes.nc) yes LE -12F -7- @ Is it 4 ostrich? (yes,na? ne #1 give up. What animal are you thinking of? parrot * Type in a question to disitinguish a parrot and a ostrich: Can it fly? @ wat Will be an answer for a parrot? yas @ Does it live in water? (yes,na) yes @ Is it 2 fish?tyes,nod yes + I've quessed! writing @ variable you may use slices and selections: KNOWLEDGECNI:= ATTEMPT \ see Example & Example 9, Proc REPLACE ( <=WHERE, =>WHAT, =>BY_WHAT ) \a replacement in a text \ <=WHERE - in-out-parameter, \ =°WHAT, =>BY_WHAT ~ in-parameters we do \ endless loop Kr index WiMAT, WHERE cnr) MM search for next pattern if kK = @ then exit \ Toop exit 4 Ki= NeK-1 WHERE CK: Ke#WHAT—122= BY_WHAT replace a pattern MB by the new text K + #BY_WHAT od end FAIRYTAIL:= “Somebody said," + 1f + *" And then he said," + 1f + """Oh,deary me!" + le + ‘Samebody sobbed, “"Oh,deary me!""" + 1f + ‘And went back to bed. REPLACE (<=FAIRYTAIL, =>"Somebody", =>"The King") \ 4FAIRYTAIL - actual in-out-parameter \ =>"Somebody", =>"The King" ~ \ actual in-parameters output: FAIRYTAIL The King said, “Bother |" And then he said, ‘Oh.deary me The King sobbed, "Oh,deary me!” And went back to bed. aorees BEM? 2 Bue Statements Statements: assignment, procedure call, conditional, cases, leops, output, input, loop exit, return from procedure or function. Almost all statements were used in the examples above. One more examples Example 18. proc GAME 0 MM guessing numbers extern: GAME_START, YOUR TURN, MY_TURN, WRONG intern: RIDDLE, MIN, MAX, YOU_GUESSED, 1_GUESSED outputs “Wha'll guess First?* GAME_START © do output: “Your turns"; YOUR TURN(? output: “My turn." MY_TURNO case \ select a true condition when YUU_GUESSED and 1_GUESSED: output: “Nobody won when YOU_GUESSED: qutput: “You won!” when [_GUESSED: output: "I wont esac if YOU_GUESSED or I GUESSED then return \ precedure return ft until WRONG C \ end of leap if \ WRONGO) = yea output: “You've missed somewhere: " gutput: “I don’t want to play anymore. end proc GAME _START © extern: RIDDLE, MIN, MAX, YOU_GUESSED, 1_GUESSED output: “Think of a number from 1 ta 1999" output: “and try to guess mine" RIDDLE t= int_rand (1900) MIN r= oD MAX r= 1901 YOU_GUESSED := no IGUESSED t= no end proc YOUR_TURN © extern: RIDDLE, YOU_GUESSED ATTEMPT ATTEMPT when ATTEMPT >RIDDLE: cutut: "My number is less!” when ATTEMPT (riddle>". ATTEMPT, "), < friddle<", ATTEMPT, =)" input text: ANSWER ANSWER_CORRECT:= yes case ANSWER \ select an abject when " MIN i ATTEMPT when MAX 2= ATTEMPT when “=": I _SUESBED:= yes else @NSWER_CORRECT:= no output: "You did a mistake" esac until ANSWER CORRECT end fun WRONG © extern: MAX, MIN return MINCI=MAK end GAME (> @ Who’ll guess first? ¢ Think of a number from 1 to 1908 @ and try ta guess mine ® Your turns 312 * My nuaber is less! © My turn. eis it 5907 * Answers: =, > (riddie> 300), < (riddle< SBD) < * Your turn: 256 + My number is greater! @ My turn. eis it 2507 @ Answers: =, > (riddle> Za), < (riddle< 258) « © Your turns 384 My turn. @Is it 1257 @ Answers: =, > (riddle> 125), ¢ (riddles 125) > # You won! Frocedures and functions @11 the uniocai names of procedure (function) should be mentioned an the “extern” list. (Local names may be mentioned eptionally in the “intern™ list). Names that are used in a LIE 1°46 procedure are known aleo in all procedures called from it (if they are marked as “extern there), because the search of external names is being held dynamically through the chain of calls (see Example 19). Procedure parameters: an- =>wHar \ see Example 9 PHRASE \ see Example 4 arrow => is optional) in-out-1 <=WHERE \ see Example <=KNOWLEDBE \ see Example 8 Functions may have in-parameters only. Modules and devices Means of modules and devices planned: — connecting a module enlarges the list of standard nay (including standard procedures and functions names). — connecting a module enlarges the set of simple statements. - a device is a special form af module. A device may be communicated with by means of input and output: output >>printer: “This text - to printer” Input/output statements may contain mode specifications: input text: QUESTION \ see Example & “text” is a keyword for the KEYBOARD device. References 1. Seenropoacki® PLA. Nepaue yponn sporparMvposanna/ Noa pea. A.D. Epwora.~ M.rHayna,i985.~ 268 c.~ (B-4Ka “KmanT". Buin. aL. 2. Tporpanmian cucrena “likankuua” Wee PeARHsuHA Ha nePcO HaALHOM SEM/P.A. BpermropoackHi Map. // M¥KPOnPOuRCCOPHIE cpenctea 4 cuctem.— 1984.- N 1.- c.50-5S. ELE 12> B) RAPIRA. FORMAL LANGUAGE SPECIFICATION ‘ modules, devices and exception handling excluded > > SYNTAX ( 24.09.87 CHARACTER SET: - letter: = digits; - special chara Ee Ay AOR, Mie ates Meeker Lr Cine hie ae cs mi ee ete oo as = extra characters. SEPARATOR = +1= ( space ss= 7° 7) ( carriage return s2= 547 > 5 ( comment #s= "\* { character™ > "#7 > LEXEME i= specsymbol { keyword } name t unsigned int i unsigned real : text specsymbol 23= oe eo Le wee oa » Ce a | oe ee ee keyword ri \ In the Russian variant: Yon \ muzop \ pusop \ unxa- No nmase No xowen \ ace exit \. pexoa extern No ayxne fi \ sce for \ aaa from \ er fun \ ovr if \ ecan input \ spon intern \ cron nif \ ene not \ ne od YK or \ nan putput \ memon proc Xo npou repeat \ noptor return \ sosspar step \ war text \ recta ~ except > 4" AC VE - 32 - then \ ora to \ aa until \ su ag when So onpe while \ none name letter € letter | i digit > int gree y 2 unsigned_int unsigned int digit ¢ digit > real fC # 4 =" 0 unsigned_real unsigned real @igit ¢ digit > digit € digit } C ‘e’ ant 3 ¢ tet int > text eC character** 1 CONDITION ::= EXPRESSION expr_a ¢ ( “and? expra t= C *mote 3 expr_b re es ee od Ltyet > expr_b 3 expr_o i= reg a expr_e CC eG Fy ee? a Se expric ? expec ri tres (name + text | unsigned int ¢ unsigned real | procedure ! function | (seg_construct i= ° 4 £ lexpr 1 PO) t °C expression ")° > { ( index expr ie= °C" llexpr "3" t °° C expression 3 *2° { expression 2 + actual_fun_param ? Tlexpr iss axpression ( ’,’ expression } except *"? and > #7 LOO 12 F- actual _fun_param i: oan C r—3? 2 expression © ',° £ '=3? 7 expression > 37) PROCEDURE 1 ‘proc’ C name 2 ree f cme toy bes € declarations 3 2 name "<= Tname 339° stmts ena? si eee dk ey declarations © fextern’ 727 name © 7,% name> 5 E ‘intern? 72" name ¢ 737 name> 33 43 5 « ttatern? name < name} 35 { ’extern™ name ¢ name } 3303) FUNCTION + fun’ C name 2 rE e { *=>' J name ',7 f=? Dname 239" gp { dectarations I stmts vend” DIALOG_UNIT := ( statement | routine definition > 35 stmts 13 { statement 33 3 routine_definition :1= ¢ procedure | function ) STATEMENT ( Cskipee= 77 ot assignment | call afi case oop output i input ( Loop_enit s2= ‘exatt 1 ( proclreturn r= "return? > + ( fun_return f:= "return? expression > > assignment ( variable i= name ¢ index_expr >) *:=" expression call ( 'call? expression { name ) actual _prot_param actual _prac_param : brome: ( "<=" variable + £ 7=3? 2 expression } ty) 0 tee" "variable. ¢ € =>" J expression )» } 37)" 216 - lek wire afs= 718" condition "then? stats t ‘else’ stmts 1 ae case i= ¢ ‘case’ expression C twhen’ expression ¢ '," expression > “2° stmta } ' > case” ( ‘when? condition stmts > > £ ‘else’ stats 1 Pepac’ loop CC far’ name { ‘from’ expression 1 C ’to” expression 3 { ‘step’ expression 1 5 ‘repeat’ expression 23} qk "while? condition 3 rage ste < Tod? } until’ condition > outeut’ © ‘nif a Ctr? expression (7, expression > J variable ¢°,’ variable > Context restrictions: “Loop_exit" statement may appear in loops only; roc_return" statement may appear in procedures anys - “fun_return” statement may appear in functions onlys - procedures and functions: the procedure (function) name and all the names in ‘extern’, “intern’ and parameter lists must be different; - the routine name in “routine_definition™ obligatory (see "DIALOG_UNIT"). = 5= SEMANTICS ( 24.09.87 ) NAMES AND VARIABLES. ny language object may act as a variable value. There exist standard names isee below). See procedures for names scoping rule. If a name is not standard in the given scope and has not been assigned to, then it has an empty value (the ‘empty” object as a value? DBJECTS. object: bb yect_venctation: empty empty” t logical yes’ 1 ?no" : procedure procedure om syntax #/ ft function function ed syntax %/ 1 integer ant 1 unsigned_int 0% see syntax x/ i real real? unsigned_real 7% see syntax text text 2% see syntax sequence "ee ob ject_denatation t object _denotation } 3 Text. represents °"' in the text denatation. Sequence. Sequence is an ordered set of arbitrary objects. Frocedures and functions. Procedure (function) name is local inside the procedure (function). Parameters ~ an- £ ?=>7 2 name and in-out tom name Functions have in-parameters only. Names declaration: undeclared non-standard name is considered to be local ("intern"). Names scoping rule: in the dynamic order of calls, Functions may be simulated by procedures (not regarded here). OPERATION PRIORITIES ( descending ): 4h 0) £2 £33 ¢ function call a ed MT th + - (unary and binary? >< om ke “ers nat and er A6-13 0 ~ 16 STATEMENTS AND OPERATIONS. Ze Bae fe fae Or ke My By My x” @Xpressions - name - variable - statements BASIG SUBSET: Operations: Po...) ~ pots function - function call. tee - sequence constructor . Rk - k 4s text or sequence - length. kK fad —-k is text or sequence a is integer 1 <= a <= fk. = selection. result: a-th sequence element (a-th character in text). ae b a, > are numbers ~ exponentiation. b is reals 2 X€b = exp(inta) ¥ bP b is integer: see partial simulation. a%6 - a, b are numbers; ais text or sequence, b is integer: b is text or sequence, a is integer ~ multiplication. multiply by integer see partial simlation. a7 b 4, b are numbers = division. results a, b are integers: integer or real, otherwise: real. -a - a is number - negated value. a+b - a, b are numbers; a, b are textes a, b are sequences =~ numbers addition, sequence and text concatenation. a> = 4, b are qumbers - (yes/no), a=b - a, b are any objects - if a,b are sequences - se partial simulation. Statements: i= 4 16 any abject — assign the value pf x to i. call pc 3) - p is procedure - procedure call. if then S f2 ~ f is logical - conditional statement. outputr - output of objects: object denotations are displayed at the screen (except texts, which are displayed unquoted) . output nits... - output with no line feed (temporary here: dye to device. LL6- 734 input: anput of objects: object denotations are input from the keyboard. input texts ... - unquoted text input (temporary here: due to device). return return from procedure. return x - 4 1s any abyect ~ return the value of function. ‘SIMALATION: Simulating constructions give an error for illegal arguments not later than necessary. All the names written with capital letters are usec as metesymbols for simulation of the constructions being defined. Also used. ERROR procedure (it could have p. error); standard functions 1S_INT, - pseudo-atatements "PROTECT name" (i.e. to prevent assignment te the name) and “UNPROTECT name", needed for FOR-loop simulation. ameter: which PARTIAL SIMULATION: 1) sequence equivalence: k=h = fun SEG_EQUIV «Kk, HD af 8K /= #H then return no fi for IND to #k do if KLIND] /= HEIND3 then \ recursive point return no 4 og return yes end te, > 2) multiplication by integer (for text or sequence non-negative number 1s required): axb fun MULT_BY_INT (AA, BB) if is_int(Aa) then A; Br= BB BB; Br= AA tat (BE) is_real (B) isltext (B) is_seq(B) L46~ $32. if A>=@ then return RES else return -RES \ for text and A \ sequence: error end fa, bd 3) exponentiation ta integer power a tb = fun EXP_TO_INT (A, B? if €=@ and Be@ then error #1 if B>@ then N= B else -B fi Pist while Re do if M/Z2 /= @ then Pim PxA fi Arm AKA Nie N//2 od 4# B2® then return P else return 1/P #4 end fa, be SIMULATED: Statements: 1) Procedure calls Ace Weak ae weed \ i 4s procedure 2) Conditionals if # then S1 else 82 #4 = call proc IF_THEN_ELSE (F) extern? ... \ all the names trom 1,52,F af F then st return #1 82 end a \ is logical 3) Case: case 5a 52 Sn else so LE 233 oa a #1 then 82 @lse if f2 then S2 elsi if fn then Sn els 86 Fit ince 4a case 6 when bis Si when b2: S2 when bn: Sn eise so esac = call proc CASE_EXPR tay extern \ all the names trom Si,pi,a if & = bi then St else if A = bz then S2 else ... if A = bn then Sn else 36 fi fa fi end fad \ a is any obsect bz: 81 case = when bi: S12 esac Operations: 4) not fF . fun LOG_NOT (F) if F then return yes else return no #4 end a fun LOG_AND ¢ ) extern! if not # then > f ana g else if g then else #1 41 end \ all the names from f,9 return no return yes return no \ #,9 are logical Ae 134 = 2@- © forg = fun LOG_OR «5 extern: ... \ all the names trom f,g if # then return yes if g then return yes else return ns fi fh end ie \ f,9 are logical 7D +a = Bra 8 ab = a+ Cb ace a fun LATER (a, By return not(@>B or A=B) end fa, b) 19) aos b aot (aces 1) a extern: 22. \ all the names from Ss s ENDLESS () end o> exit = return \ it loop: as above while # do s until ¢ = do Af otf) then exit fi s if g then exit £1 od while £ do s on . while # do s until ao BO OS 21 - do Ss until # = while yes do 5 until repeat n while # do s until g s call proc REPEAT_LOOP (N) extern: \ all the names from S,f,u Af not(is_int(N) and N>=@) then error © #1 While N>@ and # do 8 Nee No until g end «np \ nas integer repeat n do s od repeat n while yes do s until no for 4 from a step while de s until @ = call proc FOR_FROM_STEP_LOOP (A, 6? extern: Nip all the names from S,f,9 if not(is_int(A) or is_real(A)) then error) i if not (as_int(C? or is_reai(c)? then error fa if Ce@ then errorO fi i= A protect 1 while f do s unprotect 1 are ite protect i until g unprotect + end ao \ a, © are numbers aes for i from a step < do S od = for 1 trom a step c while yes do s until ne for i step c do s od = for 1 from 1 step c do s od for 1 from a do s od for 1 froma step t do Ss od for 1 froma te b step ¢ while # do s until g = call proc FOR_PROM_TU_STEP_LOUF (A, B, C> extern: .. \i, all the names from 8,f.g if not (is_int(B) or is_reai(B)) then error fi for i from @ step © while ((B-i)xC >= @) and + do s until @ end fa, by Gd Sa, b, © are numbers for 1 froma to b step « do S od = for 1 from a to b step while yes do s until no Operations: ESA ae bi ge ses. etd = Ktaleps ... tad 15) k faa bd kKfazbie fun SLICE (kK, A, BD if not is_int(B) then error © FL if (B-Ae1 < @) then error © #1 BE - BP -23- if ie text then Hee e* for IND from A to B da He= HeKEIND od else Hi= a> for IND from @ to 8 do He= H+ 4 KCINDI b od #1 return end th, a, Dd \ kas tent or sequence, \ a, b are integers KC1eb2 k = fun Tall & , AD return KCA:#K) end (ky a \ k is text or sequence, \ a is integer 16) a sf b = fun INT_DIVISION (6, 8) 44 not(is_int(a) and is_int(B)) then error0 #1 a¢ BC=6 then error i RES:= af A>=8 then while AD=B do A= A-B RES:= RES*1 od else while (-6) >= B do Ar= A+B REG:= RES-1 od if A/=® then RESi= RES-1 Fi #2 return RES end (a, bs \ a, b are integers 17) a Kb = fun REMAINDER (A, BD return A ~ A//BXB end fa, BD \ a, b are integers Ab - RF ares Statements: 18) vE aso .sen # call Proc SLICE_ASSIGN (<=K, 6, 8, H) if (B-Ati < @) then error (© fi Kr= KOr@-21 + H+ KEBeIE2 end tv, @ bh) \ (yh are sequences! \ vb are texts \ a, b are integers 19 VC adaex = call Proc SEL_ASSIGN (<= K, A, x) if is text) then af OX /= 1 then error () #4 KrAsAqt= xX iv, a, ® \ (y as sequence: any « i \ vy is text: x - text of length 1, \ a is intege Definitions: 20) procedure detinition ( see "DIALOG_UNIT™ }: proc i end = 325 proc i ‘ena 21) function definition ( see “DIALOG_UNIT” ): fun i end - 25 STANDARD NAMES ( 24.99.87 > Hb- BP \ In the Russian variant: constents: empty yes ne lt (line feed, mare precisely: newline. es apart, pi (pi = 3.14...1 functions: abs G0) ~ absolute value of number x sign{x) - number sign of x ( ~1, @, +2) sqrt Go ~ square root of number x entier(x) - the largest integer, that is less than x Centier (5.9) = 3; entier (-5.9) = -8 4 entier (5,4) = 53 entier (-5.4) = -6) rauna(s? - the nearest integer ta « (round (5.9) = 63 round (-5.9) = -6 3 round (5.5) = &3 round (-5.5) = -6 3 round (5.4) = 53 round (-5.4) = -5 > rand G0 ~ generator of random numbers in the interval C@-x€ CxO? int_randGo ~ generator of integer random numbers in the intervalt Fi-x 1 (=e) index of the element £ in the sequence S (of the subtext & in the text K). result: index of the first eccurrence or @, if absent index te, 8) ds_empty bo, is_lag(x), ig_int Oo, is_real (x), is text (x), is_seq(x), is proc(x), is_fun(x) © ~ the result 1s “yes’ or ‘no’ accerding ta the type of abject « graphic procedures (the values of arguments xi,yi,r are numbers): dot (x,y) = dot, line (l,y1,x2,y2) ~ Line, cfer Gyr) = circumference, color (cir) ~ color setting (clr — integer number or i-char text) eeeer eeererere nycTo ae ac m4, pa abs sign Kopens, sqrt wens ones acm migenc Ten_ayer AN_aor THN_ueA THn_sew tun reKcT Tun _KOpT THn_ApoU Tun eyHie rua oKP user regiont,y,clr) rect Gl, yi,x2,y2,clr) triangie(xt,y1,%2,y2, x3,y3,cir) cireletx.y.r.clr> functions: sin OD, cos (x), to Ge, arcsin(x), arctg (x), exp (x), In Os, ig oO. Soe painting af monacolored connected region by the other color (Oy) ~ coordinates of @ dot within the region) painted rectangle with the diagonal COD, yA) s OKZ, 2d painted triangle circle \ aaperrer Lb - $0 np ae apr neve sin cos to arcein arctg exp In 1g ay RAPIRA Differences in implementation on “Korvet™ and “Yamaha” in comparison with the langauge specification ( 24.09.87 > € 24.09.87 ) At present moment only the Russian variant of Rapira on “Korvet" and "Yamaha" is available. SYNTAX. Character set. The following Russian and Latin letters are equal (except in text constants): KEHXBAPOCHT ee 8 ee Capita! and small letters are equal (except in text constants). Lexemes, Keywords are reserved. mame ir= ( letter 1’ * > ¢ letter it) i digit > text rs 77" € 7+" letter + "\? digit C digit £ aigit 231 character™ | For specsymbols "4° and *>? there are equal " letter denotes a control characters "\? number denotes a character with the given code. Statements. Input - not only for absect_denotations, but for any expressions by commas, either. nput text” and “output nif" are not implemented. STANDARD NAMES. No "tg" and GRAPHICS. No “region” procedure. Graphic window’s boundary coordinates: x-axe : ® ~ 255, yraxe 1 9 - 1915 Colors are determined only by integers: @-14 (14 - for reverse color) resin" functions; ~ except """ and "4