geektimes.ru/post/100171 :
I’m always delighted by the early programming languages. Not much text; a lot gets done. Old programs read a quietly spoken researcher and a compiler. Who'd have guessed sophistication bought such noise?
- Dick Gabriel
...
')
The standard languages (Java, C ++) are statically typed.
Most outsider languages (Ruby, Python, JavaScript) are interpreted and dynamically typed.
Perhaps as a result, non-expert programmers have a confused "ease of use" with interpretation and dynamic typing.
The world has split into a false dichotomy: interpreted, dynamic versus ugly, compiled, static.
Time to put things right.I have always admired the ease and serenity of early programming languages. Some text; but much is being done. Older programs are read as quiet conversations between a well-spoken researcher and a well-trained mechanical colleague, and not as debates with the compiler. Who would have thought that sophistication would bring so much noise?
- Dick Gabriel
...
Standard languages (Java, C ++) are statically typed.
Most outsider languages (Ruby, Python, JavaScript) are interpretable and dynamically typed.
Perhaps as a result of this, non-expert programmers confuse "ease of use" with interpretability and dynamic typing.
The world was divided by a false dichotomy: pleasant, interpretable, dynamic versus ugly, compiled, static.
The time has come to correct this situation.
F calculate_sacred_number()
A results = []
L(hash_algorithm) hashlib:algorithms_available // -
\\ ( MD5, SHA...)
I.unlikely "shake" C hash_algorithm // SHAKE, ...
L.continue
L(uppercase) 0B..1B // ,
L(space) 0B..1B //
L(n) 10..99 //
A nw = :numbers[n] // , .
I uppercase
nw .= upper()
I space
nw .= replace(‘-’, ‘ ’)
A ns = String(n)
// ,
A digest1 = hashlib:(hash_algorithm, nw.encode()).hexdigest()
// , .
A digest2 = hashlib:(hash_algorithm, ns.encode()).hexdigest()
L 2 // ,
//
// .
I digest1[0] == ns[0] & digest1.last == ns[1]
& digest2[0] == ns[0] & digest2.last == ns[1]
results [+]= ns
//
digest1 = digest1[0 .< (len) I/ 2]
digest2 = digest2[0 .< (len) I/ 2]
assert(results.len == 1) // ""
R results[0] //
// Based on [https://stackoverflow.com/a/8982279/2692494 ‘How do I tell Python to convert integers into words’]
A numbers = "zero one two three four five six seven eight nine".split()
numbers [+]= "ten eleven twelve thirteen fourteen fifteen sixteen".split()
numbers [+]= "seventeen eighteen nineteen".split()
L(tens) "twenty thirty forty fifty sixty seventy eighty ninety".split()
L(ones) numbers[0..9]
numbers [+]= I ones == "zero" {tens} E tens‘-’ones
print(calculate_sacred_number())
fn calculate_sacred_number()
var results = []
loop(hash_algorithm) hashlib:algorithms_available // -
\\ ( MD5, SHA...)
if.unlikely "shake" in hash_algorithm // SHAKE, ...
loop.continue
loop(uppercase) 0B..1B // ,
loop(space) 0B..1B //
loop(n) 10..99 //
var nw = :numbers[n] // , .
if uppercase
nw .= upper()
if space
nw .= replace(‘-’, ‘ ’)
var ns = String(n)
// ,
var digest1 = hashlib:(hash_algorithm, nw.encode()).hexdigest()
// , .
var digest2 = hashlib:(hash_algorithm, ns.encode()).hexdigest()
loop 2 // ,
//
// .
if digest1[0] == ns[0] & digest1.last == ns[1]
& digest2[0] == ns[0] & digest2.last == ns[1]
results [+]= ns
//
digest1 = digest1[0 .< (len) I/ 2]
digest2 = digest2[0 .< (len) I/ 2]
assert(results.len == 1) // ""
return results[0] //
// Based on [https://stackoverflow.com/a/8982279/2692494 ‘How do I tell Python to convert integers into words’]
var numbers = "zero one two three four five six seven eight nine".split()
numbers [+]= "ten eleven twelve thirteen fourteen fifteen sixteen".split()
numbers [+]= "seventeen eighteen nineteen".split()
loop(tens) "twenty thirty forty fifty sixty seventy eighty ninety".split()
loop(ones) numbers[0..9]
numbers [+]= if ones == "zero" {tens} else tens‘-’ones
print(calculate_sacred_number())
_:_(...)
. , fs:path:dirname()
, re:compile()
\:()
, math:log()
\:()
, time:sleep()
\:()
, json:load()
, html:escape()
(fs
, fs:path
\:
, re
, math
, time
, json
, html
).'""'
, ''"" "'""''
, ``.]"http://...?rev=" + revision
).A | var | ( auto C++11) | ||
C | in | contained in\ | ||
I | if | |||
E | else | |||
exception | ||||
F | fn | |||
L | / | loop | // | for, while do-while |
N | null | |||
R | return | |||
S | switch | switch/select | ||
T | type | |||
T() | typeof | () | (typeof GCC, decltype C++11) | |
X |
I\ | I.likely\. I.unlikely\. |
\ | E.try E.throw E.catch\. E.try_end ( try-else Python) |
F\ | F.args\. F.virtual.new\.. F.virtual.override\.. F.virtual.final\.. F.virtual.abstract\.. F.destructor\. |
L\ | L.continue\. L.on_continue\._ L.break\. L.on_break\._ L.again — L.index — ( 0) L.next\. — L.prev\. — |
S | S.break S.fallthrough |
T | T.base\. — T.enum\. — |
F.on_scope_exit
( defer Go).F.destructor
.tmpfile, fname = tempfile.mkstemp(text=True)
tmpfile = open(tmpfile)
r = subprocess.call(cmd, stdout = tmpfile, stderr = tmpfile)
tmpfile.seek(0)
print(tmpfile.read(), end = '')
tmpfile.close() # , tmpfile
os.remove(fname)
move() :Person p
p.name = ...
p.age = ...
persons.append(p) // ++ persons.push_back(std::move(p))
sorted()\():for root, dirs, files in os.walk(path):
for file in sorted(files): # C++ - (files.sort(), files) files
...
=
).A fstr = File(fname).read() // = ().()
File(fname).write(contents) // ().()
I File(fname) // I fs:file_exists(fname)
File(fname).size // fs:stat(fname).size
:
( :numbers
)..
(, , .x
[/] x
), ( \static C++) — .:
.^
— ‘ ’\scope, (, i
, - , i
, i
, ^i
). ^ :F outer_func(...)
F local_func(...)
^R // (or ^(outer_func)R) return from outer_func
T Person
String name
Int age
F (name, age)
.name = name // or (.).name = name, because (.) is this/self
.age = age
A persons = []
persons [+]= Person("Name", 17)
// Translation of Python's `def parenthesize(s: Union[str, bytes]) -> Union[str, bytes]: ...` from [http://neopythonic.blogspot.com]:
F parenthesize(T C (String, Bytes) s)
...
// Doubly linked list
T DLListItem[T Type]
Type& prev // ‘unsafe pointer’/‘unowned reference’ [true weak pointer/reference `Type??` is much more expensive]
Type? next
F is_in_list // if method is defined without parentheses, than it must be called also without, i.e.: I it.is_in_list {...}
R next != N
T DLList[T Type(DLListItem)] // Type(DLListItem) means that Type must be derived from DLListItem
Type? first
Type& last
F.destructor // destructor is needed/necessary because some list item may be shared, and in that case it will not be removed from the list and also all following items will not be removed
.clear()
F clear()
Type? p = move(first) // this also sets `first` to N
L p
p.prev = N
Type? n = move(p.next) // this also sets `p.next` to N
p = n // move(n) is not needed here as the compiler put `move` automatically at all places of last use of variable
last = N
F append, [+]=(Type &item) // define both method `append()` and operator [+]=
item.prev = .last
I .last {.last.next = item} E .first = item
.last = item
F calc_len()
Int len = 0
L (.)
len++
R len
F L
F () -> Type& // returns iterator to the first element of this container
R .first
F next(it) -> Type&
R it.next
F prev(it)
R it.prev
(, )
. = // (.). = , (.) this/self
. =
_ = []
_ [+]= ("", 17)
// Python- `def parenthesize(s: Union[str, bytes]) -> Union[str, bytes]: ...` [http://neopythonic.blogspot.com]:
__( (, ) )
...
//
[ ]
& // / [ `??` ]
?
_ // , , : ._ {...}
!=
[ ()] // () ,
?
&
. // , - shared\,
.()
()
? = () // ``
. =
? = (.) // `.`
= // () , ``
=
, , [+]=( &) // "" : F append, ...
. = .
. {.. = } . =
. =
_()
= 0
(.)
++
() -> & // ( — )
.
() -> &
.
()
.
Source: https://habr.com/ru/post/350694/
All Articles