Привет, котаны!
Я решился на отчаянный шаг — поэкспериментировать с компиляторами. После долгого сидения я понял что питон это не то — надо шагнуть дальше. Ну, хотя бы в с т.з. функционального программирования. Сразу скажу что концепции я пока не вижу и ответов на фундаментальные вопросы типа степень ленивости языка, всякие там монады, в каком виде делать ООП (и делать ли?) у меня нет. Но всё же забавно поиграться просто с синтаксисом.
Основные приоритеты: компактность, наглядность, удобное представление рутинных действий. Цели: высокоуровневое системное программирование. Т.е. целей писать на нём ядро нет, вопросы скорости пока не интересует. Скажем, хотелось бы ЯП чтобы можно было легко писать как скрипты аля-шелл, так и полноценные программы. Но внутренние детали я бы хотел обсудить позже, и так вопросов куча. Вот что родилось в моём больном воображении:
/* DATA TYPES */
//ints and floats, types are infered from the value
i = 1; f = 1.0
// list
l = [1,2,3]
//tuple (arguments of functions are passed in tuples)
t = 1, 2, 3
//tuple with named fields
tuple X: a, b, c
x = X a=1, b=2, c=3
// the same but with optional parens
x = X(a=1, b=2, c=3)
// access tuple attrs
print x.a, x.b, x.c
//hashes
{} // empty hash
h = {b=>2,a=>1}
print h.keys // -> "pb, a]" because hashes preserve insert order
//regular expressions
pattern = /[A-z][a-z]{1-2}/
/* BASICS */
// define variable
x = 1
// define function "z" of two args
z x:int, y:int = 2*x + y
// function invocation
z 1, 2
// or
z x=1, y=2
// composition, equivalent of print(z(1,2))
print z 1, 2
// conditions:
if a > 2:
pass
//if-else in one line
if x == 2: {x = 3} else: {x = 4}
//regexp
if x ~= //
switch x:
x == 1: pass
x < 10: print("x is really less than 10")
continue # go down
x < 5 : print("x ")
_ : print("what a strange X")
/* SUGAR */
# shell invocation
x = `ps ax | wc -l`
# equivalent of vm = VM(); ...; vm.stop()
vm1 = VM(), vm2 = VM():
on cleanup:
vm1.stop and vm2.stop():
...
/* HIGHER ORDER FUNCTIONS */
# a(b(c))
c | b | a
a . b . c
/* GROUPING */
// block may appear at any place where expression is acceptable.
// the return value is the last statement
// statements are separated by semicolon.
x = true
if x: {print "it turned out that x is true"; x=false}
else: {print "x is false, sad but true"; }
/* HELLO, WORLD */
main argv =
print "hello, hell"
print "my args:", argv
/* STRING SUBSTITUTION */
x = 666
print "x is equal to ${x+1}" // equivalent of { tmp = x+1; printf("x is equal to %d\n", tmp) }
/* EXCEPTIONS */
// catch exception and get its value in _err
fd = open "filename" || die "exception ${_err}"
try:
fd = open "filename"
except NotFound:
fd = try {open "filename"} except NotFound: -1
/* LANGUAGE MODES */
//shell invocation in backticks
files = `ls -la /tmp`
`for f in ${files}; do scp $f remote:/tmp; done` \
|| die "scp failed with ${_err}"
/* COMMENTS */
// this is a comment
# and this is a comment
/* and this as well */
; have fun with many comment styles
/* SMALL THINGS */
for elem in some_list:
...
print elem //will raise error because loop variables are not seen outside the loop by default
// for this reason file will be automaticaly closed once the control reach the end of the loop
for l in os.open("some_file"):
...
PS кодовое название — velosipedix.
PPS case ymn,
archimag,
baverman, tailgunner,
qnikst,
mv и всех других кого забыл :)
PPPS похоже что инета у меня не будет до воскресенья...