This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1,16 @@
10 LET A=1.3
20 LET B%=1.3: REM The sigil indicates an integer, so this will be rounded down
30 LET C$="0121": REM The sigil indicates a string data type. the leading zero is not truncated
40 DIM D(10): REM Create an array of 10 digits
50 DIM E$(5.10): REM Create an array of 5 strings, with a maximum length of 10 characters
60 LET D(1)=1.3: REM Assign the first element of d
70 LET E$(3)="ROSE": REM Assign a value to the third string
80 PRINT D(3): REM Unassigned array elements have a default value of zero
90 PRINT E$(3): REM Ten spaces because string arrays are not dynamic
100 PRINT E$(3);"TTA CODE": REM There will be spaces between rose and etta
110 DIM F%(10): REM Integers use less space than floating point values
120 PRINT G: REM This is an error because f has not been defined
130 PRINT D(0): REM This is an error because elements are numbered from one
140 LET D(11)=6: REM This is an error because d only has 10 elements
150 PRINT F%: REM This is an error because we have not provided an element number
160 END

View file

@ -0,0 +1,15 @@
10 A = 1.7: REM LET IS NOT REQUIRED
20 LET B% = 1.7: REM THE PERCENT SIGN INDICATES AN INTEGER; THIS GETS TRUNCATED DOWN
30 LET C$ = "0121": REM THE DOLLAR SIGN INDICATES A STRING DATA TYPE. THE LEADING ZERO IS NOT TRUNCATED
40 DIM D(20): REM CREATE AN ARRAY OF 21 FLOATING POINT NUMBERS
50 DIM E$(5,10): REM CREATE A TWO DIMENSIONAL ARRAY OF 66 STRINGS
60 LET D(1) = 1.3: REM ASSIGN THE SECOND ELEMENT OF D
70 Y$(3) = "ROSE": REM ASSIGN A VALUE TO THE FOURTH STRING
80 PRINT X: REM UNASSIGNED FLOATING POINT AND INTEGER VARIABLES HAVE A DEFAULT VALUE OF ZERO
90 PRINT Y$(2): REM UNASSIGNED STRING VARIABLES ARE EMPTY
100 PRINT Y$(3);"TTA CODE": REM THERE WON'T BE SPACES BETWEEN ROSE AND ETTA
110 F%(10) = 0: REM IF ARRAYS ARE NOT DECLARED THEY HAVE 11 ELEMENTS BY DEFAULT; IE. DIM F%(10)
120 PRINT G: REM THIS PRINTS 0 AND IS NOT AN ERROR EVEN THOUGH G HAS NOT BEEN DEFINED
130 PRINT D(0): REM THIS IS NOT AN ERROR BECAUSE ELEMENTS ARE NUMBERED FROM ZERO.
140 PRINT F%: REM THIS PRINTS 0 BECAUSE F% IS A DIFFERENT VARIABLE THAN THE ARRAY F%(10)
150 LET D(21) = 6: REM THIS IS AN ERROR BECAUSE D ONLY HAS 21 ELEMENTS INDEXED FROM 0 TO 20.

View file

@ -0,0 +1 @@
int a;

View file

@ -0,0 +1 @@
std::vector<int> intVec;

View file

@ -0,0 +1,5 @@
MOVE 5 TO x
MOVE FUNCTION SOME-FUNC(x) TO y
MOVE "foo" TO z
MOVE "values 1234" TO group-item
SET some-index TO 5

View file

@ -0,0 +1,18 @@
01 normal-date.
03 year PIC 9(4).
03 FILLER PIC X VALUE "-".
03 month PIC 99.
03 FILLER PIC X VALUE "-".
03 dday PIC 99. *> Misspelling is intentional; day is a reserved word.
01 reversed-date.
03 dday PIC 99.
03 FILLER PIC X VALUE "-".
03 month PIC 99.
03 FILLER PIC X VALUE "-".
03 year PIC 9(4).
...
PROCEDURE DIVISION.
MOVE "2012-11-10" TO normal-date
MOVE CORR normal-date TO reversed-date
DISPLAY reversed-date *> Shows '10-11-2012'

View file

@ -0,0 +1,4 @@
01 a PIC X(20). *> a is a string of 20 characters.
01 b PIC 9(10). *> b is a 10-digit integer.
01 c PIC 9(10)V9(5). *> c is a decimal number with a 10-digit integral part and a 5-digit fractional part.
01 d PIC 99/99/99. *> d is an edited number, with a slash between each pair of digits in a 6-digit integer.

View file

@ -0,0 +1,10 @@
*> Group data items do not have a picture clause.
01 group-item. *> The 'implied' PIC for group-item is PIC X(20).
03 sub-data PIC X(10).
03 more-sub-data PIC X(10).
*> Example use of FILLER.
01 formatted-data.
03 part-one PIC X(10).
03 FILLER PIC X.
03 part-two PIC X(10).

View file

@ -0,0 +1,11 @@
DATA DIVISION.
WORKING-STORAGE SECTION.
01 initialized-data PIC X(15) VALUE "Hello, World!".
01 other-data PIC X(15).
...
PROCEDURE DIVISION.
DISPLAY initialized-data *> Shows 'Hello, World!'
DISPLAY other-data *> Will probably show 15 spaces.
...
*> Sets initialized-data back to "Hello, World!" and fills other-data with spaces.
INITIALIZE initialized-data, other-data

View file

@ -0,0 +1,3 @@
01 group-item VALUE "Hello!12345".
03 a-string PIC X(6). *> Contains "Hello!"
03 a-number PIC 9(5). *> Contains '12345'.

View file

@ -0,0 +1,8 @@
some-str (1:1) *> Gets the first character from the string
some-num (1:3) *> Get the first three digits from the number
another-string (5:) *> Get everything from the 5th character/digit onwards.
*> To get a proper array slice, you must use reference modification on its parent data item:
some-table-area (4:6) *> Get 6 characters from the array after from the 4th char onwards
*> To reference modify an array element
some-table (1) (5:1) *> Get the 5th character from the 1st element in the table

View file

@ -0,0 +1,3 @@
two() ->
A_variable = 1,
A_variable + 1.

View file

@ -1,6 +1,6 @@
<?php
/**
* @author Elad Yosifon <elad.yosifon@gmail.com>
* @author Elad Yosifon
*/

View file

@ -1,7 +1,7 @@
/* The PROCEDURE block and BEGIN block are used to delimit scopes. */
declare i float; /* external, global variable, excluded from the */
/* local ares (BEGIN block) below. */
/* local area (BEGIN block) below. */
begin;
declare (i, j) fixed binary; /* local variable */
get list (i, j);

View file

@ -10,3 +10,12 @@ parse var xxx nn oo pp qq rr
/*assigns 333 ───► PP */
/*assigns ─5 ───► QQ */
/*assigns "null" ───► RR */
cat = 'A cat is a lion in a jungle of small bushes.'
/*assigns a literal ───► CAT */
call value 'CAT', "When the cat's away, the mice will play."
/*assigns a literal ───► CAT */
yyy='CAT'
call value yyy, "Honest as the Cat when the meat's out of reach."
/*assigns a literal ───► CAT */

View file

@ -8,12 +8,12 @@ say xxx 'or somesuch'
exit
novalue: /*this can be dressed up better. */
badLine =sigl /*REXX statement num that failed.*/
badSource=sourceline(badLine) /*REXX source statement ··· */
badLine =sigl /*REXX line number that failed. */
badSource=sourceline(badLine) /*REXX source line ··· */
badVar =condition('D') /*REXX var name that's ¬ defined.*/
say
say '*** error! ***'
say 'undefined variable' badvar "at REXX statement number" badLine
say 'undefined variable' badvar "at REXX line number" badLine
say
say badSource
say

View file

@ -0,0 +1,7 @@
var.='something' /* sets all possible compound variables of stem var. */
x='3 '
var.x.x.4='something else'
Do i=1 To 5
a=left(i,2)
Say i var.a.a.4 "(tail is '"a||'.'||a||'.'||'4'"')"
End

View file

@ -0,0 +1,46 @@
#lang racket
;; define a variable and initialize it
(define foo 0)
;; increment it
(set! foo (add1 foo))
;; Racket is lexically scoped, which makes local variables work:
(define (bar)
(define foo 100)
(set! foo (add1 foo))
foo)
(bar) ; -> 101
;; and it also makes it possible to have variables with a global value
;; that are accessible only in a specific local lexical scope:
(define baz
(let () ; used to create a new scope
(define foo 0)
(define (bar)
(set! foo (add1 foo))
foo)
bar)) ; this is the value that gets bound to `baz'
(list (baz) (baz) (baz)) ; -> '(1 2 3)
;; define a new type, and initialize a variable with an instance
(struct pos (x y))
(define p (pos 1 2))
(list (pos-x p) (pos-y p)) ; -> '(1 2)
;; for a mutable reference, a struct (or some specific fields in a
;; struct) can be declared mutable
(struct mpos (x y) #:mutable)
(define mp (mpos 1 2))
(set-mpos-x! mp 11)
(set-mpos-y! mp 22)
(list (mpos-x mp) (mpos-y mp)) ; -> '(11 22)
;; but for just a mutable value, we have boxes as a builtin type
(define b (box 10))
(set-box! b (add1 (unbox b)))
(unbox b) ; -> 11
;; (Racket has many more related features: static typing in typed
;; racket, structs that are extensions of other structs,
;; pattern-matching on structs, classes, and much more)