luka.hadzi
2019-8-10 11:48:46

@luka.hadzi has joined the channel


nma.arvydas.silanskas
2019-8-10 14:45:47

this racket2 thing made me have an existential-scheme crisis.. and now the more I think about it, the more it seems the only real way scheme is suitable for serious / prod level programming is in a role of embedded scripting atop of something else


spdegabrielle
2019-8-10 15:08:21

I’m sorry it’s been a bad time for you. I hope you are feeling better soon. I think a scheme was used to embed a scripting language for dialog in the game ‘last of us’.


contact
2019-8-10 20:50:29

Hi! Doing SICP in Racket, I found out that mutable list are highly discouraged in Racket. “Use of mutable lists for modern Racket code is strongly discouraged.” from: https://docs.racket-lang.org/compatibility/mlists.html.


contact
2019-8-10 20:51:12

How to implement a similar behaviour then ?


contact
2019-8-10 20:53:34

For example, in section “3.3.4 A Simulator for Digital Circuits” of SICP, things are implemented using mutable lists, for example: (define (add-to-segments! segments) (if (= (segment-time (car segments)) time) (insert-queue! (segment-queue (car segments)) action) (let ((rest (cdr segments))) (if (belongs-before? rest) (set-cdr! segments (cons (make-new-time-segment time action) (cdr segments))) (add-to-segments! rest)))))


contact
2019-8-10 20:53:49

How to do that in Racket?


contact
2019-8-10 20:54:00

“The right way” ?


alexknauth
2019-8-10 20:54:45

Oh, you mean if that SICP exercise were translated to Racket, what would it be turned into?


contact
2019-8-10 20:54:58

Yes


contact
2019-8-10 20:55:27

How to implement (add-to-segments! segments) the way and experienced Racketer would ?


contact
2019-8-10 20:58:46

Which essentially boils down to insert an element in the middle of a list without having to copy anything


contact
2019-8-10 21:00:02

It cannot be done without mutation, can it ?


contact
2019-8-10 21:01:51

soegaard2
2019-8-10 21:08:20

@contact When SICP was written Scheme had to data structures: lists and vectors.


soegaard2
2019-8-10 21:08:47

SICP shows how to built other, compound data structures using the building blocks.


soegaard2
2019-8-10 21:09:42

They use so-called tagged lists, where the first element of a list is a tag (symbol) that shows what the remaining elements in the list represent.


soegaard2
2019-8-10 21:10:23

Today one uses structs or records (same concept - Racket uses structs).


notjack
2019-8-10 21:11:04

and structs/records are much better, because the fields are named


soegaard2
2019-8-10 21:11:08

You can use the keyword #:mutable when you define a struct to make a struct mutable.


contact
2019-8-10 21:11:37

Ok! Thank you! I will try with these.


soegaard2
2019-8-10 21:11:50

Yes - I think of the SICP approach as the “Poor man’s structs”.


soegaard2
2019-8-10 21:12:24

Note that the sicp language does support mutable lists - but learning about structs is important.


contact
2019-8-10 21:12:50

Thank you very much!


sorawee
2019-8-10 21:35:15

@contact Note: the SICP language that @soegaard2 was talking about is #lang sicp. You can install it with raco pkg install sicp. In that hash lang, lists are mutable.


contact
2019-8-10 21:41:40

:+1:


plragde
2019-8-10 22:04:12

I consider SICP outdated, but it shouldn’t be hard to write a “translation” into idiomatic Racket. Given its continuing popularity, I’m surprised someone hasn’t done so.


contact
2019-8-11 06:42:01

Or this: