
Who’s going to do the 40000th?

probability says: mflatt :wink:

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.

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

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.

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

From here, you can manipulate xs
however you want

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

@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?

If you want key-value pair together in iterations, you can use in-slice
: https://docs.racket-lang.org/reference/sequences.html#%28def._%28%28lib._racket%2Fsequence..rkt%29._in-slice%29%29

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

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

Thanks!

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

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

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.

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

> 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

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

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

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

“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

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

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

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.

hi there Jesse, I’ll be there

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

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

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

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

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
.

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.

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 has joined the channel

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.


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

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

With this error message:

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

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

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

looks like something in libracket
touched a null pointer?

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?

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?

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

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

I’d be happy to be around