var x = 42
func f(x; offset=0) { return (x) }
func myFunc(x; delimiter=r'\', other="hi $x") { return (x) }
proc my-proc(x, y; d=$(echo hi)) { echo hi }
proc my-proc(x, y; d=$(echo 2)) { echo hi }
var y = f(42)
var z = f(42; offset=5)
var r2 = r'C:\Program # Files\'
var a = [0, 1, 2]
var b = [a[2], a[1], a[0], f(1)]
var c = (f(2), f(1), f(0), a[0], {})
hay define Package
Package foo {
x = 42 + f(1)
y = ['foo', "$y"]
multi_line = [
'a',
'b',
$(echo hi),
]
}
pp (1 + (a[1] + 3)); echo next
pp (1 +
(a[1] + 3)); echo next
pp ('hi' ++ "hi $x" ++ r'c:\' ++ b'\n')
echo {a,b}@example.com
if(42) { echo yes }
if (42 > a[0]) {
echo 'yes'
}
for i, item in (a) {
echo "$i $item"
}
pp [a]
pp (${x} ++ $(echo hi) ++ 'hi')
pp [${x} ++ $(echo hi) ++ 'hi']
echo *.[ch]
echo \( hi \) \[ hi \]
: '''
" TODO:
"
" More structure
"
" - backslash escapes within strings:
" - \" \$ in double quotes
" - \u{123456} in J8-style strings
"
" - Is there way to understand recursion like ${a:-'foo'}? Or just leave that
" out
" - There is also recursion of $(hostname) and such.
"
" - Here docs? They are hard, could leave them out of YSH
'''
var foods = :|
pea nut
other
\(
|
var y = f(42)
var y = f('str' ++ "hi $x")
= f(42)
call f(42)
pp (f(42))
pp [f(42)]
echo ls --flag=$[x + 1]; echo next
echo ls --flag=\$[x + 1]
echo @[glob('*.py')]; echo next
echo \@[glob]
echo "hi $x"
echo $"explicit $x"
= :| foo.txt *.py "$x" |
= :| $x $(echo hi) @(echo hi) $[42+1] @[a] |
= :| \' \" \$ \@ \( \) \[ \] |
= $(echo 'command sub' $(echo hi) )
= @(echo u'spliced command sub' @foods )
= ^(echo "unevaluated" $hi $[y + 1])
= "hi $x"
= $"explicit $x"
= ^"unevaluated $x"
= f(^"unevaluated $x")
echo "greeting = $(echo hi)"
echo "sum = $[x + 99]"
echo $(echo hi)
echo @(echo hi)
= ^[42 + a[i]]
func g(...args) { return (args[0]) }
func myfunc(...args) { return (args[0]) }
= $(echo 1
echo $x 2)
= @(echo 3
echo 'yo' 4)
= ^(echo 5
echo "hi $x" 6)
var y = (42,
43,
f(5))
var z = f(1); echo hi
var z = g(1, 2,
3); echo hi
setvar a[0 + 0] = 42
= g(42,
43,
f(5))
call myfunc(42,
43,
f(5)); echo next
call g(3, 4, 5); echo hi
call g(3, 4, 5)
var d = {
k: 1,
k: 2,
}; echo next
var d = len({
k1: 'value',
k2: g(5,
6, 7),
bracket: [
1, 2, 3
],
}) + 42
var mylist = [
1,
2,
f(3),
foods[0],
{k: 'value'},
]
= len({ k: [x, x] }) + 42
echo $(echo \( \))
echo $(echo \[ \])
echo $(echo \{ \})
= $(echo \( \))
= $(echo \[ \])
= $(echo \{ \})
= ( $(echo \( \)) )
= ( $(echo \[ \]) )
= ( $(echo \{ \}) )
= [ $(echo \( \)) ]
= [ $(echo \[ \]) ]
= [ $(echo \{ \}) ]
= { k: $(echo \( \)) }
= { k: $(echo \[ \]) }
= { k: $(echo \{ \}) }
= $(pp (42))
= $(pp [42])
pushd /tmp
cd /
popd
time echo hi | wc -l