nikluk profile
nikluk
nikluk
I write at https://nicholasderoj.com/ & https://nikluk.com (Swedish)
Subscribe
Send Message

Share

Tell people about this page...

Subscription Tiers

$2
per month
Ss logo sign mono back
Small Supporter

If you want to support with a small amount. $2 a month is doable for most.

0 subscribers   
Unlock
$5
per month
Ss logo sign mono back
Standard Supporter

For the standard supporter - ok for most who want to give financial support.

0 subscribers   
Unlock
$25
per month
Ss logo sign mono back
Big Supporter

For ppl who want to support more.

0 subscribers   
Unlock
$50
per month
Ss logo sign mono back
Superstar Supporter

This is only for superstar subscribers who appreciate what I do.

0 subscribers   
Unlock

Features

  • Posting on nicholasderoj.com

Recent posts

Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

## Ch 7, Notes A *variable* is a connection between a name and a value. Formal parameter is a na...

Comments
Like(0)
Dislike(0)
This post belongs to a locked $2 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

Simply Scheme, Chapter 6, Exercises

Comments
Like(0)
Dislike(0)
This post belongs to a locked $2 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk
Public post

Simply Scheme: Chapter 6, Exercise 6.13


This is a free sample of one Scheme exercise that I did so that you can see what some of my solutions look like.

You can find most answers to Simply Scheme on the web for free. A reason why you should pay $2 to get my solutions is that I document my thinking process, my mistakes and how I solved them.

From chapter 4 and onwards I write out my thinking process and mistakes.
For chapter 1-3 there are only my solutions.

This post has been published on my blog as well. The formatting on this post differs from my other Simply Scheme posts found under $2 tier.

From blogpost:
---

My main goal right now is just to learn to code. My main goal right now is not to write the best code that I possibly can.

By first focusing on just learning to code in Scheme I can focus on only that and not on writing the best possible code. This helps me to avoid overreaching (learn to code and write awesome code at the same time) and lets me improve one step at a time. Once I get better at fundamental coding in Scheme, I can focus on writing better code.

Below is how I dealt with exercise 6.13, ch 6, in Simply Scheme. My thinking process, my mistakes and how I solved them.

All my Scheme exercises can be found on Subscribestar in the $2 tier.
From chapter 4 and onwards I write out my thinking process and mistakes.
For chapter 1-3 there are only my solutions.


6.13 Write a better greet procedure that understands as many different kinds of names as you can think of:

> (greet ‘(john lennon))
(HELLO JOHN)

> (greet ‘(dr marie curie))
(HELLO DR CURIE)

> (greet ‘(dr martin luther king jr))
(HELLO DR KING)

> (greet ‘(queen elizabeth))
(HELLO YOUR MAJESTY)

(greet ‘(david livingstone))
(DR LIVINGSTONE I PRESUME?)
I will just focus on the examples given in the exercise. I will not come up with new kinds of names.

Thinking process:
1. A title will always be in front of a persons actual name – eg “dr“, “queen“, “king“.
2. For “dr” greet as “dr” followed by last name. But only if last name is not “jr” / “sr“. If last name is equal to “jr” / “sr” then use the second last name.
3. For “queen” / “king” greet as “your majesty“.
4. Don’t know how to presume if someone is a dr without making a list of all ppl that are dr.


Step 1:

Test the core concept.

(define (greet name)
    (if (equal? (first name) 'dr)
        (se '(hello dr) (last name))
        #f))
Works.



Step 2:

Add more “if” procedures. Add “king” / “queen“.

(define (greet name)
    (if (equal? (first name) 'dr)
        (se '(hello dr) (last name))
        (if (equal? (first name) (member? '(king queen)))
            (se '(hello your majesty))
            (se 'hello (first name)))))
Did not work.
member?” lacking one of its two arguments.

(define (greet name)
    (if (equal? (first name) 'dr)
        (se '(hello dr) (last name))
        (if (equal? (first name) (member? (first name) '(king queen)))
            (se '(hello your majesty))
            (se 'hello (first name)))))
Did not work.
Prints “(hello queen)


Test 1:

Effort to find the problem.

(define (greet name)
    (if (equal? (first name) (member? (first name) '(king queen)))
            (se '(hello your majesty))
            #f))
Prints “#f


Test 2:

(member? 'queen '(king queen))
Prints “#t

I think my mistake is that I am mixing the wrong domains.
member?” is a predicate (a function that returns either #t or #f). Thus “(equal? (first name) (member? (first name) ‘(king queen)))” would be evaluated as (step by step evaluation):
1. (equal? (first name) (member? (first name) ‘(king queen)))
2. (equal? ‘queen (member? ‘queen ‘(king queen)))
3. (equal? ‘queen #t)
4. #f

My “king” / “queen” code is unnecessarily confusing. I can just eliminate the “equal?” part.

(define (greet name)
    (if (equal? (first name) 'dr)
        (se '(hello dr) (last name))
        (if (member? (first name) '(king queen))
            (se '(hello your majesty))
            (se 'hello (first name)))))
Works.



Step 3:

Fix “jr” / “sr“.
jr” / “sr” only matters for ppl that are “dr” as “jr” / “sr” is at the end of the name.

(define (greet name)
    (if (equal? (first name) 'dr)
        (se '(hello dr) (last name))
        (if (and (equal? (first name) 'dr) (member? (last name) '(sr jr)))
            (se '(hello dr) (last (bl name)))
            (if (member? (first name) '(king queen))
                (se '(hello your majesty))
                (se 'hello (first name))))))
Did not work.
Prints “(hello dr jr)” for “> (greet ‘(dr martin luther king jr))“.

It is because the first “if” procedure is true. I need to change places with the first and the second procedure. That should fix it.

(define (greet name)
    (if (and (equal? (first name) 'dr) (member? (last name) '(sr jr)))
            (se '(hello dr) (last (bl name)))
            (if (equal? (first name) 'dr)
                (se '(hello dr) (last name))
                (if (member? (first name) '(king queen))
                    (se '(hello your majesty))
                    (se 'hello (first name))))))
Works.


I don’t know how to do the following without making a list of all ppl who could be considered doctors in advance.

> (greet ‘(david livingstone))
(DR LIVINGSTONE I PRESUME?)
A list of that would be something like:

(if (equal? name '(david livingstone))
        (se 'dr (last name) '(I presume?))
        ...))
Then it would look something like this:

(define (greet name)
    (if (and (equal? (first name) 'dr) (member? (last name) '(sr jr)))
            (se '(hello dr) (last (bl name)))
            (if (equal? (first name) 'dr)
                (se '(hello dr) (last name))
                (if (member? (first name) '(king queen))
                    (se '(hello your majesty))
                    (if (equal? name '(david livingstone))
                        (se 'dr (last name) '(I presume?))
                        (se 'hello (first name)))))))
Works.
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

Simply Scheme, Chapter 5, Exercises

Comments
Like(0)
Dislike(0)
This post belongs to a locked $2 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

Simply Scheme, Chapter 4, Exercises

Comments
Like(0)
Dislike(0)
This post belongs to a locked $2 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

Simply Scheme, Chapter 3, Exercises

Comments
Like(0)
Dislike(0)
This post belongs to a locked $2 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

Access to all of my Idea Trees (complete and incomplete)I make idea trees to help me think better...

Comments
Like(0)
Dislike(0)
This post belongs to a locked $5 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk

Idea tree on complexity (draft)A tree on what I am learning on keeping stuff simple - in an organ...

Comments
Like(0)
Dislike(0)
This post belongs to a locked $2 tier.
Unlock Tier
Ed8449d3 8b65 4e01 a23a b250a55bae2b 120x120 153x0 687x687
nikluk
Public post
Welcome!

Ideas are powerful and we are often wrong. To gett better, we should welcome criticism of our ideas so that we can find and correct our mistakes.

I like Ayn Rand, Ludwig von Mises, David Deutsch, Richard Feynman, and Elliot Temple.

---

If you find value in what I do consider donating a sum. Both a one time donation and recurring donations are appreciated and enable me to dedicate more time to write.

---

I write at https://nicholasderoj.com/


The subscription gives you:
  • Full, unlimited access to Star's profile content - to view it online or to download it to future use.
  • Support your Star by contributing – one-time or recurring.
  • You can cancel this subscription at any time.
This website uses cookies to improve your experience while you navigate through this website. Continue to use this website as normal if you agree to the use of cookies. View our Privacy Policy for the details. By choosing "I Accept", you consent to our use of cookies.