pocmatos
2019-6-13 09:06:10

Who’s going to do the 40000th?


githree
2019-6-13 09:26:47

probability says: mflatt :wink:


stefan.kruger
2019-6-13 09:33:41

Could someone give me a hint how I could achieve this effect? > (hash 'a 1 'b' 2 'c 3) '#hash((a . 1) (b . 2) (c . 3)) What I mean is - a function that creates pairs from its arguments — I’m sure this is a common idiom.


sorawee
2019-6-13 09:43:49

Maybe I misunderstand your question, but hash seems to work already, no?


stefan.kruger
2019-6-13 09:50:31

Sure — it was just an example. I’d like to write a function that is completely unrelated to (hash), but that processes its argument list as a sequence of pairs, analogous to what hash does.


sorawee
2019-6-13 09:52:32

You can do

(define (my-hash . xs)
  (for ([x xs] [i (in-naturals)])
    (if (= 0 (modulo i 2))
        (printf "~a is a key\n" x)
        (printf "~a is a value\n" x) )))

> (my-hash 'a 1 'b' 2 'c 3)
a is a key
1 is a value
b is a key
2 is a value
c is a key
3 is a value

sorawee
2019-6-13 09:52:57

From here, you can manipulate xs however you want


stefan.kruger
2019-6-13 09:54:58

That’s super-neat. Thanks for taking the time to help newbies.


sorawee
2019-6-13 09:56:42

@ryanc I’m confused about identifier comparison w.r.t. phase. Here’s my little experiment:

#lang racket

(require syntax/parse racket/format)

(define (test a b)
  (syntax-parse (syntax-shift-phase-level #'#%app a)
    [{~literal #%app #:phase b} #t]
    [_ #f]))

(for ([i (in-range -3 3)])
  (for ([j (in-range -3 3)])
    (printf "~a ~a = ~a, " (~a i #:width 2) (~a j #:width 2) (test i j)))
  (newline))

which, for #lang racket, outputs:

-3 -3 = #f, -3 -2 = #f, -3 -1 = #t, -3 0  = #f, -3 1  = #f, -3 2  = #t,
-2 -3 = #t, -2 -2 = #f, -2 -1 = #f, -2 0  = #f, -2 1  = #f, -2 2  = #t,
-1 -3 = #t, -1 -2 = #t, -1 -1 = #f, -1 0  = #t, -1 1  = #f, -1 2  = #t,
0  -3 = #t, 0  -2 = #t, 0  -1 = #t, 0  0  = #t, 0  1  = #t, 0  2  = #t,
1  -3 = #t, 1  -2 = #t, 1  -1 = #t, 1  0  = #f, 1  1  = #t, 1  2  = #f,
2  -3 = #t, 2  -2 = #t, 2  -1 = #t, 2  0  = #f, 2  1  = #f, 2  2  = #f,

and for #lang racket/base, outputs:

-3 -3 = #f, -3 -2 = #t, -3 -1 = #t, -3 0  = #f, -3 1  = #t, -3 2  = #t,
-2 -3 = #t, -2 -2 = #f, -2 -1 = #t, -2 0  = #f, -2 1  = #t, -2 2  = #t,
-1 -3 = #t, -1 -2 = #t, -1 -1 = #f, -1 0  = #f, -1 1  = #t, -1 2  = #t,
0  -3 = #t, 0  -2 = #t, 0  -1 = #t, 0  0  = #t, 0  1  = #t, 0  2  = #t,
1  -3 = #t, 1  -2 = #t, 1  -1 = #t, 1  0  = #f, 1  1  = #f, 1  2  = #t,
2  -3 = #t, 2  -2 = #t, 2  -1 = #t, 2  0  = #f, 2  1  = #t, 2  2  = #f,

1) Why is the result different when I change from #lang racket to #lang racket/base — I understand that #lang racket automatically (require (for-syntax racket/base)), but the result shouldn’t be that different. 2) What’s going on when b = 0? Why is the result flipped?


sorawee
2019-6-13 10:03:38

sorawee
2019-6-13 10:28:52

Oh I see, in #lang racket the results when b = 1 are also flipped. I guess that’s because #%app is bound in phase 1


ryanc
2019-6-13 10:30:30

@sorawee here’s a modification of the program that might make things clearer: (define (test id b) (syntax-parse id [{~literal #%app #:phase b} #t] [_ #f])) (printf "each cell has form:\n") (printf " phase-shift cmp-at-phase = equal? (shifted-bound? literal-bound?)\n") (printf "where B=bound, u=unbound\n\n") (for ([i (in-range -3 3)]) (for ([j (in-range -3 3)]) (define id (syntax-shift-phase-level #'#%app i)) (printf "~a ~a = ~a (~a ~a) " (~a i #:width 2) (~a j #:width 2) (if (test id j) "TRUE " "false") (if (identifier-binding id j) 'B 'u) (if (identifier-binding #'#%app j) 'B 'u))) (newline))


sorawee
2019-6-13 10:31:35

Thanks!


alexknauth
2019-6-13 13:32:32

An example using in-slice: (define (my-hash . xs) (for/fold ([acc (hash)]) ([kv (in-slice 2 xs)]) (match-define (list k v) kv) (hash-set acc k v))) > (my-hash 'a 1 'b' 2 'c 3) '#hash((a . 1) (b . 2) (c . 3))


samdphillips
2019-6-13 17:09:45

case-lambda is another choice in this space

(define my-hash
  (case-lambda
    [(k v)
     (hash-set (hash) k v)]
    [(k v . kvs)
     (hash-set (apply my-hash kvs) k v)]))

rokitna
2019-6-13 21:58:38

When are two hash tables equal?? Is this in the docs? I can probably guess the answer, but I was just looking for confirmation in the docs and couldn’t find it.


rokitna
2019-6-13 22:02:01

(The documentation for equal? says hash tables are one of the types with further specification of equal?, and the reference page for hash tables does specify that they’re not equal in a couple of specific circumstances. That’s all I found.)


alexknauth
2019-6-13 22:02:52

> Datatypes with further specification of equal? include … pairs, mutable pairs, vectors, boxes, hash tables, and inspectable structures. In the last six cases, equality is recursively defined


rokitna
2019-6-13 22:06:56

I suppose fundamentally I’m interested in knowing whether two hash tables that have the same mutability, the same key holding strength, the same comparator, the same number of keys, an equal? correspondence between the keys, and equal? values for each key might still be non-equal? for some other incidental reason (like the order the keys were inserted in or something).


rokitna
2019-6-13 22:08:48

Also, I don’t actually know whether differences in mutability or key holding strength affect (or are supposed to affect) equal?.


rokitna
2019-6-13 22:10:38

(And another model that’s consistent with the docs is for every two nonempty hash tables that don’t differ by comparator to be equal?, so I don’t even see confirmation that the keys and values matter.)


alexknauth
2019-6-13 22:11:26

“equality is recursively defined” wouldn’t make sense if the keys and values didn’t matter. So that specifies that it recurs into the keys and values


rokitna
2019-6-13 22:12:05

“equality is recursively defined” does strongly suggest that at least one key and/or value matter, yes XD


alexknauth
2019-6-13 22:15:24

Although it seems that equal? on eq-based hash tables compares the keys with eq? and not equal?. Which makes sense, but doesn’t seem to be documented anywhere


rokitna
2019-6-13 22:18:44

In the past I’ve expected hash tables to be equal? under circumstances similar to Java hash tables, where the order of keys doesn’t matter. I am mostly interested in whether I might have gotten away with being really lucky, like always constructing my tables with the same insertion order or something. Every other doubt I have is just in the spirit of wanting the docs to be clear.


krismicinski
2019-6-13 22:31:25

hi there Jesse, I’ll be there


krismicinski
2019-6-13 22:31:33

Feel free to come stop by and say hi if we see each other around.


krismicinski
2019-6-13 22:31:40

You should come to the Scheme Workshop if you have some time to stop by.


rokitna
2019-6-13 22:32:53

good about keys in an eq?-based hash being compared by eq?… I didn’t think about that, but of course it makes sense so that the correspondence between entries isn’t mixed around


notjack
2019-6-13 22:38:54

I’ve also wondered about this and been confused so thanks for asking the question


sorawee
2019-6-13 22:38:54

In DrRacket, if you evaluate (error-print-source-location), what’s the result? Mine is somehow always #f, even though the documentation says that it should default to #t.


rokitna
2019-6-13 23:55:12

Is there a way to define intermediate variables in between parts of an ->i contract? It would be particularly useful in situations where there’s a data structure that specifies a collection of interrelated contracts, and various functions express ways to map between the contracts in that data structure. Most of those functions’ argument and result contracts have dependencies on that one bundle of contracts, and it can get a bit verbose (maybe even inefficient) to unpack it over and over.


rokitna
2019-6-13 23:58:06

I noticed this commit a while back and was wondering if maybe I should open an issue for adding a #:with option with an implementation pretty similar to #:pre. https://github.com/racket/racket/commit/7a9b1d065e168d882ac8800e3fed4340c940e3ae


megavlad
2019-6-14 00:00:11

@megavlad has joined the channel


megavlad
2019-6-14 00:03:45

Hi there. First post in these channels. I’m trying to embed Racket into a C++ app, in Visual Studio 2019, and I’m running into an issue.


megavlad
2019-6-14 00:03:52

megavlad
2019-6-14 00:04:22

basically, there’s a line where you call: return scheme_main_setup(1, run, argc, argv);


megavlad
2019-6-14 00:04:45

However, when my app gets to that line, it crashes.


megavlad
2019-6-14 00:05:16

With this error message:


megavlad
2019-6-14 00:05:16

Exception thrown at 0x000000007084234F (libracket3m_bmjq9s.dll) in Proglet.exe: 0xC0000005: Access violation writing location 0x0000000000000000.


megavlad
2019-6-14 00:05:56

I’m not sure what’s causing that issue, and I’m hoping someone has seen this particular noobish problem.


megavlad
2019-6-14 00:06:37

I generated the .lib file for liking using this command: lib /machine:x64 /def:libracket3m_bmjq9s.def /subsystem:windows /nologo /ltcg


krismicinski
2019-6-14 00:28:35

looks like something in libracket touched a null pointer?


megavlad
2019-6-14 01:43:05

I didn’t see a debug version of the library in the installation directory. I searched online and don’t see one. Is this something that’s available for download?


mflatt
2019-6-14 01:51:21

Are you following the CGC instructions or the extended instructions for 3m (which is what you need for that DLL)? Did you include the scheme_register_tls_space step?


jesse
2019-6-14 03:45:14

cool! I’m thinking of organizing a little Racket workshop and am trying to find out who’s coming (or might be coming)


krismicinski
2019-6-14 03:45:47

well, we have a Scheme workshop :slightly_smiling_face:. I think similar groups of people would be coming.


krismicinski
2019-6-14 03:45:51

I’d be happy to be around