Comments for A Curious Programmer https://curiousprogrammer.wordpress.com Thoughts on Perl and Emacs, technology and writing Mon, 18 Aug 2025 18:26:20 +0000 hourly 1 http://wordpress.com/ Comment on Loops in Ocaml by Kevin Damm https://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/#comment-34386 Mon, 18 Aug 2025 18:26:20 +0000 http://curiousprogrammer.wordpress.com/?p=647#comment-34386 You could make the Sequences example faster by not constructing the pairs explicitly and calculating the subordinate gcd results directly within seq_ij (so, only dealing with unboxed ints everywhere) — it is difficult to beat a loop structure and multiple-assignment with refs for speed. But it’s hard to beat chains of |> pipes for readability.

]]>
Comment on Loops in Ocaml by Kevin Damm https://curiousprogrammer.wordpress.com/2009/05/30/ocaml-loops/#comment-34385 Mon, 18 Aug 2025 17:24:40 +0000 http://curiousprogrammer.wordpress.com/?p=647#comment-34385 There’s also Sequences, which have the benefits of using less memory than iterating lists while keeping the benefits of folds and maps and writing code in terms of function application.

They can be a bit unwieldy when generating pairs, it may be tempting to construct the pairs from some function over their progression, like the following pair-of-ints-in-range-descending:

let all_pairs_desc a b : (int * int) Seq.t =
let upper = (max a b)-1 in
let lower = min a b in
let rec all_pairs_aux a b = fun () ->
if b >= lower
then Seq.Cons ((a, b), all_pairs_aux a (b-1))
else begin
if a > lower
then Seq.Cons ((a-1, a-1), all_pairs_aux (a-1) (a-2))
else Seq.Nil
end
in all_pairs_aux upper upper

..but we can make it more elegant than that, using sequences-of-sequences and flat_map. Following your `count` example of counting pairs with no common denominator, using the `gcd` function from above:

let coprime (x, y) = (gcd x y == 1) in
let int_range from until =
Seq.ints from |> Seq.take_while (fun x -> x <= until)
in
let seq_ij i =
int_range (i/3+1) (i/2) |> Seq.map (fun j -> (i, j))
in
int_range 5 10000
|> Seq.flat_map seq_ij
|> Seq.filter coprime
|> Seq.length

]]> Comment on Pretty Printing XML by Christine Barr https://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-34384 Mon, 10 Mar 2025 18:23:21 +0000 http://curiousprogrammer.wordpress.com/?p=276#comment-34384 Lovvely post

]]>
Comment on Emacs Utility Functions by Ellen Delgado https://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-34383 Sat, 16 Nov 2024 06:00:35 +0000 http://curiousprogrammer.wordpress.com/?p=725#comment-34383 Very nice bloog you have here

]]>
Comment on What is the Datatype Behind an Emacs Buffer by Revolver Themes https://curiousprogrammer.wordpress.com/2010/09/28/emacs-buffer-datatype/#comment-34381 Tue, 14 May 2024 07:05:16 +0000 http://curiousprogrammer.wordpress.com/?p=1278#comment-34381 Hello mate great blog postt

]]>
Comment on Pretty Printing XML by Pretty printing XML files on Emacs - PhotoLens https://curiousprogrammer.wordpress.com/2009/02/27/pretty-printing-xml/#comment-33792 Tue, 22 Feb 2022 09:28:58 +0000 http://curiousprogrammer.wordpress.com/?p=276#comment-33792 […] pasting xml and you find your terminal is chopping the lines in arbitrary places you can use this pretty printer which fixes broken lines […]

]]>
Comment on Plack and Auto-Restart by hoppfrosch https://curiousprogrammer.wordpress.com/2010/03/22/plack-auto-restart/#comment-32852 Thu, 15 Aug 2019 09:35:22 +0000 http://curiousprogrammer.wordpress.com/?p=762#comment-32852 Right now, the Windows fix is still not available in Plack distribution.

]]>
Comment on First Steps with AnyEvent by Honza Einnews https://curiousprogrammer.wordpress.com/2010/04/18/first-steps-with-anyevent/#comment-32684 Tue, 25 Jun 2019 18:44:57 +0000 http://curiousprogrammer.wordpress.com/?p=802#comment-32684 Did you know that the return value from the prepare function of the tcp_server is the backlog size for listen()? I didn’t. Makes a lot of difference in performance, as if you don’t return anything it’s 1 and if you return false it’s 128.

]]>
Comment on Which Language Should You Choose? by brdjns https://curiousprogrammer.wordpress.com/2013/11/14/which-language/#comment-32651 Mon, 10 Jun 2019 01:14:38 +0000 http://curiousprogrammer.wordpress.com/?p=1741#comment-32651 Python and Ruby seem pretty widely used on the web these days, too.

]]>
Comment on Error Handling in Emacs Lisp by Hi-Angel https://curiousprogrammer.wordpress.com/2009/06/08/error-handling-in-emacs-lisp/#comment-32307 Wed, 06 Feb 2019 21:20:30 +0000 http://curiousprogrammer.wordpress.com/?p=665#comment-32307 I’m being told on mailing list that using this usage

(condition-case err

(‘error (…)))

Is wrong, and should instead be

(condition-case err

(error (…)))

I.e. remove the quote.

]]>