The Boring Stream - #007
Cover Image

The Boring Stream - #007

In #TheBoringStream I spent part of the night working on some exercises using #Lisp. (Exercises 1.1 - 1.5)


So far I find it pretty easy to understand the contents of the book and the language is very easy to pick up, syntax-wise.

The only thing that threw me off during this first batch of exercises was guessing the difference between how applicative/normal-order interpreters will evaluate the following code:

(define (p) (p)) ;; p will return itself?

(define (test x y)
  (if (= x 0) 0 y))

(test 0 (p))        

After spinning my wheels for about 5 minutes I realized that the difference is that when x = 0, normal-order never needs to evaluate (p) in the test, so will return the result 0. Whereas with applicative interpretation (p) will always get evaluated and because it returns itself it creates an infinite loop.

This was tricky because Lisp didn't throw any sort of runtime error or yell at me, so without debugging it's kinda tricky to know exactly whats going on.

In Dr.Racket (the IDE for LISP/Scheme) there was a subtle signifier that something was odd about the code when it ran. Upon closer inspection there was some weird indicator flickering extremely fast (which I guess is a way to indicate that the runtime is having to offload a lot of memory very quickly).

Turns out this area of the UI shows the activity of the Garbage Collector.

Lisp Interpreter Garbage Collector

Another question that was interesting was:

Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.

Here was my solution:

(define (myFinalFun a b c)
  (cond
    ((and
      (< (+ a c) (+ b c))
      (> (+ b c) (+ a b)))
     (sum (square b) (square c))) ; Handles for if b, c is largest combo
    ((and
      (> (+ a c) (+ b c))
      (> (+ a c) (+ a b)))
     (sum (square a) (square c))) ; handles if a, c is the largest
    (
     (sum (square a) (square b))) ; fall-through for a, b
    ))        

This isn't the most optimal solution, but it's what i came up with on my own- and I'm totally proud of it.

???? A better solution can be found here (spoiler)


If you wanna see the SUPER BORING 2hr stream where I worked on these and other things from Chapter 1 of Structure and Interpretation of Computer Programs, check out the link below:


?? Watch Stream:?https://lnkd.in/e6PnBiK6

?? Repo:?https://lnkd.in/eGCrhsSm

要查看或添加评论,请登录

?? ..的更多文章

  • Leadership: The Obstacle Is the Way

    Leadership: The Obstacle Is the Way

    (This was originally written in September, so please excuse an places where this might feel out-of-date). Wassup ya'll,…

    2 条评论
  • The Death of Tech Jobs (2022-2024)

    The Death of Tech Jobs (2022-2024)

    Written and Edited by ?? ..

  • Ace Leadership: Reflection on Session #1

    Ace Leadership: Reflection on Session #1

    Hey y'all, It's me again..

    6 条评论
  • TeamMaker3000 (Version 3) - Major Upgrade!

    TeamMaker3000 (Version 3) - Major Upgrade!

    ???? Github: https://github.com/MaterDev/TeamMaker3000 I'm thrilled to announce a significant update to TeamMaker3000…

  • TeamMaker3000 (Version 2)

    TeamMaker3000 (Version 2)

    ?? GitHub Repo: https://lnkd.in/gVi37-mT TeamMaker3000 is a straightforward CLI application that creates randomized…

    1 条评论
  • Prompt-Primers (ChatGPT)

    Prompt-Primers (ChatGPT)

    What is a Prompt-Primer? A prompt-primer is essentially a structured document designed to provide context for OpenAI's…

    8 条评论

社区洞察