5 ms·
I really liked this treatment of first-class functions. It started off slow, with a lot of trivial, contrived examples that should be obvious to anyone who has
by sirclueless 14y ago
I really liked this treatment of first-class functions. It started off slow, with a lot of trivial, contrived examples that should be obvious to anyone who has ever seen first-class functions in any language. But then there were some very pragmatic patterns, with standard library examples, that used recursive function types and methods on function types to build some very neat APIs. Building a lexer out of a recursive function type actually sounds like a really cool thing to try, if I find some free time I want to try it without looking at Go's standard library `text/template` lexer and see how it compares.
- jbarham 14y ago> Building a lexer out of a recursive function type actually sounds like a really cool thing to try Rob Pike did just that for Go's text/template package (http://golang.org/pkg/text/template/ http://golang.org/pkg/text/template/). See the source lexer source code at http://golang.org/src/pkg/text/template/parse/lex.go http://golang.org/src/pkg/text/template/parse/lex.go and note that stateFn is defined recursively. There's a video by Pike describing how he built the parser at http://www.youtube.com/watch?v=HxaD_trXwRE http://www.youtube.com/watch?v=HxaD_trXwRE.