dbriemann
2020-6-12 08:15:04

Is it possible to use get-field with map? (map (λ (f) (get-field f it)) '(id score time url)) expects f literally to be a field name.


soegaard2
2020-6-12 08:17:26

No. get-field is syntax, not a function. But you can use dynamic-get-field.


samth
2020-6-12 08:17:28

For racket/place, you don’t need a separate library, it’s built in.


dbriemann
2020-6-12 08:17:54

nice that works


samth
2020-6-12 08:18:00

Place channels always return Any, currently there are no typed place channels


jcoo092
2020-6-12 08:29:37

Thanks :slightly_smiling_face:


dbriemann
2020-6-12 10:52:06

I just felt clever for a moment when I searched for a function that converts #f to #f, and everything else to #t and realized i can just do (and x #t) .. lol


dbriemann
2020-6-12 11:17:09

If I want to inspect a random object in the repl, how do i do this? Printing it is always reduced to object:something ... . Is there a way to pretty print an arbitrary object or do I have to implement the printable interface for that?


soegaard2
2020-6-12 12:43:00

@dbriemann Use describe


dbriemann
2020-6-12 13:15:44

i tried it but for instances of classes this looks almost the same. the doc also does not mention classes, only structures.


soegaard2
2020-6-12 13:19:00

On top of my head I don’t know of other options.


badkins
2020-6-12 14:38:29

Just out of curiosity, why do you need to have #t as opposed to simply depending on the value being “truthy” ?


badkins
2020-6-12 14:41:54

I think I first encountered a “named let” in “The Scheme Programming Language” by Dybvig. I have a hard copy, but it’s also available free online: https://www.scheme.com/tspl4/ One of my favorite programming books. Racket provides many nice constructs, such as the variety of for loops, but I still find simple Scheme code very elegant :slightly_smiling_face:


badkins
2020-6-12 14:42:23

dcmicoltacespedes
2020-6-12 14:42:32

@dcmicoltacespedes has joined the channel


dcmicoltacespedes
2020-6-12 15:26:17

Good morning, I come from #general, with the same question. I am trying to create a program that returns the piece (that its inside of a list of structs ) with the higher number in both spaces (space1 and space2) or in some of them for example: (define piece1 (list (make-piece 1 0) (make-piece 5 1) (make-piece 2 2) (make-piece 6 6) (make-piece 3 6)) -> return: (piece 6 6) This is I have so far: (define-struct piece (space1 space2)#:transparent) (define p1 (make-piece 1 0)) (define p2 (make-piece 5 1)) (define p3 (make-piece 2 2)) (define p4 (make-piece 0 3)) (define p5 (make-piece 0 4)) (define p6 (make-piece 6 6)) (define p7 (make-piece 3 6)) (define piece1 (list p1 p2 p3 p4 p5 p6 p7)) (define (higher list) (cond [(empty? list) "it don't have elements"] [(equal? (and(piece-space1 (first list))(piece-space2 (first list))) (and(piece-space1 (first(rest list)))(piece-space2 (first(rest list))))) (something...)] [(> (and(piece-space1 (first list))(piece-space2 (first list))) (and(piece-space1 (first(rest list)))(piece-space2 (first(rest list))))) (piece(first list)(higher(rest list)))] [else (higher(rest list))] ) ) (higher piece1) I don’t know if I’m explaining well. This is the error appears to me: first: contract violation expected: (and / c list? (not / c empty?)) given: '() Although, in general, I don’t know if the program is doing what I want it to do, is it well thought out? Or should it be done differently?


badkins
2020-6-12 15:42:24

One minor note, if you don’t need to make use of p1, p2, …, there is no need to define them separately: (struct piece (space1 space2) #:transparent) (define piece1 (list (piece 1 0) (piece 5 1) (piece 2 2) (piece 0 3) (piece 0 4) (piece 6 6) (piece 3 6)))


badkins
2020-6-12 15:43:23

How do you want to handle the situation where there isn’t a clear “winner”, e.g. '( (5 3) (2 1) (3 5) (4 2)) ?


badkins
2020-6-12 15:45:42

In other words, I think the first step may be to define something like: (define (piece<? p1 p2) ...


badkins
2020-6-12 15:53:06

I’m not sure what your goal is, but since the “spaces” resemble a coordinate system, I suppose you could compute the distance from the origin as the value, and then simply use the built-in <


dcmicoltacespedes
2020-6-12 16:00:46

It is that, what I want mainly is, to compare pieces of domino of 4 players. So what I thought was, make four auxiliary functions that take out the higher piece from each player, and then in a main function, compare them and the piece higher , save it in another function called “table”.


badkins
2020-6-12 16:03:08

Can you define the property “higher” ? In other words, what does that mean? Is (0 6) higher than (5 4) ?


badkins
2020-6-12 16:03:53

Is it the sum of the values? e.g. 5 + 4 = 9 > 0 + 6 = 6 ?


dcmicoltacespedes
2020-6-12 16:32:41

Well, in the domino the pieces with the highest priority are the doubles, (0 0) <(1 1) <(2 2) <(3 3) <(4 4) <(5 5) <(6 6). So, if there are no doubles, it is determined which piece is the highest (0 0) <(0 1) <(0 2) <... (1 2) <(1 3) ... <(2 5) ... <... (4 6) ... <(6 6). And they are static values, they cannot be operated and they cannot be changed either.

In total there are 28 pieces, I defined them like this: (define p1 (make-piece 0 0)) (define p2 (make-piece 0 1)) (define p3 (make-piece 0 2)) (define p4 (make-piece 0 3)) (define p5 (make-piece 0 4)) (define p6 (make-piece 0 5)) (define p7 (make-piece 0 6)) (define p8 (make-piece 1 1)) (define p9 (make-piece 1 2)) (define p10 (make-piece 1 3)) (define p11 (make-piece 1 4)) (define p12 (make-piece 1 5)) (define p13 (make-piece 1 6)) (define p14 (make-piece 2 2)) (define p15 (make-piece 2 3)) (define p16 (make-piece 2 4)) (define p17 (make-piece 2 5)) (define p18 (make-piece 2 6)) (define p19 (make-piece 3 3)) (define p20 (make-piece 3 4)) (define p21 (make-piece 3 5)) (define p22 (make-piece 3 6)) (define p23 (make-piece 4 4)) (define p24 (make-piece 4 5)) (define p25 (make-piece 4 6)) (define p26 (make-piece 5 5)) (define p27 (make-piece 5 6)) (define p28 (make-piece 6 6)) and I put all those pieces in a list, that’s why I defined them. Then I divided that list into 4 parts each with 7 elements (list p1 p2 p3 ...) (list p8 p9 ..) … and each list was assigned to a player. Now what I’m looking for is to get the piece with the highest value among the four players to start the game


notjack
2020-6-12 23:04:47

@badkins often it comes up when a higher order function expects a predicate


notjack
2020-6-12 23:06:55

If it’s your own class, implement whatever interface is needed to control the printing behavior.

If it’s not, ask the owner of the class if they’d consider doing so.


badkins
2020-6-12 23:25:20

Not sure I follow; do you have an example where #t would work but another non-#f value would not? I’m not saying that never happens, it just seems rare to me.