# Dev Log 2022-07-15 ## Building a ZeroMQ client/server hello world Setting up a C development environment. Let's go with [[Doom Emacs]]. I enabled `(cc + lsp)` in `~/.doom.d/init.el`. Let's create `~/code/wesen/kv-store` and use that for now. I used `M-x compile` and then the `make hello` command to run the hello world. [[Conan]] would be a good tool to learn. While I created my compilation database with [[CMake]], there is a tool called "Bear" that seems to do the same. Why two tools? - [GitHub - rizsotto/Bear: Bear is a tool that generates a compilation database for clang tooling.](https://github.com/rizsotto/Bear) There seems to be a good resource here, maybe, on how to configure [[Language Server Protocol|LSP]] for [[Emacs]] (in particular, [[clangd]]): - [Configuring Emacs as a C/C++ IDE - LSP Mode - LSP support for Emacs](https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/) We are copying the C example server from the [[ZeroMQ]] guide: - [1. Basics | ØMQ - The Guide](https://zguide.zeromq.org/docs/chapter1/) We got a basic server/client running. What to do next: - continue going through ZeroMQ guide? - build a BTree? - build a minimal lisp in C? - Build a LSMTree? - Add KV support to the client? - See how we could do many reads single write? ## PUB SUB in ZMQ Next example, PUB SUB for weather updates. This actually sends like 5M messages / second (if no subscriber). We at first thought it was slow, but not, it generated (and filtered) a shitton of messages. ## Pairing on parser combinators with Marcin ```fsharp zeroOrMore<a'> : Parser<List<a'>> zeroOrMore digit : Parser<List<char>> concatenateChars : List<char> -> String (>>=) : M a -> (a -> M b) -> M b let tryMapP (fn : 'a -> Result<'b>) -> Parser<'a> -> Parser<'b> = _ let concatenateChars (l: list<char>): string = _ let parseInteger (s: string): Result<int> = _ let integer: Parser <int> = zeroOrMore digit // Parser<List<char>> |> tryMapP (concatenateChars |> parseInteger) // Parser<int> let integer : Parser<int> = let p = zeroOrMore digit // Result<string * List<char>> >>= (fun (remaining, listChars) -> match System.Int.32 (concatenateChars listChars) // Result<integer> | true, i -> Ok(remaining, i) | _ -> Nothing ) let separator = whitespace .>>. (pchar '=') .>>. whitespace let key = (until separator) let kv = key >>= (fun k -> separator .>>. genericString >>= (fun v -> Result(k, v))) let kv = do k <- key v <- separator .>>. genericString Result(k, v) end ```