Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
16
Task/Variables/BASIC/variables-1.basic
Normal file
16
Task/Variables/BASIC/variables-1.basic
Normal 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
|
||||
15
Task/Variables/BASIC/variables-2.basic
Normal file
15
Task/Variables/BASIC/variables-2.basic
Normal 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.
|
||||
1
Task/Variables/C++/variables-1.cpp
Normal file
1
Task/Variables/C++/variables-1.cpp
Normal file
|
|
@ -0,0 +1 @@
|
|||
int a;
|
||||
1
Task/Variables/C++/variables-2.cpp
Normal file
1
Task/Variables/C++/variables-2.cpp
Normal file
|
|
@ -0,0 +1 @@
|
|||
std::vector<int> intVec;
|
||||
5
Task/Variables/COBOL/variables-1.cobol
Normal file
5
Task/Variables/COBOL/variables-1.cobol
Normal 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
|
||||
18
Task/Variables/COBOL/variables-2.cobol
Normal file
18
Task/Variables/COBOL/variables-2.cobol
Normal 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'
|
||||
4
Task/Variables/COBOL/variables-3.cobol
Normal file
4
Task/Variables/COBOL/variables-3.cobol
Normal 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.
|
||||
10
Task/Variables/COBOL/variables-4.cobol
Normal file
10
Task/Variables/COBOL/variables-4.cobol
Normal 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).
|
||||
11
Task/Variables/COBOL/variables-5.cobol
Normal file
11
Task/Variables/COBOL/variables-5.cobol
Normal 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
|
||||
3
Task/Variables/COBOL/variables-6.cobol
Normal file
3
Task/Variables/COBOL/variables-6.cobol
Normal 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'.
|
||||
8
Task/Variables/COBOL/variables-7.cobol
Normal file
8
Task/Variables/COBOL/variables-7.cobol
Normal 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
|
||||
3
Task/Variables/Erlang/variables.erl
Normal file
3
Task/Variables/Erlang/variables.erl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
two() ->
|
||||
A_variable = 1,
|
||||
A_variable + 1.
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Elad Yosifon <elad.yosifon@gmail.com>
|
||||
* @author Elad Yosifon
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
7
Task/Variables/REXX/variables-4.rexx
Normal file
7
Task/Variables/REXX/variables-4.rexx
Normal 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
|
||||
46
Task/Variables/Racket/variables.rkt
Normal file
46
Task/Variables/Racket/variables.rkt
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue