You are viewing a single comment's thread from:

RE: Daily Coding Problem - My Attempt to Become a Better Problem Solver

in #technology6 years ago

car should be a function that takes in something made by cons to output the first arg. Right now your car is set to the "pair" object itself, whereas it should instead be a function that acts on pairs.

Are you saying this because the question uses it as a function in it's asking?

In other words, right now if I typed car(cons(8, 9)) I would get something weird.

Why would you execute that though when the code sets it as an object? car = cons(8, 9) executes as expected. Unless you are referring to the question stating car as a function in which case I get what you are saying.

That being said, I am doing this to learn not get a perfect answer by semantics. I never claim to know "the best" way to achieve the desired result. I am just looking to learn new concepts and ideas.

Sort:  

Unless you are referring to the question stating car as a function in which case I get what you are saying.

Right, perhaps the problem isn't really clear in its goals. It's trying to get us to create an API around dealing with "pairs". Here they chose to represent a pair as a function itself, which itself is weird. They want you define accessors assuming this representation.

car here should be generic. It should be able to take anything generated by cons and generate the correct result.

But there is an important lesson in here. It's about abstraction, the separation between the interface (cons, car, cdr) from the implementation (functions that act on other functions).

On a side note: it's funny to say "car should be a function" because it is a function. But it's not the correct function.

This post was not about my crappy coding but about the love of learning mate
🤣🤣🤣

Doh. I know it wasn't the main part of your post, but this jumped out at me. Especially since it's a problem I'm very familiar with. These kinds of toy problems. I'm quite happy that someone else is doing them hahaha!

You did say you wanted to clean up this solution a bit too though, so I wanted to make sure you knew that it's not quite what they were looking for.

Right on man. I'm working on a refactor that runs the functions as the question alludes to. I need to read things more carefully lol.

Coin Marketplace

STEEM 0.31
TRX 0.11
JST 0.034
BTC 64852.72
ETH 3178.07
USDT 1.00
SBD 4.20