langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
18
Task/Accumulator-factory/UNIX-Shell/accumulator-factory-1.sh
Normal file
18
Task/Accumulator-factory/UNIX-Shell/accumulator-factory-1.sh
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
accumulator() {
|
||||
# Define a global function named $1
|
||||
# with a global variable named ${1}_sum.
|
||||
eval "${1}_sum=\$2"
|
||||
eval "$1() {
|
||||
${1}_sum=\$(echo \"(\$${1}_sum) + (\$2)\" | bc)
|
||||
eval \"\$1=\\\$${1}_sum\" # Provide the current sum.
|
||||
}"
|
||||
}
|
||||
|
||||
accumulator x 1
|
||||
x r 5
|
||||
accumulator y 3
|
||||
x r 2.3
|
||||
echo $r
|
||||
y r -3000
|
||||
echo $r
|
||||
12
Task/Accumulator-factory/UNIX-Shell/accumulator-factory-2.sh
Normal file
12
Task/Accumulator-factory/UNIX-Shell/accumulator-factory-2.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fn accumulator n {
|
||||
result @ i {
|
||||
n = `{echo $n + $i | bc}
|
||||
result $n
|
||||
}
|
||||
}
|
||||
|
||||
fn-x = <={accumulator 1}
|
||||
x 5
|
||||
fn-y = <={accumulator 3}
|
||||
echo <={x 2.3}
|
||||
echo <={y -3000}
|
||||
Loading…
Add table
Add a link
Reference in a new issue