Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,2 +1,4 @@
---
category:
- Simple
note: Basic language learning

View file

@ -1,2 +1,20 @@
a = 1 # Here we declare a numeric variable
fruit = "banana" # Here we declare a string datatype
BEGIN {
# Variables are dynamically typecast, and do not need declaration prior to use:
fruit = "banana" # create a variable, and fill it with a string
a = 1 # create a variable, and fill it with a numeric value
a = "apple" # re-use the above variable for a string
print a, fruit
# Multiple assignments are possible from within a single statement:
x = y = z = 3
print "x,y,z:", x,y,z
# "dynamically typecast" means the content of a variable is used
# as needed by the current operation, e.g. for a calculation:
a = "1"
b = "2banana"
c = "3*4"
print "a,b,c=",a,b,c, "c+0=", c+0, 0+c
print "a+b=", a+b, "b+c=", b+c
}

View file

@ -1 +1,7 @@
x = y = z = 3
# usage: awk -v x=9 -f test.awk
BEGIN {
y = 3
z = x+y
print "x,y,z:", x,y,z
printf( "x=%d,y=%d,z=%d:", x,y,z )
}

View file

@ -1,7 +1,15 @@
function foo(j k) {
# j is an argument passed from caller
# k is a dummy not passed by caller, but because it is in the
# argument list, it will have a scope local to the function
k = length(j)
print j "contains " k " characters"
function foo(s, k) {
# s is an argument passed from caller
# k is a dummy not passed by caller, but because it is
# in the argument list, it will have a scope local to the function
k = length(s)
print "'" s "' contains", k, "characters"
}
BEGIN {
k = 42
s = "Test"
foo("Demo")
print "k is still", k
foo(s,k)
print "k still is", k
}

View file

@ -0,0 +1,2 @@
# Feeding standard-input with echo:
echo -e "2 apples 0.44$ \n 3 banana 0.33$" | awk '{p=$1*$NF; sum+=p; print $2,":",p; }; END{print "Sum=",sum}'

View file

@ -0,0 +1 @@
(myfunc=i j.!arg:(?i.?j)&!i+!j)

View file

@ -0,0 +1 @@
(defparameter *x* nil "nothing")

View file

@ -0,0 +1 @@
(defvar *x* 42 "The answer.")

View file

@ -0,0 +1 @@
(documentation '*x* 'variable)

View file

@ -0,0 +1,3 @@
(let ((jenny (list 8 6 7 5 3 0 9))
hobo-joe)
(apply #'+ jenny))

View file

@ -0,0 +1,4 @@
(progn
(let ((*x* 43))
(print *x*)
(print *x*))

View file

@ -0,0 +1 @@
(setf *x* 625)

View file

@ -0,0 +1,4 @@
(declaim (ftype (function (fixnum) fixnum) frobnicate))
(defun frobnicate (x)
(declare (type fixnum x))
(the fixnum (+ x 128)))

View file

@ -0,0 +1,23 @@
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Run application.
local
i: INTEGER
s: STRING
do
i := 100
s := "Some string"
create a.make_empty
end
feature {NONE} -- Class Features
a: ARRAY[INTEGER]

View file

@ -0,0 +1,3 @@
-- assume A and B are of the same datatype
B := A
A.some_modification_feature

View file

@ -4,7 +4,7 @@ cc = 2*10 /*assigns charser 20 ───► CC
dd = 'Adam' /*assigns chars Adam ───► DD */
ee = "Adam" /*same as above ───► EE */
ff = 10. /*assigns chars 10. ───► FF */
gg = '10.' /*same as above ───► GG */
gg='10.' /*same as above ───► GG */
hh = "+10" /*assigns chars +10 ───► hh */
ii = 1e1 /*assigns chars 1e1 ───► ii */
jj = +.1e+2 /*assigns chars +.1e+2 ───► jj */

View file

@ -11,11 +11,8 @@ parse var xxx nn oo pp qq rr
/*assigns ─5 ───► QQ */
/*assigns "null" ───► RR */
/*a "null" is a string of length zero (0), */
/*and is not to be confused with a null char.*/
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

@ -1,20 +1,8 @@
/*REXX pgm to do a "bad" assignment (with an unassigned REXX variable).*/
signal on novalue /*usually, placed at pgm start. */
xxx=aaaaa /*tries to assign aaaaa ───► xxx */
say xxx 'or somesuch'
exit
novalue: /*this can be dressed up better. */
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 line number" badLine
say
say badSource
say
exit 13
call value 'CAT', "When the cat's away, the mice will play."
/*assigns a literal ───► CAT */
yyy='CA'
call value yyy'T', "Honest as the Cat when the meat's out of reach."
/*assigns a literal ───► CAT */
yyy = 'CA'
call value yyy || 'T', "Honest as the Cat when the meat's out of reach."
/*assigns a literal ───► CAT */

View file

@ -1,7 +1,20 @@
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
/*REXX pgm to do a "bad" assignment (with an unassigned REXX variable).*/
signal on noValue /*usually, placed at pgm start. */
xxx=aaaaa /*tries to assign aaaaa ───► xxx */
say xxx 'or somesuch'
exit
noValue: /*this can be dressed up better. */
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 line number" badLine
say
say badSource
say
exit 13

View file

@ -0,0 +1,18 @@
/*REXX pgm shows different scopes of a variable: "global" and "local".*/
q = 55 ; say ' 1st q=' q /*assign a value ───► "main" Q.*/
call sub ; say ' 2nd q=' q /*call a procedure subroutine. */
call gyro ; say ' 3rd q=' q /*call a procedure with EXPOSE. */
call sand ; say ' 4th q=' q /*call a subroutine or function. */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SUB subroutine──────────────────────*/
sub: procedure /*use PROCEDURE to use local vars*/
q = -777 ; say ' sub q=' q /*assign a value ───► "local" Q. */
return
/*──────────────────────────────────GYRO subroutine─────────────────────*/
gyro: procedure expose q /*use EXPOSE to use global var Q.*/
q = "yuppers" ; say 'gyro q=' q /*assign a value ───► "exposed" Q*/
return
/*──────────────────────────────────SAND subroutine─────────────────────*/
sand: /*all REXX variables are exposed.*/
q = "Monty" ; say 'sand q=' q /*assign a value ───► "global" Q*/
return

View file

@ -0,0 +1,7 @@
aaa. = 'nope.' /*assign this string as a default*/
aaa.1=1 /*assign 1 to first element.*/
aaa.4=4. /* " 4 " fourth " */
aaa.7='lucky' /* " 7 " seventh " */
do j=0 to 8 /*go through a bunch of elements.*/
say 'aaa.'||j '=' aaa.j /*display element # and its value*/
end /*we could've started J at -100.*/

View file

@ -0,0 +1,4 @@
radius=6.28 /*assign a value to a variable. */
say 'radius =' radius
drop radius /*now, "undefine" the variable. */
say 'radius =' radius

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