当前位置:网站首页>The writing style of the construction and interpretation of the mini LISP interpreter

The writing style of the construction and interpretation of the mini LISP interpreter

2022-06-21 05:28:00 ccat

Today, I saw some readers complain that my book is to print out the source code for sale . I can understand this feeling , But in fact, this writing style is the result of repeated attempts , Instead of being lazy . The source code attached to the book , A lot of them use Scala To annotate Java . For example, yesterday my good friend asked me Java edition Env Type of get Why does the method use a try catch,

    public Object get(String name) throws ParserException {
        try {
            return findIn(name);
        } catch (ParserException notfound) {
            return findOut(name);
        }
    }

This is actually on the next page Scala The version is very clean

  def get(name: String): Try[Any] = {
    findIn(name).orElse(findUp(name))
  }

.Java The implementation of the , Just to get as close as possible Scala Of Try[T] , This is closer to a getOrElse Not error handling . This contrast of different languages , In the process of my development and writing , It brings a lot of inspiration and fun , It is also the experience I want to share with readers .
I read alone , Sometimes not patient enough , Will often skip the text and gnaw the code , This also affects writing . The future is also a place for improvement .
When sorting out this code , My idea is more like the process of writing mathematical problems . A caption 、 Illustrations can certainly help understand , I will try to add in the future version , But in the end , Programming problems , It is still to be solved by writing code . These codes are repeatedly modified to the current state , Than github Is easier to read . I also removed some engineering code as much as possible . Of course , Generally speaking , Same function ,Java The implementation of is usually better than Scala More verbose . But there are some interesting details to show . and Scala Code for , If you remove the explicit type definitions of variables and functions , It must be much more beautiful , But if the reader follows that code , You will encounter many compiler warnings and even type derivation errors . This point , I actually hope that in the future scala Can be like haskell So the dimension type , After all scala 3 Even indentation syntax can be implemented , The attitude of developers is still very open .Haskell Style annotation types , Combining indentation Syntax , It will be very helpful for typesetting, printing and reading .

There are also some implementations in the book , At the same time Scala 2 and Scala 3 Version of , This is because Scala 3 Of FP The grammar has changed a lot , Closer to the Haskell The system of . By showing Scala 3 Version of , Can better explain why these designs are so .
The other is if the reader can read directly github in JISP and SISP Code for , Of course, it's also very happy for me . But the code is missing some information , Mainly Commit Records do not necessarily represent correctness 、 Clear build process , There are a lot of debug、parsec Upgrade and think 、 test 、 Trial and error and writing correction . In the future, I will try to build a clear process , Teaching Library with chapter division . Not yet , Because these three years Jaskell The library is still developing rapidly , I have basically made some revisions every month in recent years . Teaching demonstrations and documentation , It can only be solved by investing a lot of work , There is no shortcut. .
Last , Thank you for your comments and suggestions , You are my driving force .

原网站

版权声明
本文为[ccat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210523395194.html