exercism

roelof 2023-10-12T11:43:28.608779Z

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

roelof 2023-10-12T12:27:21.807179Z

a question

roelof 2023-10-12T12:28:17.953519Z

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 Towers 2023-10-12T12:29:05.877989Z

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

roelof 2023-10-12T12:30:33.898649Z

oke, then I have to dive into macros

Bobbi Towers 2023-10-12T12:32:56.745299Z

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

Bobbi Towers 2023-10-12T12:33:18.716029Z

(a function for each planet)

roelof 2023-10-12T12:33:52.108989Z

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

roelof 2023-10-12T12:34:15.245529Z

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

Bobbi Towers 2023-10-12T12:38:02.661669Z

when in doubt, use maps

roelof 2023-10-12T12:40:53.517669Z

thanks

Bobbi Towers 2023-10-12T12:34:24.912129Z

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

Bobbi Towers 2023-10-12T12:46:24.075149Z

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

roelof 2023-10-12T13:55:13.917779Z

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)))

borkdude 2023-10-12T13:57:16.096409Z

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

roelof 2023-10-12T13:58:13.097089Z

sometimes clojure makes me crazy

roelof 2023-10-12T13:58:30.811249Z

I try to use the output of that function

roelof 2023-10-12T13:59:22.354959Z

oke

roelof 2023-10-12T13:59:43.593239Z

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

roelof 2023-10-12T16:22:37.720409Z

any hints ?

slipset 2023-10-12T19:26:28.878599Z

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)

roelof 2023-10-12T19:29:38.287459Z

Thanks will change it

slipset 2023-10-12T19:21:32.365229Z

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.

slipset 2023-10-12T19:22:24.836379Z

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

slipset 2023-10-12T19:23:15.206319Z

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
roelof 2023-10-12T19:39:04.654699Z

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

roelof 2023-10-12T19:39:37.682269Z

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

roelof 2023-10-12T19:40:33.609029Z

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

roelof 2023-10-12T19:40:54.618909Z

@slipset

Bobbi Towers 2023-10-12T20:25:57.497649Z

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 Towers 2023-10-12T20:28:07.032929Z

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 Towers 2023-10-12T20:33:35.650419Z

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.

slipset 2023-10-12T20:41:11.528079Z

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 Towers 2023-10-12T20:45:06.941329Z

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

slipset 2023-10-12T20:46:08.814979Z

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

slipset 2023-10-12T20:46:28.253899Z

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

Bobbi Towers 2023-10-12T20:46:34.641219Z

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

slipset 2023-10-12T20:47:25.637729Z

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.

slipset 2023-10-12T20:48:01.374029Z

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

Bobbi Towers 2023-10-12T20:51:33.896669Z

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

slipset 2023-10-12T20:51:51.851099Z

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.

slipset 2023-10-12T20:53:10.026929Z

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

Bobbi Towers 2023-10-12T20:54:51.031629Z

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

slipset 2023-10-12T20:57:19.739409Z

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 Towers 2023-10-12T21:00:05.936369Z

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 Towers 2023-10-12T21:00:51.170369Z

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

slipset 2023-10-12T21:05:47.846579Z

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 Towers 2023-10-12T21:15:59.619829Z

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

slipset 2023-10-12T20:55:03.644299Z

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 Towers 2023-10-12T20:55:59.332309Z

That's great to hear 🙂