新しいプログラミング言語のフレームワーク


geektimes.ru/post/100171
初期のプログラミング言語の軽いタッチと静けさにいつも満足しています。 テキストはあまりありません。 多くのことが行われます。 古いプログラムは、コンパイラとの議論としてではなく、よく話された研究者とよく研究された機械の同僚との間の静かな会話のように読みます。 洗練されたものがそのようなノイズを買うと誰が推測したでしょうか?

-ディック・ガブリエル

...

標準言語(Java、C ++)は静的に型付けされています。

ほとんどの部外者言語(Ruby、Python、JavaScript)は解釈され、動的に型指定されます。

おそらくその結果、専門家ではないプログラマーは、「使いやすさ」と解釈および動的型付けを混同してしまいました。

世界は誤った二分法に分かれています:素敵な、解釈された、動的な対versusい、コンパイルされた、静的な。

物事を正しくする時。
私は初期のプログラミング言語の使いやすさと静けさに常に魅了されてきました。 テキストのビット。 しかし、多くが行われています。 古いプログラムは、コンパイラーとの議論としてではなく、よく話す研究者と訓練された機械の同僚との間の静かな会話として読まれます。 洗練されたものほどノイズが増えると誰が考えたでしょうか?

-ディック・ガブリエル

...

標準言語(Java、C ++)は静的に型付けされます。

ほとんどの部外者言語(Ruby、Python、JavaScript)は解釈され、動的に型指定されます。

おそらくこの結果として、専門家ではないプログラマーは、「使いやすさ」と解釈可能性および動的型付けを混同しています。

世界は間違った二分法によって分割されました:心地よい、解釈された、動的な対lyい、コンパイルされた、静的な。

この状況を修正する時が来ました。

この哀れなことに、私は新しいプログラミング言語の例を紹介します。

以下に小さなコード例を示します。

[ コードは次の記事のアイデアに基づいています ]
(予約文字の意味を推測し、あなたが知っているプログラミング言語でこのコードを精神的に書き換えてみてください。)

そして、より大きな例があります(これは、以前の記事の Pythonコードの翻訳です)。
[予約済み]レターを使用したコード
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).

. [ : '""', ''"" "'""'', ``.]
, Python , , , Python, — , ( \closure ), ( Cython : "http://...?rev=" + revision).

11/12/13 /:
Avar( auto C++11)
Cincontained in\
Iif
Eelse
exception
Ffn
L/loop//for, while do-while
Nnull
Rreturn
Sswitchswitch/select
Ttype
T()typeof()(typeof GCC, decltype C++11)
X
( — , .)

/ , ( [ [?]] ), , 11/12/13 / /.
:
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\. —
SS.break
S.fallthrough
TT.base\. —
T.enum\. —



  1. ( ++ RAII) — F.on_scope_exit ( defer Go).
  2. / — F.destructor.

.
close():
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
        ...

(type inference)


, copy()\() share()\().
( Nemerle ). autounishared_ptr — unique_ptr shared_ptr C++11. share(p), p shared_ptr-, unique_ptr-.

copy()\() , , , ( = ).
, (a1 a2 ):
a2 = a1;
C++ . Python a2 a1. : a2 = copy(a1) , a2 = share(a1) .
( — , , C++ Rust ( ).)

, , ?
A fstr = File(fname).read()  //    = ().()
File(fname).write(contents)  //  ().()

I File(fname)    //    I fs:is_file(fname)
File(fname).size //    fs:stat(fname).size

/


Release/Optimized ? Debug ? Debug Release/Optimized? , , / , . , - , Release/Optimized build. , gdb, optimized out . , - ( - ) ! — . , , , .

, , , , , .

( )


: ( :numbers ).

. (, , .x [/] x), ( \static C++) — .:.

@ ( C a — Capture\) — , nonlocal Python.

^ — ‘ ’\scope, (, i, - , i, i , ^i). ^ :
F outer_func(...)
   F local_func(...)
      ^R // (or ^(outer_func)R) return from outer_func 

( , ). - , .

P.S. .
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
       (.)
         ++
       

    
       () -> & //    (   —     )
          .
       () -> &
          .
       ()
          .

, : ( Python ) [] ( C++ ).

Source: https://habr.com/ru/post/J350694/


All Articles