September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,8 +1,4 @@
10 REM STRING SLICING EXAMPLE
20 LET S$="KNIGHTS"
30 REM WITH FIRST CHARACTER REMOVED:
40 PRINT S$(2 TO )
50 REM WITH LAST CHARACTER REMOVED:
60 PRINT S$( TO LEN S$-1)
70 REM WITH BOTH REMOVED:
80 PRINT S$(2 TO LEN S$-1)
100 LET S$="Knights"
110 PRINT S$(2:)
120 PRINT S$(:LEN(S$)-1)
130 PRINT S$(2:LEN(S$)-1)

View file

@ -0,0 +1,8 @@
10 REM STRING SLICING EXAMPLE
20 LET S$="KNIGHTS"
30 REM WITH FIRST CHARACTER REMOVED:
40 PRINT S$(2 TO )
50 REM WITH LAST CHARACTER REMOVED:
60 PRINT S$( TO LEN S$-1)
70 REM WITH BOTH REMOVED:
80 PRINT S$(2 TO LEN S$-1)

View file

@ -0,0 +1,17 @@
identification division.
program-id. toptail.
data division.
working-storage section.
01 data-field.
05 value "[this is a test]".
procedure division.
sample-main.
display data-field
*> Using reference modification, which is (start-position:length)
display data-field(2:)
display data-field(1:length of data-field - 1)
display data-field(2:length of data-field - 2)
goback.
end program toptail.

View file

@ -1,10 +1,10 @@
import extensions.
import extensions;
program =
[
var testString := "test".
public program()
{
var testString := "test";
console printLine(testString Substring(1)).
console printLine(testString Substring(0, testString length - 1)).
console printLine(testString Substring(1, testString length - 2)).
].
console.printLine(testString.Substring(1));
console.printLine(testString.Substring(0, testString.Length - 1));
console.printLine(testString.Substring(1, testString.Length - 2))
}

View file

@ -0,0 +1,11 @@
/**
Subtring/Top-Tail in Neko
*/
var data = "[this is a test]"
var len = $ssize(data)
$print(data, "\n")
$print($ssub(data, 1, len - 1), "\n")
$print($ssub(data, 0, len - 1), "\n")
$print($ssub(data, 1, len - 2), "\n")

View file

@ -0,0 +1,55 @@
from functools import (reduce)
def main():
for xs in transpose(
(chunksOf(3)(
ap([tail, init, compose(init)(tail)])(
['knights', 'socks', 'brooms']
)
))
):
print(xs)
# GENERIC -------------------------------------------------
# tail :: [a] -> [a]
def tail(xs):
return xs[1:]
# init::[a] - > [a]
def init(xs):
return xs[:-1]
# ap (<*>) :: [(a -> b)] -> [a] -> [b]
def ap(fs):
return lambda xs: reduce(
lambda a, f: a + reduce(
lambda a, x: a + [f(x)], xs, []
), fs, []
)
# chunksOf :: Int -> [a] -> [[a]]
def chunksOf(n):
return lambda xs: reduce(
lambda a, i: a + [xs[i:n + i]],
range(0, len(xs), n), []
) if 0 < n else []
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
def compose(g):
return lambda f: lambda x: g(f(x))
# transpose :: [[a]] -> [[a]]
def transpose(xs):
return list(map(list, zip(*xs)))
if __name__ == '__main__':
main()

View file

@ -0,0 +1,3 @@
str='abcdefg'
echo "${str#?}" # Remove first char
echo "${str%?}" # Remove last char

View file

@ -0,0 +1 @@
echo ${${str#?}%?} # Remove first & last chars

View file

@ -0,0 +1 @@
echo "${s:1:${#s}-2}"

View file

@ -0,0 +1 @@
tmp=${s#?}; tmp=${tmp%?}; echo "$tmp"

View file

@ -1,5 +0,0 @@
#!/bin/zsh
str='abcdefg'
echo ${str#?} # Remove first char
echo ${str%?} # Remove last char
echo ${${str#?}%?} # Remove first & last chars