Recent submissions

Comment · 2 years ago
I seem to be missing something, thus thank you for taking your time

> Wouldn't that be like if in C, you had to write the arguments in reverse order of the format string, like this?

Exactly and that's not what we want

Let's go through this step by step:

sprintf "%s %d" returns a function, taking a string and returning a function taking an integer and returning a string, right?

sprintf "%s %d" "hello" returns a function taking an integer, returning a string, right?

sprintf "%s %d" "hello" 42 returns a string, right?

Thus my intuition of the return type of sprintf "%s %d" would be string -> (int -> string) not int -> (string -> string)

Comment · 2 years ago
No
Comment · 2 years ago
Yes, but the final result is out_str, not a forward to console, isn't it?

Either way, the format string discussion for the printf familiy of functions is very similar between them

Comment · 2 years ago
I'm not that familiar with syntax of functional programming languages.

Isn't Int -> String -> String a shorthand for Int -> (String -> String)?

Thus I would have assumed the first argument to the result of sprintf "%s %d" would be an integer, then a string and the final result would be a string.

But the invocation would be sprintf "%s %d" "hello" 42, wouldn't it?

Comment · 2 years ago
Nice writeup! It would be helpful to seen an actual invocation of the new sprintf function

I know it's supposed to be pseudo code and most likely it's something like sprintf "% world %d" "hello" 42 but I got a little confused by the type list being backwards from what I expected

Comment · 2 years ago
This is just a choice of having to provide an output buffer to the function instead of returning a new buffer since it's easier to inject custom allocator behaviour that way

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton