Sign in

Vladimir Keleshev

@keleshev.com
806 followers 438 following 57 posts

OCaml programmer, author of Compiling to Assembly from Scratch: keleshev.com/cas Copenhagen

PostsRepliesMedia
Reposted by Vladimir Keleshev
CF Bolz-Tereick @cfbolz.bsky.social · 21/05/2025
@keleshev.com not sure whether you already saw, but Compiling to Assembly from Scratch got a review in c't 9/25 (the largest German IT magazine)
151
Vladimir Keleshev @keleshev.com · 15/05/2025
Onfim was not the greatest artist, but why do you have to rub it in like that?!
A probable self portrait by Rafael, drawn when he was around the same age (1499), Ashmolean Museum, Oxford, UK.
120
Vladimir Keleshev @keleshev.com · 02/05/2025
Glad to see that Python finally got more dedicated syntax for type annotations in 3.12. Now it looks quite decent. So I updated the Python version of the book's compiler to use the new syntax: github.com/keleshev/com...
@dataclass
class Parser[T]:
    _parse: Callable[[Source], ParseResult[T] | None]

    def parse(self, s: Source) -> ParseResult[T] | None:
        return self.__dict__['_parse'](s)
    
    @staticmethod
    def regexp(regexp: Pattern) -> Parser[str]:
        return Parser(lambda source: source.match(regexp))

    @staticmethod
    def constant[U](value: U) -> Parser[U]:
        return Parser(lambda source: ParseResult(value, source))
230
Vladimir Keleshev @keleshev.com · 04/01/2025
In original docopt, square brackets mean each item is optional. For example, `prog [<x> <y>]` is the same as `prog [<x>] [<y>]`. Weird or not? To make both-or-nothing you need to group them like `prog [(<x> <y>)]`. You know why this was the design decision?
120
Vladimir Keleshev @keleshev.com · 02/01/2025
😲
010
Vladimir Keleshev @keleshev.com · 01/01/2025
Power new Raspberry Pis is tricky nowadays, isn't it? Pi 4 needs 15W at 5V, but normally hubs/screens/power supplies advertise their max power delivery at a higher voltage, so there's no way to know without trying.
230
Vladimir Keleshev @keleshev.com · 22/12/2024
Not going to upgrade kids to Raspberry Pi 500 (from their Pi 400). Waiting for the next Pi X00 series for four years, of course it's a disappointment.
100
Vladimir Keleshev @keleshev.com · 22/11/2024
Killer feature! In OCaml you would have to opam install ppx_deriving first. But I know where this is going… type classes… that’s where OCaml really lacks. But if I had (and I had) to pick type classes vs. error handling using polymorphic variants, I’d choose the latter.
2141
Reposted by Vladimir Keleshev
Katiuska Pino @katiuskapino.com · 22/11/2024
+600 of you are following me! It's amazing! 🌱 Let's do a little introduction. Hi! 👋 I'm Katiuska, I'm Venezuelan and I like to draw kids and sometimes write my own stories. I'm available for freelance work and also looking for representation. 🖍️ Portfolio ⭐ WIP's and Tips
091
Vladimir Keleshev @keleshev.com · 20/11/2024
rec is my favorite in OCaml—lets me find out that the function is recursive before reading it—super important, I think. Even better—mutually recursive functions with let rec…and—you see mutual recursion at birds eye view.
141
Vladimir Keleshev @keleshev.com · 20/11/2024
Excellent! Now use fold. gist.github.com/keleshev/36e...
  let size = fold ~leaf:(const 1) ~node:(+)
  let height = fold ~leaf:(const 1) ~node:(fun l r -> 1 + max l r)
  let to_string leaf = fold ~leaf ~node:(sprintf "(%s %s)")
  let reverse = fold ~leaf ~node:(fun l r -> node r l)
  let map f = fold ~leaf:(f >> leaf) ~node
  let bind f = fold ~leaf:f ~node
  let iter f = fold ~leaf:f ~node:(fun _ _ -> ())
  let for_all predicate = fold ~leaf:predicate ~node:(&&)
  let exists predicate = fold ~leaf:predicate ~node:(||)
2120
Vladimir Keleshev @keleshev.com · 18/11/2024
Making parser combinators in OCaml that do not allocate (except when you explicitly do so, e.g. constructing an AST) is tricky. The usual advice I'm hearing is to use CPS in order to "return" multiple arguments. But in practice, even sequencing two parser creates closures that capture variables.
161
Vladimir Keleshev @keleshev.com · 13/11/2024
Every time I see a Bluesky notification, my first thought: Banksy followed me!
110
Reposted by Vladimir Keleshev
Katiuska Pino @katiuskapino.com · 22/09/2024
It's not a #kidlit book but the print version of Compiling to Assembly is available! I worked on this book a couple of years ago and you can finally get the printed book which includes 15 chapter illustrations. Thank you Vladimir for asking me to be part of this project! #STEM #TypeScript
programming book picture
1114
Vladimir Keleshev @keleshev.com · 01/11/2024
The grammar. The parser. I love doing this.
    # Recursive definition of pattern
    required <- "(" _ pattern ")" _
    optional <- "[" _ pattern "]" _
    confined <- required / optional / atom _
    multiple <- confined ("..." _)?
    sequence <- multiple multiple*
    junction <- sequence ("|" _ sequence)*
    pattern <- junction  let rec pattern x =
    let required = token "(" %> pattern <% token ")" in
    let optional =
      let+ pattern = token "[" %> pattern <% token "]" in
      Pattern.Optional pattern in
    let confined = required / optional / atom in
    let multiple =
      let+ pattern, ellipsis = confined <%> maybe (token "...") in
      if ellipsis = None then pattern else Pattern.Multiple pattern in
    let sequence =
      let+ first, rest = multiple <%> zero_or_more multiple in
      List.fold_left Pattern.sequence first rest in
    let junction =
      let+ first, rest = sequence <%> zero_or_more (token "|" %> sequence) in
      List.fold_left Pattern.junction first rest in
    junction x
120
Vladimir Keleshev @keleshev.com · 01/11/2024
Hello Bsky! I like OCaml and Compilers. You might know me from docopt or the book Compiling to Assembly from Scratch. github.com/docopt/docopt keleshev.com/cas
3120