Fork me on GitHub
#exercism
<
2023-10-12
>
roelof11:10:28

@slipset then I hope she is doing better then me . I did now some 12 and im very stuck at solving the rest

roelof12:10:21

a question

roelof12:10:17

Im now busy with the space_age challenge But I wonder what is the best way to link planets to a factor. So I can use the factor in a calculation

Bobbi Towers12:10:05

I think that is the one which makes sense to use a macro, actually

roelof12:10:33

oke, then I have to dive into macros

Bobbi Towers12:10:56

Because the tests expect you to have a function for calculating the time on each planet

Bobbi Towers12:10:18

(a function for each planet)

roelof12:10:52

yep , I see that when I open the challenge. I see a lot of methods. One for every planet

roelof12:10:15

but I mean more how to store the planet name and the factor

Bobbi Towers12:10:02

when in doubt, use maps

Bobbi Towers12:10:24

I mean... you could write 9 different functions, but using a macro makes it so you only have to write one

Bobbi Towers12:10:24

Another way I've seen that avoids macros, and also avoids having to write 9 functions, is to use intern: https://clojuredocs.org/clojure.core/intern With that, you can pass a namespace, symbol name, and function body and will define the appropriate function

roelof13:10:13

What does this vague error message mean ;

An unexpected error occurred:
sci.impl.fns$fun$arity_0__1162 cannot be cast to java.lang.Number
with this code :
(defn seconds_year_earth
  []
  31557600
 )

 (defn conversion_ratios
   "returns the factor for the seconds a year for a planet"
   [planet]
    {
     :mercury 0.2408467 
     :venus  0.61519726 
    }
   )

(defn on-earth 
  [seconds]
  (/ seconds seconds_year_earth))

(defn on-mercury 
  [seconds]
  (*(on-earth seconds)  (conversion_ratios :mercury)))

borkdude13:10:16

you are trying to use a function as a number in (/ seconds seconds_year_earth)

roelof13:10:13

sometimes clojure makes me crazy

roelof13:10:30

I try to use the output of that function

roelof13:10:43

now find out how to take the value out of a map for a key

roelof16:10:37

any hints ?

slipset19:10:28

I’d argue that your conversions-ratio function (fn) is a bit unnecessary. In Clojure maps acts as functions of their keys so you can do the following:

(def conversion-ratios {:mercury 0.2408467 :venus 0.61519726})
Then to get the conversion-ratio for :mercury you simply do:
(conversion-ratios :mercury)

roelof19:10:38

Thanks will change it

slipset19:10:32

A thing that we both find difficult is the numbers stuff. It’s quite mathy, especially for a 13 year old (who might not be the target audience) but also for a 50something who’s forgotten most of his maths.

slipset19:10:24

I really enjoyed the robot thingy. It sounds really complicated when reading but we managed to make a rather neat solution with reduce

slipset19:10:15

The cool thing with doing it with reduce was that on first go we got the wrong answer (we did the exercise on paper first), so we switched to reductions and could see exactly where we’d done the mistake.

👍 1
roelof19:10:04

oke, I was stuck at the age-planet challenge but with some help of this channels I think I found a way to solve things

roelof19:10:37

With the robot thing , you mean the robot-name or the robot-simulator challenge ?

roelof19:10:33

I know the feeling with maths. Im 56 and math at school I was fairly good at

Bobbi Towers20:10:57

One project I've been planning is a gentle maths course using Clojure for young people, or older folks who have either forgotten or never learned it in the first place, like me

Bobbi Towers20:10:07

I'm not sure if this would be a fit for Exercism though. They tried to do something similar in the Julia track, but it was never finished.

Bobbi Towers20:10:35

Jeremy, the CEO, said that it wasn't likely to be viable because it strayed too far from the pedagogical style that Exercism uses. As I recall it involved the student building up over several exercises, a mini maths library. But this is something that I'm going to build in any case, because I think it's really important.

slipset20:10:11

Again, perhaps not the target audience, but the language of the exercises seem a bit theoretical for my 13 year old. Like, on strings, > A string in Clojure is a Java string, which is an object that represents immutable text as a sequence of Unicode characters (letters, digits, punctuation, etc.) and is defined as follows: is the introduction. There were so many questions asked when she read this sentence. Also, IMO, so much information here that she didn’t need in order to do the exercises or to learn about strings. Please do tell me to shut up if I’m rambling about stuff that is not interesting.

Bobbi Towers20:10:06

The feedback is much appreciated 🙂 The target audience of Exercism is indeed people who have experience in at least one other language

slipset20:10:08

🙂 My daughter started on the Python track, but I got tired of the whitespace stuff and switched her over to Clojure 🙂

slipset20:10:28

So I guess she has “experience” in at least one other language.

Bobbi Towers20:10:34

For awhile they were kicking around an idea for a whole new "Learn to Code" platform to address this gap

slipset20:10:25

But, she is really enjoying this, and she’s working on the problems on her own, and I get to help her. So my comments are mostly nitpicks.

slipset20:10:01

She’s also found an online Clojure repl where she tries out her solutions when the tests don’t pass 🙂

Bobbi Towers20:10:33

I wrote a REPL plugin for the Exercism editor that uses SCI, but unfortunately it was never added to the site

slipset20:10:51

I got a bit annoyed when she was working on the “bird watcher” because I suggested a solution like:

(defn inc-bird [birds]
  (conj (vec (butlast birds)) (inc (last birds))))
Which made me have to explain to her how conj works differently for lists and vectors (which she seemed to grasp) But then later I realized that the suggested solution would be with update which I hadn’t even thought about.

slipset20:10:10

and I guess reaching for butlast should have been a sign for me to consider another solution 🙂

Bobbi Towers20:10:51

It was a challenge to port some of those exercises, because they were written for other languages and it was often awkward to make it work in Clojure without totally reworking them

slipset20:10:19

Ya, I can see that some of this stuff is a bit forced or something in Clojure. Like “tracks on tracks” has a lot of fns which are not really that useful in Clojure. Like add-language is a fn I’d probably never write, as that’s basically conj

Bobbi Towers21:10:05

Exactly, I'm not a fan of that exercise because it's just having you shadow core functions. And the final task is best solved with a threading macro but those haven't been taught yet at that point

Bobbi Towers21:10:51

My plan is to make a different exercise for lists, and rework that one to teach threading macros

slipset21:10:47

Interestingly this is our solution:

(defn learning-list
  "Creates an empty list, adds Clojure and Lisp, removes Lisp, adds
  Java and JavaScript, then finally returns a count of the total number
  of languages."
  []
  (-> (new-list)
      (add-language "clojure")
      (add-language "lisp")
      (remove-language)
      (add-language "Java")
      (add-language "JavaScript")
      (count-languages)))
I had to introduce the threading macro here, because otherwise she would have rage-quit Clojure, and we couldn’t have that. The concept of the threading macro was easy for her to grasp. I didn’t use the m word, I just told her what it did. She asked for the as-> thread, but I told here we don’t want to have a thing like that, -> and ->> suffices 🙂

Bobbi Towers21:10:59

I'm glad you managed to get through it 🙂 I think I might do some work on this today

slipset20:10:03

Anyways, thanks for the work you’re putting in. As I said, Una is really enjoying this, and it’s really fun to work with her on them.

Bobbi Towers20:10:59

That's great to hear 🙂