Show Sidebar

This is the blog of Sam Marshall.

On this page you can see the latest blog updates. For further articles, please use the search bar or navigate through the blue tags.

Most recent articles or updates:

2020-12-09: capturing locations within a web page

When I read a book and take notes, I make a little "idea index" with a reference back to what page the idea was covered on. I like to make the same index when I'm reading web articles. This workflow stumbles a little with web pages though. It's difficult to refer to a position within an article, whether rough (like a page marker) or specific (like a ebook location).

I'm currently getting around this by using a little bookmarklet that logs out the percentage scrolled down the page. This works in a 'for now' kind of way, but it isn't ideal.

I'd like a more secure mark of where I am in a page that isn't influenced by how big I've made my browser today or whether I'm on my desktop or my laptop. I'd also like a way of jumping back to a specific location by pasting a location into the page. Ideally, the tool would be open source too. I don't know of any tool of this kind, but it would be useful to me.

If I were to build something like this, I might have the user select a html element within the page, and count paragraph tags within that section to deterministically generate an identifying number for each paragraph. This only works if the page doesn't change, of course, but I tend to take a snapshot of pages I read (sometimes two, I use both and zotero) so this isn't a huge concern for me, I can always use the snapshot.

2020-12-02: The Little Schemer. ch 4. part 2. subtracting natural numbers

How do we define subtraction in terms of sub1? Based on the content of this book so far, it's likely got something to do with recursion.

Again, going from the solution to o+ we can guess that we'll be asking a series of questions with cond, and that we'll start by checking for 0. We know that there'll be 2 arguments, n and m. We'll need to subtract m from n, and we'll need to stop when one of them hits 0. This kinda tells us that both arguments are gonna need to be subtracted.

If we were using real numbers, I'd be worried here because we only have sub1 to work with, and negative numbers make that complex - but with natural numbers, subtracting both works just fine. We'll never have to deal with 6 - -3 or whatever.

In essence, what we need to do here is (sub1 n) =m= times. Let's give that a go:


(define o-
  (lambda (n m)
      ((zero? m) n)
      (else (o- (sub1 n) (sub1 m))))))

(o- 14 3)
(o- 17 9)	  



That seems to work pretty well. Looking at the definition in the book, there's the same pattern again - they define o- in the same way that I have, but the last line is

 (else (sub1 (o- n (sub1 m))))	  

I'm a little concerned that I'm missing some point or other here, but it could be just that I think in a different way. I'm gonna leave it, and hope that it doesn't come back to bite me!

2020-12-02: chapter 4. number games

quick note: I'm using racket scheme locally because, well, I already had it installed. Starting at the beginning of the /number games/ chapter and working through it in a semi-logical order that should make sense if you have the book in front of you. I hope.

Read the whole article ...