arifshaikh.astro
2021-10-25 08:37:10

How to get the nth element of a list? Equivalent to (nth n lst) from emacs-lisp


sorawee
2021-10-25 08:39:13

list-ref


gmauer
2021-10-25 14:27:10

I’ve been poking this leetcode problem in a literate programming style every few nights for the last few weeks and just finished it https://github.com/togakangaroo/daily-programmer/tree/master/island-perimeter

Any kind soul want to give me a free code review in exchange for internet good samaritan points?


gmauer
2021-10-25 14:29:51

I’m more concerned about this being idiomatic than I am about the general approach. I know the approach itself isn’t the slickest. I did spend waay too long last night lying in bed thinking how I might simplify things with a convolution pass from a laplacian filter


gmauer
2021-10-25 14:34:34

apologies ahead of time for github’s org rendering being shitty. If you have a configured emacs and pull it down it is much nicer, but this is still legible


gmauer
2021-10-25 14:40:43

now that I think of it, I think there might be a subtle bug when an island forms a pincer that connects on a diagonal. Technically the rules allow that and I suspect it breaks my algorithm


soegaard2
2021-10-25 18:40:07

This is a great write-up!


gmauer
2021-10-25 18:42:35

thank you. I’ve been practicing trying to do this stuff in org for a while


soegaard2
2021-10-25 18:43:07

Random typo: indicies-of-cells-adjacent-to-move> -> indices-of-cells-adjacent-to-move>


gmauer
2021-10-25 18:44:04

dammit, I think I misspelled the word indices every time I wrote it in that document. Flyspell was yelling at me nonstop


soegaard2
2021-10-25 18:45:03

Note that (require racket/match) (require racket/format) can be written (require racket/match racket/format)


soegaard2
2021-10-25 18:48:25

You specifically mention that you are interested in being idiomatic. I think, you will see that most programs use “a vector of vectors” instead of a matrix to represent two-dimensional arrays. I like your approach though.


gmauer
2021-10-25 18:49:44

yeah, some of this was just me spiraling the rabbit hole of finding the right data structure. I do think a matrix is ultimately the most helpful one though since I can iterate the indicies as a flat list


gmauer
2021-10-25 18:49:50

that’s real helpful


soegaard2
2021-10-25 18:56:15

An alternative design would be to make #lang island-perimeter \| \| \| X \| \| \| \| X \| X \| X \| X \| \| \| X \| X \| X \| X \| \| \| X \| X \| X \| X \| \| \| \| \| X \| \| \| \| X \| X \| X \| \| \| expand into a module that contains (provide island) (define island <your-representation-of-the-island>) That makes it possible to write a program like: (require "example-1.rkt") (print-island island) (perimeter island) That is, if you are in a situation, where the data can be used in multiple ways, it makes sense to split the “parsing-into-a-data structure” and the “calculation” parts of the program.


gmauer
2021-10-25 18:56:57

oh yeah, I like that definitely


soegaard2
2021-10-25 18:58:20

That’s the way Scribble works internally. If you run a #lang scribble program, you get a module that exports an identifier doc which holds a representation of the input. Then the raco scribble command can render the documentation into various formats such as pdf or html from the same data structure.


soegaard2
2021-10-25 19:01:55

How was the experience of using org files to do this?


gmauer
2021-10-25 19:06:56

It’s ok. I’m pretty comfortable with org and parinfer which I rely on a lot. I am also good at vim keys so navigation is where I want it.

I did have to invent kind of my own ob-racket to make this work. The trick is that you have to emit modules like the reader and expander as adjacent files in the same directory so I had to write my own headers to do it


gmauer
2021-10-25 19:07:15

I should probably pull it out into its own extension so that its not tied to racket though


gmauer
2021-10-25 19:08:54

I think that overall the REPL-driven workflow works in a notebook and noweb is almost powerful enough to do everything I need it to. Being able to do stuff like pop out the editing window into a side-by-side and be able to execute that in a keystroke as I’m editing and having that write directly into the notebook on the other side was pretty nice


soegaard2
2021-10-25 19:10:40

Have you seen the blog posts of Jay? He also likes the literal programming style. https://jeapostrophe.github.io/


gmauer
2021-10-25 19:11:28

nope. Pretty old, but always down to read conway’s life articles :D


soegaard2
2021-10-25 19:12:25

It’s worth scanning the entire list: https://jeapostrophe.github.io/archive.html


gmauer
2021-10-25 19:12:54

cool, thanks!


ben.knoble
2021-10-25 21:09:59

Racket has a literal-programming lang that co-operates with scribble, IIRC


gmauer
2021-10-25 22:34:55

yup, thats the stuff soegaard2 was talking about above. I might look into that, but scribble only works with racket - whereas org works with all languages, isn’t going to render in a github document, and I’m not sure to what degree it integrates with emacs.


ben.knoble
2021-10-25 23:41:21

Well, renders to HTML isn’t bad, and probably could be made to work with other langs in racket, but that’s fair.